-
Notifications
You must be signed in to change notification settings - Fork 8
227 lines (192 loc) · 6.54 KB
/
Copy pathrelease.yml
File metadata and controls
227 lines (192 loc) · 6.54 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
name: Release
on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: "Release tag (e.g. v0.3.0)"
required: true
permissions:
contents: write
packages: write
env:
CARGO_TERM_COLOR: always
REGISTRY: ghcr.io
jobs:
build-binary:
name: Build release binary
# ubuntu-22.04 → glibc 2.35, the binary will run on 22.04+ and on
# any newer Debian/RHEL with glibc >= 2.35.
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- name: Install protobuf compiler
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler
- uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-release-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-release-
- name: Build spur-cloud-api
run: cargo build --release --bin spur-cloud-api
- uses: actions/upload-artifact@v4
with:
name: spur-cloud-api-binary
path: target/release/spur-cloud-api
retention-days: 1
build-frontend:
name: Build frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
working-directory: frontend
run: npm ci
- name: Build frontend
working-directory: frontend
run: npm run build
- uses: actions/upload-artifact@v4
with:
name: spur-cloud-frontend-dist
path: frontend/dist/
retention-days: 1
package:
name: Package release tarball
needs: [build-binary, build-frontend]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: spur-cloud-api-binary
path: ./bin
- uses: actions/download-artifact@v4
with:
name: spur-cloud-frontend-dist
path: ./frontend-dist
- name: Package binaries + assets
run: |
set -e
VERSION="${GITHUB_REF_NAME:-${{ github.event.inputs.tag }}}"
DIST="spur-cloud-${VERSION}-linux-amd64"
mkdir -p "${DIST}/bin" "${DIST}/frontend" "${DIST}/etc" "${DIST}/deploy"
cp ./bin/spur-cloud-api "${DIST}/bin/"
chmod +x "${DIST}/bin/spur-cloud-api"
cp -r ./frontend-dist/. "${DIST}/frontend/"
cp spur-cloud.toml.example "${DIST}/etc/spur-cloud.toml.example"
cp -r deploy/. "${DIST}/deploy/"
cp README.md LICENSE "${DIST}/"
tar czf "${DIST}.tar.gz" "${DIST}"
sha256sum "${DIST}.tar.gz" > "${DIST}.tar.gz.sha256"
ls -lh "${DIST}.tar.gz" "${DIST}.tar.gz.sha256"
- uses: actions/upload-artifact@v4
with:
name: spur-cloud-release
path: |
spur-cloud-*.tar.gz
spur-cloud-*.tar.gz.sha256
verify:
name: Verify on ${{ matrix.name }}
needs: package
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- distro: "ubuntu:22.04"
name: "Ubuntu 22.04"
- distro: "ubuntu:24.04"
name: "Ubuntu 24.04"
- distro: "debian:12"
name: "Debian 12"
steps:
- uses: actions/download-artifact@v4
with:
name: spur-cloud-release
- name: Smoke test on ${{ matrix.name }}
run: |
set -e
tar xzf spur-cloud-*.tar.gz
BINDIR=$(ls -d spur-cloud-*/bin | head -1)
docker run --rm -v "$(pwd)/${BINDIR}:/test:ro" ${{ matrix.distro }} bash -c '
set -e
echo "=== $(grep PRETTY_NAME /etc/os-release | cut -d\" -f2) ==="
echo "glibc: $(ldd --version 2>&1 | head -1)"
/test/spur-cloud-api --help > /dev/null
echo " spur-cloud-api: OK"
'
docker-images:
name: Build and push Docker images
needs: [build-binary, build-frontend]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3
- uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Resolve tag
id: vars
run: |
VERSION="${GITHUB_REF_NAME:-${{ github.event.inputs.tag }}}"
# ghcr.io requires lowercase repo names
REPO_LOWER="$(echo '${{ github.repository }}' | tr '[:upper:]' '[:lower:]')"
OWNER_LOWER="${REPO_LOWER%/*}"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "owner=${OWNER_LOWER}" >> "$GITHUB_OUTPUT"
- name: Build and push API image
uses: docker/build-push-action@v5
with:
context: .
file: deploy/docker/Dockerfile.api
push: true
tags: |
${{ env.REGISTRY }}/${{ steps.vars.outputs.owner }}/spur-cloud-api:${{ steps.vars.outputs.version }}
${{ env.REGISTRY }}/${{ steps.vars.outputs.owner }}/spur-cloud-api:latest
cache-from: type=gha,scope=api
cache-to: type=gha,mode=max,scope=api
- name: Build and push frontend image
uses: docker/build-push-action@v5
with:
context: .
file: deploy/docker/Dockerfile.frontend
push: true
tags: |
${{ env.REGISTRY }}/${{ steps.vars.outputs.owner }}/spur-cloud-frontend:${{ steps.vars.outputs.version }}
${{ env.REGISTRY }}/${{ steps.vars.outputs.owner }}/spur-cloud-frontend:latest
cache-from: type=gha,scope=frontend
cache-to: type=gha,mode=max,scope=frontend
release:
name: Create GitHub Release
needs: [verify, docker-images]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: spur-cloud-release
- name: Resolve tag
id: tag
run: echo "tag=${GITHUB_REF_NAME:-${{ github.event.inputs.tag }}}" >> "$GITHUB_OUTPUT"
- name: Create release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${{ steps.tag.outputs.tag }}"
gh release create "${TAG}" \
--title "Spur Cloud ${TAG}" \
--generate-notes \
spur-cloud-*.tar.gz spur-cloud-*.tar.gz.sha256