Skip to content

Commit 012dc2d

Browse files
authored
Merge pull request #1 from myxo/master
Github action CI (run test + publish release)
2 parents c568549 + 0dbb25d commit 012dc2d

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

.github/workflows/ci.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
tags:
9+
- "v*"
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v5
23+
with:
24+
go-version-file: go.mod
25+
cache: true
26+
27+
- name: Run tests
28+
run: go test ./...
29+
30+
- name: Cross-compile binaries
31+
run: |
32+
set -euo pipefail
33+
mkdir -p dist
34+
for GOOS in linux darwin windows; do
35+
for GOARCH in amd64 arm64; do
36+
ext=""
37+
if [ "$GOOS" = "windows" ]; then
38+
ext=".exe"
39+
fi
40+
bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}"
41+
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" .
42+
done
43+
done
44+
45+
release:
46+
if: startsWith(github.ref, 'refs/tags/v')
47+
needs: test
48+
runs-on: ubuntu-latest
49+
permissions:
50+
contents: write
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v4
54+
55+
- name: Set up Go
56+
uses: actions/setup-go@v5
57+
with:
58+
go-version-file: go.mod
59+
cache: true
60+
61+
- name: Build release binaries
62+
run: |
63+
set -euo pipefail
64+
mkdir -p dist
65+
for GOOS in linux darwin windows; do
66+
for GOARCH in amd64 arm64; do
67+
ext=""
68+
if [ "$GOOS" = "windows" ]; then
69+
ext=".exe"
70+
fi
71+
bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}"
72+
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" .
73+
done
74+
done
75+
76+
- name: Create or fetch release
77+
env:
78+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
79+
TAG_NAME: ${{ github.ref_name }}
80+
run: |
81+
set -euo pipefail
82+
gh release view "$TAG_NAME" >/dev/null 2>&1 || gh release create "$TAG_NAME" --title "$TAG_NAME" --notes ""
83+
84+
- name: Upload release assets
85+
env:
86+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
TAG_NAME: ${{ github.ref_name }}
88+
run: |
89+
set -euo pipefail
90+
gh release upload "$TAG_NAME" dist/* --clobber

0 commit comments

Comments
 (0)