Skip to content

Commit bcd3e3e

Browse files
committed
feat: build workflow
1 parent 93df84c commit bcd3e3e

4 files changed

Lines changed: 256 additions & 417 deletions

File tree

.github/workflows/release.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
goreleaser:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Fetch all tags
21+
run: git fetch --force --tags
22+
23+
- name: Set up Go
24+
uses: actions/setup-go@v5
25+
with:
26+
go-version: '1.25.5'
27+
cache: true
28+
29+
- name: Run GoReleaser
30+
uses: goreleaser/goreleaser-action@v6
31+
with:
32+
distribution: goreleaser
33+
version: latest
34+
args: release --clean
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Upload release artifacts
39+
uses: actions/upload-artifact@v4
40+
if: always()
41+
with:
42+
name: release-artifacts
43+
path: |
44+
dist/*.tar.gz
45+
dist/*.zip
46+
dist/checksums.txt
47+
retention-days: 7

.goreleaser.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# GoReleaser configuration for node-serviced
2+
# Documentation: https://goreleaser.com
3+
4+
version: 2
5+
6+
project_name: node-serviced
7+
8+
before:
9+
hooks:
10+
# Ensure dependencies are up to date
11+
- go mod tidy
12+
- go mod download
13+
14+
builds:
15+
- id: node-serviced
16+
main: .
17+
binary: node-serviced
18+
env:
19+
- CGO_ENABLED=0
20+
goos:
21+
- linux
22+
goarch:
23+
- amd64
24+
- arm64
25+
- arm
26+
goarm:
27+
- "6"
28+
- "7"
29+
ldflags:
30+
- -s -w
31+
- -X main.version={{.Version}}
32+
- -X main.commit={{.Commit}}
33+
- -X main.date={{.Date}}
34+
flags:
35+
- -trimpath
36+
37+
archives:
38+
- id: default
39+
name_template: >-
40+
{{ .ProjectName }}_
41+
{{- .Version }}_
42+
{{- title .Os }}_
43+
{{- if eq .Arch "amd64" }}x86_64
44+
{{- else if eq .Arch "386" }}i386
45+
{{- else }}{{ .Arch }}{{ end }}
46+
{{- if .Arm }}v{{ .Arm }}{{ end }}
47+
builds:
48+
- node-serviced
49+
rlcp: true
50+
files:
51+
- README.md
52+
- LICENSE*
53+
54+
checksum:
55+
name_template: 'checksums.txt'
56+
algorithm: sha256
57+
58+
snapshot:
59+
version_template: "{{ incpatch .Version }}-next"
60+
61+
changelog:
62+
sort: asc
63+
use: github
64+
filters:
65+
exclude:
66+
- '^docs:'
67+
- '^test:'
68+
- '^ci:'
69+
- '^chore:'
70+
- 'typo'
71+
groups:
72+
- title: Features
73+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
74+
order: 0
75+
- title: Bug Fixes
76+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
77+
order: 1
78+
- title: Performance Improvements
79+
regexp: '^.*?perf(\([[:word:]]+\))??!?:.+$'
80+
order: 2
81+
- title: Others
82+
order: 999
83+
84+
release:
85+
github:
86+
owner: PasarGuard
87+
name: node-serviced
88+
draft: false
89+
prerelease: auto
90+
mode: replace
91+
header: |
92+
## node-serviced Release {{ .Tag }}
93+
footer: |
94+
**Full Changelog**: https://github.com/PasarGuard/node-serviced/compare/{{ .PreviousTag }}...{{ .Tag }}
95+
96+
---
97+
98+
**Verify checksums**: Download `checksums.txt` and verify with `sha256sum -c checksums.txt`
99+
100+
# Optional: Generate Software Bill of Materials
101+
# sboms:
102+
# - artifacts: archive
103+
104+
# Optional: Sign binaries (requires signing keys)
105+
# signs:
106+
# - cmd: cosign
107+
# artifacts: checksum
108+
# args:
109+
# - sign-blob
110+
# - --output-signature=${signature}
111+
# - ${artifact}

install.sh

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# node-serviced installer (Linux only)
5+
# Downloads the latest GitHub release for the detected arch and installs to /usr/local/bin/node-serviced
6+
7+
REPO_OWNER="PasarGuard"
8+
REPO_NAME="node-serviced"
9+
INSTALL_PATH="/usr/local/bin/node-serviced"
10+
API_URL="https://api.github.com/repos/${REPO_OWNER}/${REPO_NAME}/releases/latest"
11+
12+
ARCH=""
13+
OS="linux"
14+
TMPDIR=""
15+
16+
log() {
17+
printf '[%s] %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >&2
18+
}
19+
20+
cleanup() {
21+
if [[ -n "${TMPDIR:-}" && -d "$TMPDIR" ]]; then
22+
rm -rf "$TMPDIR"
23+
fi
24+
}
25+
trap cleanup EXIT
26+
27+
detect_arch() {
28+
case "$(uname -m)" in
29+
x86_64|amd64) ARCH="amd64" ;;
30+
aarch64|arm64) ARCH="arm64" ;;
31+
armv7l|armv7) ARCH="armv7" ;;
32+
armv6l|armv6) ARCH="armv6" ;;
33+
*) log "Unsupported architecture: $(uname -m)"; exit 1 ;;
34+
esac
35+
}
36+
37+
require_linux() {
38+
if [[ "$(uname -s)" != "Linux" ]]; then
39+
log "This installer supports Linux only."
40+
exit 1
41+
}
42+
}
43+
44+
require_tools() {
45+
for bin in curl tar; do
46+
if ! command -v "$bin" >/dev/null 2>&1; then
47+
log "Missing required tool: $bin"
48+
exit 1
49+
fi
50+
done
51+
}
52+
53+
fetch_latest_url() {
54+
local asset_name="${REPO_NAME}_*_Linux_${ARCH}.tar.gz"
55+
local url
56+
url=$(curl -sSf "$API_URL" | grep -oE "\"browser_download_url\": \"[^\"]*${asset_name}\"" | head -n1 | cut -d\" -f4)
57+
if [[ -z "$url" ]]; then
58+
log "Could not find a release asset for arch=${ARCH}"
59+
exit 1
60+
fi
61+
echo "$url"
62+
}
63+
64+
download_and_install() {
65+
TMPDIR=$(mktemp -d)
66+
local url="$1"
67+
local archive="$TMPDIR/node-serviced.tar.gz"
68+
69+
log "Downloading: $url"
70+
curl -fL "$url" -o "$archive"
71+
72+
log "Extracting archive"
73+
tar -xzf "$archive" -C "$TMPDIR"
74+
75+
if [[ ! -f "$TMPDIR/node-serviced" ]]; then
76+
log "Binary node-serviced not found in archive"
77+
exit 1
78+
fi
79+
80+
log "Installing to $INSTALL_PATH"
81+
install -m 0755 "$TMPDIR/node-serviced" "$INSTALL_PATH"
82+
}
83+
84+
main() {
85+
require_linux
86+
require_tools
87+
detect_arch
88+
89+
log "Detected linux/${ARCH}"
90+
local url
91+
url=$(fetch_latest_url)
92+
93+
download_and_install "$url"
94+
log "Install complete: $INSTALL_PATH"
95+
}
96+
97+
main "$@"
98+

0 commit comments

Comments
 (0)