Skip to content

Commit effb107

Browse files
committed
feat: initial commit
0 parents  commit effb107

23 files changed

Lines changed: 3145 additions & 0 deletions

.github/workflows/docker.yaml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
name: docker images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- master
8+
paths:
9+
- 'neutrino_server/**'
10+
- '.github/workflows/docker.yaml'
11+
pull_request:
12+
branches:
13+
- main
14+
- master
15+
paths:
16+
- 'neutrino_server/**'
17+
- '.github/workflows/docker.yaml'
18+
release:
19+
types: [published]
20+
21+
env:
22+
REGISTRY: ghcr.io
23+
IMAGE_NAME: ${{ github.repository }}
24+
25+
jobs:
26+
test:
27+
uses: ./.github/workflows/test.yaml
28+
29+
pre-commit:
30+
uses: ./.github/workflows/pre-commit.yaml
31+
32+
build-and-push:
33+
runs-on: ubuntu-latest
34+
needs: [test, pre-commit]
35+
# Only push images on push to main/master or releases, not on PRs
36+
if: github.event_name != 'pull_request'
37+
38+
permissions:
39+
contents: read
40+
packages: write
41+
42+
steps:
43+
- name: Checkout repository
44+
uses: actions/checkout@v4
45+
46+
- name: Set up Docker Buildx
47+
uses: docker/setup-buildx-action@v3
48+
49+
- name: Log in to Container registry
50+
uses: docker/login-action@v3
51+
with:
52+
registry: ${{ env.REGISTRY }}
53+
username: ${{ github.actor }}
54+
password: ${{ secrets.GITHUB_TOKEN }}
55+
56+
- name: Extract metadata (tags, labels)
57+
id: meta
58+
uses: docker/metadata-action@v5
59+
with:
60+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
61+
tags: |
62+
type=ref,event=branch
63+
type=ref,event=pr
64+
type=semver,pattern={{version}}
65+
type=semver,pattern={{major}}.{{minor}}
66+
type=sha,prefix={{branch}}-
67+
type=raw,value=latest,enable={{is_default_branch}}
68+
69+
- name: Build and push Docker image
70+
uses: docker/build-push-action@v5
71+
with:
72+
context: ./neutrino_server
73+
file: ./neutrino_server/Dockerfile
74+
push: true
75+
tags: ${{ steps.meta.outputs.tags }}
76+
labels: ${{ steps.meta.outputs.labels }}
77+
cache-from: type=gha
78+
cache-to: type=gha,mode=max
79+
platforms: linux/amd64,linux/arm64

.github/workflows/pre-commit.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
workflow_call:
6+
7+
jobs:
8+
pre-commit:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v4
12+
13+
- name: Set up Go
14+
uses: actions/setup-go@v5
15+
with:
16+
go-version: '1.21'
17+
cache: false
18+
19+
- uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.14'
22+
23+
- uses: pre-commit/action@v3.0.1

.github/workflows/release.yaml

Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
name: release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch:
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
create-release:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
upload_url: ${{ steps.create_release.outputs.upload_url }}
18+
version: ${{ steps.get_version.outputs.version }}
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Get version
24+
id: get_version
25+
run: |
26+
if [[ $GITHUB_REF == refs/tags/* ]]; then
27+
VERSION=${GITHUB_REF#refs/tags/}
28+
else
29+
VERSION=$(git describe --tags --always)
30+
fi
31+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
32+
echo "Version: ${VERSION}"
33+
34+
- name: Extract release notes
35+
id: extract_notes
36+
run: |
37+
# Extract version-specific notes from CHANGELOG.md if it exists
38+
if [ -f CHANGELOG.md ]; then
39+
VERSION=${{ steps.get_version.outputs.version }}
40+
# Simple extraction - customize as needed
41+
echo "notes<<EOF" >> $GITHUB_OUTPUT
42+
echo "Release ${VERSION}" >> $GITHUB_OUTPUT
43+
echo "" >> $GITHUB_OUTPUT
44+
echo "Built with Neutrino v0.16.0" >> $GITHUB_OUTPUT
45+
echo "EOF" >> $GITHUB_OUTPUT
46+
else
47+
echo "notes=Release ${{ steps.get_version.outputs.version }}" >> $GITHUB_OUTPUT
48+
fi
49+
50+
- name: Create Release
51+
id: create_release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: ${{ github.ref }}
57+
release_name: Release ${{ steps.get_version.outputs.version }}
58+
body: ${{ steps.extract_notes.outputs.notes }}
59+
draft: false
60+
prerelease: false
61+
62+
build-binaries:
63+
needs: create-release
64+
runs-on: ubuntu-latest
65+
strategy:
66+
matrix:
67+
include:
68+
- goos: linux
69+
goarch: amd64
70+
output: neutrinod-linux-amd64
71+
- goos: linux
72+
goarch: arm64
73+
output: neutrinod-linux-arm64
74+
- goos: darwin
75+
goarch: amd64
76+
output: neutrinod-darwin-amd64
77+
- goos: darwin
78+
goarch: arm64
79+
output: neutrinod-darwin-arm64
80+
- goos: windows
81+
goarch: amd64
82+
output: neutrinod-windows-amd64.exe
83+
84+
steps:
85+
- name: Checkout
86+
uses: actions/checkout@v4
87+
88+
- name: Set up Go
89+
uses: actions/setup-go@v5
90+
with:
91+
go-version: '1.21'
92+
cache-dependency-path: neutrino_server/go.sum
93+
94+
- name: Get dependencies
95+
working-directory: neutrino_server
96+
run: go mod download
97+
98+
- name: Build binary
99+
working-directory: neutrino_server
100+
env:
101+
GOOS: ${{ matrix.goos }}
102+
GOARCH: ${{ matrix.goarch }}
103+
CGO_ENABLED: 0
104+
run: |
105+
VERSION=${{ needs.create-release.outputs.version }}
106+
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
107+
COMMIT_HASH=$(git rev-parse --short HEAD)
108+
109+
go build \
110+
-ldflags="-s -w -X main.version=${VERSION} -X main.buildTime=${BUILD_TIME} -X main.commit=${COMMIT_HASH}" \
111+
-o ${{ matrix.output }} \
112+
./cmd/neutrinod
113+
114+
- name: Create archive
115+
run: |
116+
if [[ "${{ matrix.goos }}" == "windows" ]]; then
117+
zip neutrino_server/${{ matrix.output }}.zip neutrino_server/${{ matrix.output }}
118+
ASSET_PATH=neutrino_server/${{ matrix.output }}.zip
119+
ASSET_NAME=${{ matrix.output }}.zip
120+
else
121+
tar -czf neutrino_server/${{ matrix.output }}.tar.gz -C neutrino_server ${{ matrix.output }}
122+
ASSET_PATH=neutrino_server/${{ matrix.output }}.tar.gz
123+
ASSET_NAME=${{ matrix.output }}.tar.gz
124+
fi
125+
echo "ASSET_PATH=${ASSET_PATH}" >> $GITHUB_ENV
126+
echo "ASSET_NAME=${ASSET_NAME}" >> $GITHUB_ENV
127+
128+
- name: Upload Release Asset
129+
uses: actions/upload-release-asset@v1
130+
env:
131+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132+
with:
133+
upload_url: ${{ needs.create-release.outputs.upload_url }}
134+
asset_path: ${{ env.ASSET_PATH }}
135+
asset_name: ${{ env.ASSET_NAME }}
136+
asset_content_type: application/octet-stream
137+
138+
build-docker:
139+
needs: create-release
140+
runs-on: ubuntu-latest
141+
permissions:
142+
contents: read
143+
packages: write
144+
145+
steps:
146+
- name: Checkout
147+
uses: actions/checkout@v4
148+
149+
- name: Set up QEMU
150+
uses: docker/setup-qemu-action@v3
151+
152+
- name: Set up Docker Buildx
153+
uses: docker/setup-buildx-action@v3
154+
155+
- name: Log in to Container registry
156+
uses: docker/login-action@v3
157+
with:
158+
registry: ${{ env.REGISTRY }}
159+
username: ${{ github.actor }}
160+
password: ${{ secrets.GITHUB_TOKEN }}
161+
162+
- name: Extract metadata
163+
id: meta
164+
uses: docker/metadata-action@v5
165+
with:
166+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
167+
tags: |
168+
type=semver,pattern={{version}}
169+
type=semver,pattern={{major}}.{{minor}}
170+
type=semver,pattern={{major}}
171+
type=raw,value=latest,enable={{is_default_branch}}
172+
173+
- name: Build and push Docker image
174+
uses: docker/build-push-action@v5
175+
with:
176+
context: ./neutrino_server
177+
file: ./neutrino_server/Dockerfile
178+
platforms: linux/amd64,linux/arm64
179+
push: true
180+
tags: ${{ steps.meta.outputs.tags }}
181+
labels: ${{ steps.meta.outputs.labels }}
182+
cache-from: type=gha
183+
cache-to: type=gha,mode=max
184+
build-args: |
185+
VERSION=${{ needs.create-release.outputs.version }}
186+
BUILD_TIME=${{ github.event.repository.updated_at }}
187+
COMMIT=${{ github.sha }}
188+
189+
checksums:
190+
needs: [create-release, build-binaries]
191+
runs-on: ubuntu-latest
192+
steps:
193+
- name: Download all artifacts
194+
uses: actions/download-artifact@v3
195+
with:
196+
path: ./artifacts
197+
198+
- name: Generate checksums
199+
run: |
200+
cd artifacts
201+
find . -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec sha256sum {} \; > SHA256SUMS
202+
cat SHA256SUMS
203+
204+
- name: Upload checksums
205+
uses: actions/upload-release-asset@v1
206+
env:
207+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
208+
with:
209+
upload_url: ${{ needs.create-release.outputs.upload_url }}
210+
asset_path: ./artifacts/SHA256SUMS
211+
asset_name: SHA256SUMS
212+
asset_content_type: text/plain

0 commit comments

Comments
 (0)