Skip to content

Commit efc2ffc

Browse files
committed
ci: automate release artifacts
1 parent d34a077 commit efc2ffc

1 file changed

Lines changed: 119 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
workflow_dispatch:
8+
inputs:
9+
ref:
10+
description: "Tag to release, for example v0.0.18"
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
test:
19+
name: test
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v6
23+
with:
24+
ref: ${{ github.event.inputs.ref || github.ref }}
25+
- name: Validate release tag
26+
env:
27+
TAG: ${{ github.event.inputs.ref || github.ref_name }}
28+
run: |
29+
case "$TAG" in
30+
v*) ;;
31+
*) echo "release tag must start with v"; exit 1 ;;
32+
esac
33+
- uses: actions/setup-go@v6
34+
with:
35+
go-version-file: "go.mod"
36+
- name: Test
37+
run: go test -v -race ./...
38+
39+
build:
40+
name: build ${{ matrix.goos }}/${{ matrix.goarch }}
41+
needs: test
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- goos: darwin
47+
goarch: amd64
48+
runs-on: macos-15-intel
49+
- goos: darwin
50+
goarch: arm64
51+
runs-on: macos-15
52+
- goos: linux
53+
goarch: amd64
54+
runs-on: ubuntu-latest
55+
- goos: linux
56+
goarch: arm64
57+
runs-on: ubuntu-24.04-arm
58+
- goos: windows
59+
goarch: amd64
60+
runs-on: windows-latest
61+
runs-on: ${{ matrix.runs-on }}
62+
steps:
63+
- uses: actions/checkout@v6
64+
with:
65+
ref: ${{ github.event.inputs.ref || github.ref }}
66+
- uses: actions/setup-go@v6
67+
with:
68+
go-version-file: "go.mod"
69+
- name: Verify native build target
70+
shell: bash
71+
run: |
72+
test "$(go env GOHOSTOS)" = "${{ matrix.goos }}"
73+
test "$(go env GOHOSTARCH)" = "${{ matrix.goarch }}"
74+
- name: Build archive
75+
shell: bash
76+
env:
77+
CGO_ENABLED: "0"
78+
GOOS: ${{ matrix.goos }}
79+
GOARCH: ${{ matrix.goarch }}
80+
run: |
81+
tag="${{ github.event.inputs.ref || github.ref_name }}"
82+
version="${tag#v}"
83+
revision="${version}+$(git rev-parse --short HEAD)"
84+
output="go-csp-collector_${version}_${GOOS}_${GOARCH}"
85+
86+
mkdir -p dist
87+
if [ "$GOOS" = "windows" ]; then
88+
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}.exe" .
89+
tar -czf "dist/${output}.tar.gz" -C dist "${output}.exe"
90+
else
91+
go build -trimpath -ldflags "-s -w -X main.Rev=${revision}" -o "dist/${output}" .
92+
tar -czf "dist/${output}.tar.gz" -C dist "${output}"
93+
fi
94+
- name: Upload archive
95+
uses: actions/upload-artifact@v7
96+
with:
97+
name: go-csp-collector-${{ matrix.goos }}-${{ matrix.goarch }}
98+
path: dist/*.tar.gz
99+
if-no-files-found: error
100+
101+
release:
102+
name: publish release
103+
needs: build
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: Download archives
107+
uses: actions/download-artifact@v8
108+
with:
109+
path: dist
110+
pattern: go-csp-collector-*
111+
merge-multiple: true
112+
- name: Generate checksums
113+
working-directory: dist
114+
run: shasum -a 256 -- *.tar.gz > checksums.txt
115+
- name: Publish GitHub release
116+
env:
117+
GH_TOKEN: ${{ github.token }}
118+
TAG: ${{ github.event.inputs.ref || github.ref_name }}
119+
run: gh release create "$TAG" dist/*.tar.gz dist/checksums.txt --title "$TAG" --generate-notes

0 commit comments

Comments
 (0)