| |
@@ -0,0 +1,120 @@ |
|
1 |
+name: Build and Release |
|
2 |
+ |
|
3 |
+on: |
|
4 |
+ push: |
|
5 |
+ tags: |
|
6 |
+ - 'v*' |
|
7 |
+ workflow_dispatch: |
|
8 |
+ inputs: |
|
9 |
+ tag: |
|
10 |
+ description: 'Release tag (e.g. v1.2.3)' |
|
11 |
+ required: true |
|
12 |
+ |
|
13 |
+permissions: |
|
14 |
+ contents: write |
|
15 |
+ |
|
16 |
+env: |
|
17 |
+ BINARY_NAME: quilldrop |
|
18 |
+ |
|
19 |
+jobs: |
|
20 |
+ build: |
|
21 |
+ runs-on: ubuntu-latest |
|
22 |
+ strategy: |
|
23 |
+ fail-fast: false |
|
24 |
+ matrix: |
|
25 |
+ include: |
|
26 |
+ - goos: linux |
|
27 |
+ goarch: amd64 |
|
28 |
+ - goos: linux |
|
29 |
+ goarch: arm64 |
|
30 |
+ - goos: darwin |
|
31 |
+ goarch: amd64 |
|
32 |
+ - goos: darwin |
|
33 |
+ goarch: arm64 |
|
34 |
+ - goos: windows |
|
35 |
+ goarch: arm64 |
|
36 |
+ |
|
37 |
+ steps: |
|
38 |
+ - name: Checkout |
|
39 |
+ uses: actions/checkout@v4 |
|
40 |
+ |
|
41 |
+ - name: Setup Go |
|
42 |
+ uses: actions/setup-go@v5 |
|
43 |
+ with: |
|
44 |
+ go-version-file: go.mod |
|
45 |
+ cache: true |
|
46 |
+ |
|
47 |
+ - name: Build static binary |
|
48 |
+ env: |
|
49 |
+ GOOS: ${{ matrix.goos }} |
|
50 |
+ GOARCH: ${{ matrix.goarch }} |
|
51 |
+ CGO_ENABLED: '0' |
|
52 |
+ run: | |
|
53 |
+ set -euo pipefail |
|
54 |
+ |
|
55 |
+ BIN="${BINARY_NAME}-${GOOS}-${GOARCH}" |
|
56 |
+ if [ "${GOOS}" = "windows" ]; then |
|
57 |
+ BIN="${BIN}.exe" |
|
58 |
+ fi |
|
59 |
+ |
|
60 |
+ go build -trimpath -ldflags="-s -w" -o "${BIN}" . |
|
61 |
+ |
|
62 |
+ mkdir -p dist |
|
63 |
+ if [ "${GOOS}" = "windows" ]; then |
|
64 |
+ zip "dist/${BINARY_NAME}-${GOOS}-${GOARCH}.zip" "${BIN}" |
|
65 |
+ else |
|
66 |
+ tar -czf "dist/${BINARY_NAME}-${GOOS}-${GOARCH}.tar.gz" "${BIN}" |
|
67 |
+ fi |
|
68 |
+ |
|
69 |
+ - name: Generate checksum |
|
70 |
+ run: | |
|
71 |
+ cd dist |
|
72 |
+ sha256sum * > checksums-${{ matrix.goos }}-${{ matrix.goarch }}.txt |
|
73 |
+ cat checksums-${{ matrix.goos }}-${{ matrix.goarch }}.txt |
|
74 |
+ |
|
75 |
+ - name: Upload artifact |
|
76 |
+ uses: actions/upload-artifact@v4 |
|
77 |
+ with: |
|
78 |
+ name: ${{ env.BINARY_NAME }}-${{ matrix.goos }}-${{ matrix.goarch }} |
|
79 |
+ path: dist/* |
|
80 |
+ if-no-files-found: error |
|
81 |
+ |
|
82 |
+ release: |
|
83 |
+ needs: build |
|
84 |
+ runs-on: ubuntu-latest |
|
85 |
+ steps: |
|
86 |
+ - name: Download all artifacts |
|
87 |
+ uses: actions/download-artifact@v4 |
|
88 |
+ with: |
|
89 |
+ path: artifacts |
|
90 |
+ merge-multiple: true |
|
91 |
+ |
|
92 |
+ - name: Merge checksums |
|
93 |
+ run: | |
|
94 |
+ cd artifacts |
|
95 |
+ cat checksums-*.txt > checksums.txt |
|
96 |
+ rm checksums-*.txt |
|
97 |
+ echo "=== checksums.txt ===" |
|
98 |
+ cat checksums.txt |
|
99 |
+ |
|
100 |
+ - name: Determine tag |
|
101 |
+ id: tag |
|
102 |
+ run: | |
|
103 |
+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
|
104 |
+ echo "version=${{ github.event.inputs.tag }}" >> "$GITHUB_OUTPUT" |
|
105 |
+ else |
|
106 |
+ echo "version=${GITHUB_REF#refs/tags/}" >> "$GITHUB_OUTPUT" |
|
107 |
+ fi |
|
108 |
+ |
|
109 |
+ - name: List release assets |
|
110 |
+ run: ls -la artifacts/ |
|
111 |
+ |
|
112 |
+ - name: Create GitHub Release |
|
113 |
+ env: |
|
114 |
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
|
115 |
+ run: | |
|
116 |
+ gh release create "${{ steps.tag.outputs.version }}" \ |
|
117 |
+ --repo "${{ github.repository }}" \ |
|
118 |
+ --title "${{ steps.tag.outputs.version }}" \ |
|
119 |
+ --generate-notes \ |
|
120 |
+ artifacts/* |