-
Notifications
You must be signed in to change notification settings - Fork 0
95 lines (84 loc) · 2.48 KB
/
Copy pathci.yml
File metadata and controls
95 lines (84 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: CI
on:
pull_request:
push:
branches:
- master
tags:
- "v*"
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Run tests
run: go test ./...
- name: Cross-compile binaries
run: |
set -euo pipefail
mkdir -p dist
for GOOS in linux darwin windows; do
for GOARCH in amd64 arm64; do
ext=""
if [ "$GOOS" = "windows" ]; then
ext=".exe"
fi
bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}"
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" .
done
done
release:
if: startsWith(github.ref, 'refs/tags/v')
needs: test
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Build release binaries
run: |
set -euo pipefail
mkdir -p dist
for GOOS in linux darwin windows; do
for GOARCH in amd64 arm64; do
ext=""
if [ "$GOOS" = "windows" ]; then
ext=".exe"
fi
bin="dist/drawbridge-${GOOS}-${GOARCH}${ext}"
GOOS=$GOOS GOARCH=$GOARCH CGO_ENABLED=0 go build -o "$bin" .
done
done
- name: Create immutable release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
tag="${{ github.ref_name }}"
if gh release view "$tag" >/dev/null 2>&1; then
if [ "$(gh release view "$tag" --json isDraft --jq .isDraft)" = "true" ]; then
echo "Draft release '$tag' already exists; uploading assets and publishing."
gh release upload "$tag" dist/* --clobber
gh release edit "$tag" --draft=false
else
echo "Release '$tag' already exists and is published; skipping."
fi
exit 0
fi
gh release create "$tag" --draft --title "$tag" --notes ""
gh release upload "$tag" dist/* --clobber
gh release edit "$tag" --draft=false