-
Notifications
You must be signed in to change notification settings - Fork 12
265 lines (241 loc) · 11.2 KB
/
slsa3-release.yaml
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
name: GroundSeg SLSA3 release
on:
workflow_dispatch:
inputs:
release_channel:
description: 'Release Channel'
required: true
type: choice
options:
- nobuild
- edge
- canary
- latest
to_canary:
description: 'Also push build to canary channel (if edge)'
required: false
type: boolean
default: false
version_server:
description: 'Version Server'
required: true
type: choice
options:
- staging.version.groundseg.app
- version.groundseg.app
permissions: read-all
env:
VERSION_AUTH: ${{ secrets.VERSION_AUTH }}
RCLONE_CONFIG: ${{ secrets.RCLONE_CONFIG }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
args:
runs-on: ubuntu-latest
outputs:
commit-date: ${{ steps.ldflags.outputs.commit-date }}
commit: ${{ steps.ldflags.outputs.commit }}
version: ${{ steps.ldflags.outputs.version }}
tree-state: ${{ steps.ldflags.outputs.tree-state }}
channel: ${{ steps.channel.outputs.value }}
bin-tag: ${{ steps.channel.outputs.bin-tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: ldflags
run: |
COMMIT_DATE=$(git log --date=iso8601-strict -1 --pretty=%ct)
COMMIT=$GITHUB_SHA
VERSION=$(git describe --tags --always --dirty | cut -c2-)
TREE_STATE=$(if git diff --quiet; then echo "clean"; else echo "dirty"; fi)
echo "commit-date=$COMMIT_DATE" >> "$GITHUB_OUTPUT"
echo "commit=$COMMIT" >> "$GITHUB_OUTPUT"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "tree-state=$TREE_STATE" >> "$GITHUB_OUTPUT"
- id: channel
run: |
CHANNEL="${{ github.event.inputs.release_channel }}"
if [ "$CHANNEL" = "latest" ]; then
BIN_TAG=$(echo ${{ github.ref_name }} | cut -d'-' -f1 | sed 's@/@.@g')
else
BIN_TAG=$(echo ${{ github.ref_name }} | sed 's@/@.@g')
fi
echo "value=$CHANNEL" >> "$GITHUB_OUTPUT"
echo "bin-tag=$BIN_TAG" >> "$GITHUB_OUTPUT"
frontend-build:
needs: args
if: ${{ github.event.inputs.release_channel != 'nobuild' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build Frontend
run: |
cd ./ui
docker build -t web-builder -f builder.Dockerfile .
container_id=$(docker create web-builder)
docker cp $container_id:/webui/build ./web
rm -rf ../goseg/web
mv web ../goseg/
docker build -t web-builder -f gallseg.Dockerfile .
container_id=$(docker create web-builder)
git clone https://github.com/Native-Planet/globber
cd globber
docker cp $container_id:/webui/build ./web
./glob.sh web
hash=$(ls -1 -c . | head -1 | sed "s/glob-\\([a-z0-9\\.]*\\).glob/\\1/")
mkdir -p /tmp/groundseg/version/glob
mv glob-*.glob "/tmp/groundseg/version/glob/gallseg-${{ github.event.inputs.release_channel }}-${hash}.glob"
echo "$hash" > /tmp/groundseg/version/glob/hash.txt
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-outputs
path: |
/tmp/groundseg/version/glob
- name: Upload web files
uses: actions/upload-artifact@v4
with:
name: web-files
path: goseg/web/
backend-build:
needs: [args, frontend-build]
runs-on: ubuntu-latest
outputs:
hashes: ${{ steps.hash.outputs.hashes }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download web directory
uses: actions/download-artifact@v4
with:
name: web-files
path: goseg/web
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: '1.23.2'
- name: Build binaries
env:
VERSION: ${{ needs.args.outputs.version }}
COMMIT: ${{ needs.args.outputs.commit }}
COMMIT_DATE: ${{ needs.args.outputs.commit-date }}
TREE_STATE: ${{ needs.args.outputs.tree-state }}
run: |
cd goseg
for arch in amd64 arm64; do
GO111MODULE=on CGO_ENABLED=0 GOARCH=$arch go build -o ../groundseg_${arch}_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }} \
-trimpath \
-tags=netgo \
-ldflags="-X main.Version=${VERSION} -X main.Commit=${COMMIT} -X main.CommitDate=${COMMIT_DATE} -X main.TreeState=${TREE_STATE}" .
done
- name: Generate hashes
id: hash
run: |
ls -la groundseg_*_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}
HASH_OUTPUT=$(sha256sum groundseg_*_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }} | tee /dev/stderr | base64 -w0)
echo "Hash base64: $HASH_OUTPUT" >&2
echo "hashes=$HASH_OUTPUT" >> "$GITHUB_OUTPUT"
- name: Upload binaries
uses: actions/upload-artifact@v4
with:
name: binaries
path: groundseg_*_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}
provenance:
needs: [backend-build]
permissions:
actions: read
id-token: write
contents: write
uses: slsa-framework/slsa-github-generator/.github/workflows/[email protected]
with:
base64-subjects: "${{ needs.backend-build.outputs.hashes }}"
deploy:
needs: [args, backend-build, provenance]
permissions: write-all
if: ${{ github.event.inputs.release_channel != 'nobuild' }}
runs-on: ubuntu-latest
steps:
- name: Download binaries
uses: actions/download-artifact@v4
with:
name: binaries
- name: Download blobs
uses: actions/download-artifact@v4
with:
name: build-outputs
path: artifacts
- name: Download blobs
uses: actions/download-artifact@v4
with:
name: multiple.intoto.jsonl
- name: Deploy Files
run: |
mkdir -p ~/.config/rclone/
echo "${{ env.RCLONE_CONFIG }}" > ~/.config/rclone/rclone.conf
DEBIAN_FRONTEND=noninteractive sudo apt update
DEBIAN_FRONTEND=noninteractive sudo apt install rclone jq -y
for arch in amd64 arm64; do
rclone -vvv --config ~/.config/rclone/rclone.conf copy groundseg_${arch}_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }} r2:groundseg/bin
done
if [ -d "artifacts/version/glob" ]; then
GLOB_HASH=$(cat artifacts/version/glob/hash.txt)
rclone -vvv --config ~/.config/rclone/rclone.conf copy artifacts/version/glob/gallseg-${GLOB_HASH}.glob r2:groundseg/glob
fi
mv multiple.intoto.jsonl groundseg_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}.jsonl
rclone -vvv --config ~/.config/rclone/rclone.conf copy groundseg_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}.jsonl r2:groundseg/bin
VERSION_SERVER="${{ github.event.inputs.version_server }}"
for arch in amd64 arm64; do
curl -X PUT -H "X-Api-Key: ${VERSION_AUTH}" -H 'Content-Type: application/json' \
"https://${VERSION_SERVER}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/${arch}_url/payload" \
-d "{\"value\":\"https://files.native.computer/bin/groundseg_${arch}_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}\"}"
if [[ "${{github.event.inputs.to_canary}}" -eq "true" ]]; then
curl -X PUT -H "X-Api-Key: ${VERSION_AUTH}" -H 'Content-Type: application/json' \
"https://${VERSION_SERVER}/modify/groundseg/canary/groundseg/${arch}_url/payload" \
-d "{\"value\":\"https://files.native.computer/bin/groundseg_${arch}_canary_${{ needs.args.outputs.bin-tag }}\"}"
fi
done
AMD64_BIN="groundseg_amd64_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}"
ARM64_BIN="groundseg_arm64_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}"
AMDSHA=$(sha256sum "$AMD64_BIN" | awk '{print $1}')
ARMSHA=$(sha256sum "$ARM64_BIN" | awk '{print $1}')
curl -X PUT -H "X-Api-Key: ${{ env.VERSION_AUTH }}" \
"https://${{ github.event.inputs.version_server }}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/amd64_sha256/$AMDSHA"
curl -X PUT -H "X-Api-Key: ${{ env.VERSION_AUTH }}" \
"https://${{ github.event.inputs.version_server }}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/arm64_sha256/$ARMSHA"
curl -X PUT -H "X-Api-Key: ${VERSION_AUTH}" -H 'Content-Type: application/json' \
"https://${VERSION_SERVER}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/slsa_url/payload" \
-d "{\"value\":\"https://files.native.computer/bin/groundseg_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}.jsonl\"}"
VERSION=$(echo "${{ needs.args.outputs.bin-tag }}" | sed 's/-rc[0-9]*//')
MAJOR=$(echo "$VERSION" | cut -d'.' -f1 | sed 's/v//')
MINOR=$(echo "$VERSION" | cut -d'.' -f2)
PATCH=$(echo "$VERSION" | cut -d'.' -f3)
is_number() {
[[ "$1" =~ ^[0-9]+$ ]]
}
if is_number "$MAJOR" && is_number "$MINOR" && is_number "$PATCH"; then
echo "All version components are valid numbers. Sending to version server..."
curl -X PUT -H "X-Api-Key: ${{ env.VERSION_AUTH }}" \
"https://${{ github.event.inputs.version_server }}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/major/$MAJOR"
curl -X PUT -H "X-Api-Key: ${{ env.VERSION_AUTH }}" \
"https://${{ github.event.inputs.version_server }}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/minor/$MINOR"
curl -X PUT -H "X-Api-Key: ${{ env.VERSION_AUTH }}" \
"https://${{ github.event.inputs.version_server }}/modify/groundseg/${{ needs.args.outputs.channel }}/groundseg/patch/$PATCH"
else
echo "Skipping version server semver update."
echo "Major: $MAJOR, Minor: $MINOR, Patch: $PATCH"
fi
- name: Create Release and Upload Assets
if: ${{ github.event.inputs.version_server == 'version.groundseg.app' }}
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.args.outputs.bin-tag }}
name: Release ${{ needs.args.outputs.bin-tag }} (${{ needs.args.outputs.channel }})
draft: false
prerelease: ${{ contains(needs.args.outputs.channel, 'edge') || contains(needs.args.outputs.channel, 'canary') }}
files: |
./groundseg_amd64_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}
./groundseg_arm64_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}
./groundseg_${{ needs.args.outputs.channel }}_${{ needs.args.outputs.bin-tag }}.jsonl