-
Notifications
You must be signed in to change notification settings - Fork 0
283 lines (258 loc) · 8.83 KB
/
Copy pathrelease.yml
File metadata and controls
283 lines (258 loc) · 8.83 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
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
tag:
description: 'Release tag (e.g. v0.1.0). Required for manual runs.'
required: true
type: string
permissions:
contents: write
packages: write
jobs:
resolve-tag:
runs-on: ubuntu-22.04
outputs:
tag: ${{ steps.t.outputs.tag }}
version: ${{ steps.t.outputs.version }}
steps:
- id: t
run: |
if [ "${GITHUB_EVENT_NAME}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF#refs/tags/}"
fi
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then
echo "::error::Tag '$TAG' does not match v*.*.*"
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
echo "version=${TAG#v}" >> "$GITHUB_OUTPUT"
lint-shell:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y shellcheck
- name: Shellcheck installer + bootstrap scripts
run: |
shopt -s globstar nullglob
FILES=()
for p in installer/bootstrap/*.sh installer/stage2/common/*.sh installer/stage2/linux/*.sh install.sh; do
[ -f "$p" ] && FILES+=("$p")
done
if [ ${#FILES[@]} -gt 0 ]; then
shellcheck "${FILES[@]}"
else
echo "No shell scripts to lint"
fi
build-image:
runs-on: ubuntu-22.04
needs: [resolve-tag, lint-shell]
outputs:
image: ${{ steps.meta.outputs.image }}
digest: ${{ steps.push.outputs.digest }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute image refs
id: meta
run: |
OWNER="${GITHUB_REPOSITORY_OWNER,,}"
IMG="ghcr.io/${OWNER}/cortexsim"
TAG="${{ needs.resolve-tag.outputs.tag }}"
{
echo "image=${IMG}"
echo "tags=${IMG}:${TAG},${IMG}:latest"
} >> "$GITHUB_OUTPUT"
- name: Build and push
id: push
uses: docker/build-push-action@v5
with:
context: .
file: core/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: false
build-stage2:
runs-on: ubuntu-22.04
needs: resolve-tag
steps:
- uses: actions/checkout@v4
- name: Prepare release dir
run: mkdir -p dist
- name: Package stage2-linux.tar.gz
run: |
if [ -d installer/stage2/linux ] || [ -d installer/stage2/common ]; then
tar -C installer/stage2 \
--exclude='*.zip' --exclude='*.tar.gz' \
-czf dist/stage2-linux.tar.gz \
$([ -d installer/stage2/common ] && echo common) \
$([ -d installer/stage2/linux ] && echo linux)
else
echo "no stage2 linux assets — skipping" && touch dist/.no-stage2-linux
fi
- name: Package stage2-windows.zip
run: |
if [ -d installer/stage2/windows ] || [ -d installer/stage2/common ]; then
sudo apt-get update && sudo apt-get install -y zip
( cd installer/stage2 && \
zip -r "${GITHUB_WORKSPACE}/dist/stage2-windows.zip" \
$([ -d common ] && echo common) \
$([ -d windows ] && echo windows) \
-x '*.tar.gz' '*.zip' )
else
echo "no stage2 windows assets — skipping" && touch dist/.no-stage2-windows
fi
- name: Stage bootstrap scripts (or fall back to legacy install.sh)
run: |
if [ -f installer/bootstrap/install.sh ]; then
cp installer/bootstrap/install.sh dist/install.sh
elif [ -f install.sh ]; then
cp install.sh dist/install.sh
fi
if [ -f installer/bootstrap/install.ps1 ]; then
cp installer/bootstrap/install.ps1 dist/install.ps1
fi
- uses: actions/upload-artifact@v4
with:
name: stage2-bundles
path: dist/
if-no-files-found: warn
retention-days: 7
manifest:
runs-on: ubuntu-22.04
needs: [resolve-tag, build-image, build-stage2]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: stage2-bundles
path: dist/
- name: Generate SHA256SUMS
working-directory: dist
run: |
rm -f .no-stage2-linux .no-stage2-windows
if compgen -G "*" > /dev/null; then
sha256sum * > SHA256SUMS
cat SHA256SUMS
else
echo "no artifacts to checksum"
: > SHA256SUMS
fi
- name: Generate manifest.json
working-directory: dist
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
IMAGE: ${{ needs.build-image.outputs.image }}
DIGEST: ${{ needs.build-image.outputs.digest }}
REPO: ${{ github.repository }}
run: |
python3 - <<'PY'
import hashlib, json, os, pathlib, datetime
d = pathlib.Path(".")
tag = os.environ["TAG"]
artifacts = []
for p in sorted(d.iterdir()):
if p.name in ("SHA256SUMS", "manifest.json") or p.is_dir():
continue
h = hashlib.sha256(p.read_bytes()).hexdigest()
artifacts.append({
"name": p.name,
"size": p.stat().st_size,
"sha256": h,
"url": f"https://github.com/{os.environ['REPO']}/releases/download/{tag}/{p.name}",
})
manifest = {
"schema_version": 1,
"release": tag,
"generated_at": datetime.datetime.utcnow().isoformat(timespec="seconds") + "Z",
"image": {
"ref": f"{os.environ['IMAGE']}:{tag}",
"latest": f"{os.environ['IMAGE']}:latest",
"digest": os.environ.get("DIGEST", ""),
"platforms": ["linux/amd64", "linux/arm64"],
},
"artifacts": artifacts,
}
pathlib.Path("manifest.json").write_text(json.dumps(manifest, indent=2) + "\n")
print(pathlib.Path("manifest.json").read_text())
PY
- uses: actions/upload-artifact@v4
with:
name: release-bundle
path: dist/
retention-days: 30
release:
runs-on: ubuntu-22.04
needs: [resolve-tag, manifest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
name: release-bundle
path: dist/
- name: Generate release notes
id: notes
env:
TAG: ${{ needs.resolve-tag.outputs.tag }}
run: |
PREV=$(git describe --tags --abbrev=0 "${TAG}^" 2>/dev/null || echo "")
{
echo "## CortexSim ${TAG}"
echo
echo "**Container image** — \`ghcr.io/${GITHUB_REPOSITORY_OWNER,,}/cortexsim:${TAG}\` (linux/amd64, linux/arm64)"
echo
echo "**One-line install (Linux jumpbox):**"
echo
echo '```bash'
echo "curl -fsSL https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}/install.sh | sudo bash"
echo '```'
echo
echo "Verify artifact integrity with \`SHA256SUMS\` or \`manifest.json\`."
echo
if [ -n "$PREV" ]; then
echo "### Changes since ${PREV}"
git log --pretty='- %s (%h)' "${PREV}..${TAG}" | head -100
else
echo "### Initial release"
fi
} > NOTES.md
echo "path=NOTES.md" >> "$GITHUB_OUTPUT"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ needs.resolve-tag.outputs.tag }}
run: |
ASSETS=()
for f in dist/*; do
[ -f "$f" ] && ASSETS+=("$f")
done
if gh release view "$TAG" >/dev/null 2>&1; then
gh release upload "$TAG" "${ASSETS[@]}" --clobber
gh release edit "$TAG" --notes-file NOTES.md
else
gh release create "$TAG" \
--title "CortexSim $TAG" \
--notes-file NOTES.md \
"${ASSETS[@]}"
fi