-
Notifications
You must be signed in to change notification settings - Fork 0
174 lines (144 loc) · 4.93 KB
/
pre-release.yml
File metadata and controls
174 lines (144 loc) · 4.93 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
name: Pre-release Snapshot
# Creates a pre-release snapshot build on every merge to main.
# These builds are tagged as "snapshot" and are considered unstable.
on:
push:
branches:
- main
permissions:
contents: write
packages: write
env:
GOPRIVATE: github.com/GoCodeAlone/*
GONOSUMCHECK: github.com/GoCodeAlone/*
jobs:
test:
name: Pre-release Tests
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
cache: 'npm'
cache-dependency-path: ui/package-lock.json
- name: Build UI assets (required for Go embed)
run: |
cd ui && npm ci && npm run build
cd .. && mkdir -p module/ui_dist && cp -r ui/dist/* module/ui_dist/
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run tests
run: go test -race ./...
snapshot:
name: Build Snapshot Release
runs-on: ubuntu-latest
needs: test
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://npm.pkg.github.com'
cache: 'npm'
cache-dependency-path: ui/package-lock.json
- name: Build UI assets (required for Go embed)
run: |
cd ui && npm ci && npm run build
cd .. && mkdir -p module/ui_dist && cp -r ui/dist/* module/ui_dist/
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Determine snapshot version
id: version
run: |
SHORT_SHA=$(git rev-parse --short HEAD)
SNAPSHOT_VERSION="snapshot-${SHORT_SHA}"
echo "VERSION=${SNAPSHOT_VERSION}" >> "$GITHUB_ENV"
echo "version=${SNAPSHOT_VERSION}" >> "$GITHUB_OUTPUT"
- name: Build binaries
run: |
mkdir -p dist
LDFLAGS="-s -w -X main.version=${VERSION}"
GOOS=linux GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/workflow-linux-amd64 ./cmd/server
GOOS=linux GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/workflow-linux-arm64 ./cmd/server
GOOS=darwin GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/workflow-darwin-amd64 ./cmd/server
GOOS=darwin GOARCH=arm64 go build -ldflags="${LDFLAGS}" -o dist/workflow-darwin-arm64 ./cmd/server
GOOS=windows GOARCH=amd64 go build -ldflags="${LDFLAGS}" -o dist/workflow-windows-amd64.exe ./cmd/server
- name: Package admin UI
run: |
tar -czf "dist/workflow-admin-ui-${VERSION}.tar.gz" -C ui dist
- name: Create checksums
run: |
cd dist
sha256sum * > checksums.txt
- name: Clean up old snapshot releases
run: |
# Delete all previous snapshot-* releases (keep only latest)
gh release list --limit 50 | grep '^snapshot-' | awk '{print $1}' | while read tag; do
gh release delete "$tag" --yes --cleanup-tag || true
done
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create snapshot release
run: |
TAG="snapshot-$(git rev-parse --short HEAD)"
gh release create "$TAG" \
--title "Snapshot (${{ steps.version.outputs.version }})" \
--notes "Automated pre-release snapshot built from the latest commit on \`main\`.
**Commit**: ${{ github.sha }}
**Build**: ${{ steps.version.outputs.version }}
> **Warning**: This is an unstable development build. Use tagged releases for production." \
--target main \
--prerelease \
dist/*
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker-snapshot:
name: Build & Push Snapshot Image (ko)
runs-on: ubuntu-latest
needs: test
permissions:
contents: read
packages: write
steps:
- name: Check out code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
cache: true
- name: Set up ko
uses: ko-build/setup-ko@v0.9
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | ko login ghcr.io --username ${{ github.actor }} --password-stdin
- name: Build and push snapshot
env:
KO_DOCKER_REPO: ghcr.io/gocodealone/workflow
GOPRIVATE: github.com/GoCodeAlone/*
GONOSUMCHECK: github.com/GoCodeAlone/*
GOFLAGS: -mod=mod
run: |
SHA_SHORT="${GITHUB_SHA:0:7}"
ko build ./cmd/server \
--bare \
--platform=linux/amd64,linux/arm64 \
--tags="snapshot,main-sha-${SHA_SHORT}" \
--sbom=spdx