Repository navigation
276 lines (258 loc) · 10.5 KB
/
Copy pathfork-release.yml
File metadata and controls
276 lines (258 loc) · 10.5 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
name: Fork release
# Builds and publishes camerontaylor/jcode releases for the hosts that run it:
# Linux x86_64 and arm64 (native Ubuntu 24.04, glibc 2.39 baseline), macOS
# arm64, macOS x86_64. The portable glibc 2.17 Linux x86_64 build is manual
# only (workflow_dispatch with linux_compat) and never a release asset.
#
# Caching: GitHub caches saved under a tag are invisible to the next tag, so
# release builds only restore. Pushes to custom (the default branch) run the
# same build matrix without publishing, purely to save warm caches that the
# next tag build can read.
# `jcode update`, auto-update and the agents repo's harness-update all read
# this fork's latest release (GITHUB_REPO in crates/jcode-app-core/src/update.rs).
#
# Tag scheme: vMAJOR.MINOR.PATCH+fork.pN, where PATCH is upstream patch *
# 1000 + fork build and N identifies upstream v1.0.0-preview.N.
# Example: v0.99.1004+fork.p199. Build metadata preserves numeric precedence.
# Upstream's release.yml is gated to 1jehuang/jcode and skips itself here.
env:
JCODE_CI: "1"
RELEASE_TAG: ${{ inputs.tag || github.ref_name }}
# "true" for a tag push or a dispatch naming a tag; "false" for cache warming.
IS_RELEASE: ${{ (inputs.tag || github.ref_type == 'tag') && 'true' || 'false' }}
CARGO_BUILD_RUSTC_WRAPPER: ""
CARGO_TERM_COLOR: always
CARGO_INCREMENTAL: "0"
CARGO_PROFILE_RELEASE_OPT_LEVEL: "3"
JUSTRUST_TOOLCHAIN: system
JUSTRUST_SLOTS: "0"
JUSTRUST_NO_TELEMETRY: "1"
on:
push:
tags:
- "v*"
branches:
- custom
paths-ignore:
- "docs/**"
- "**/*.md"
workflow_dispatch:
inputs:
tag:
description: Existing fork tag to release (vMAJOR.MINOR.PATCH+fork.pN); empty = warm caches only
required: false
type: string
linux_compat:
description: Also build the portable glibc 2.17 Linux x86_64 binary (workflow artifact only)
required: false
type: boolean
default: false
concurrency:
group: fork-release-${{ inputs.tag || github.ref_name }}
# Never cancel a release; a newer custom push supersedes a cache-warm run.
cancel-in-progress: ${{ !(inputs.tag || github.ref_type == 'tag') }}
permissions:
contents: write
jobs:
preflight:
name: Validate release provenance
if: github.repository == 'camerontaylor/jcode' && (inputs.tag || github.ref_type == 'tag')
runs-on: ubuntu-latest
outputs:
tagged_sha: ${{ steps.provenance.outputs.tagged_sha }}
upstream_sha: ${{ steps.provenance.outputs.upstream_sha }}
custom_sha: ${{ steps.provenance.outputs.custom_sha }}
steps:
- name: Validate fork release tag
shell: bash
run: |
set -euo pipefail
if [[ ! "$RELEASE_TAG" =~ ^v(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\+fork\.p([1-9][0-9]*)$ ]]; then
echo "Expected vMAJOR.MINOR.PATCH+fork.pN, got: $RELEASE_TAG" >&2
exit 1
fi
- uses: actions/checkout@v4
with:
ref: ${{ env.RELEASE_TAG }}
fetch-depth: 0
- name: Verify upstream base
id: provenance
shell: bash
run: |
set -euo pipefail
upstream=https://github.com/1jehuang/jcode
preview=${RELEASE_TAG##*+fork.p}
upstream_tag="v1.0.0-preview.$preview"
refs=$(git ls-remote "$upstream" "refs/tags/$upstream_tag" "refs/tags/$upstream_tag^{}")
upstream_sha=$(printf '%s\n' "$refs" | awk '$2 ~ /\^\{\}$/ { print $1; exit }')
if [ -z "$upstream_sha" ]; then
upstream_sha=$(printf '%s\n' "$refs" | awk 'NF == 2 { print $1; exit }')
fi
if [ -z "$upstream_sha" ]; then
echo "Upstream tag $upstream_tag does not exist in $upstream" >&2
exit 1
fi
# Fetch the commit without importing upstream tags into the fork.
git fetch --no-tags "$upstream" "$upstream_sha"
tagged_sha=$(git rev-parse HEAD)
if ! git merge-base --is-ancestor "$upstream_sha" "$tagged_sha"; then
echo "tag p$preview does not match the fork's upstream base" >&2
exit 1
fi
custom_sha=$(git merge-base refs/remotes/origin/custom "$tagged_sha")
printf 'tagged_sha=%s\nupstream_sha=%s\ncustom_sha=%s\n' \
"$tagged_sha" "$upstream_sha" "$custom_sha" >> "$GITHUB_OUTPUT"
build:
name: Build (${{ matrix.artifact }})
needs: preflight
# preflight is skipped on cache-warm runs; build must still run then.
if: github.repository == 'camerontaylor/jcode' && !failure() && !cancelled()
runs-on: ${{ matrix.os }}
timeout-minutes: 120
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
target: x86_64-unknown-linux-gnu
artifact: jcode-linux-x86_64
- os: ubuntu-24.04-arm
target: aarch64-unknown-linux-gnu
artifact: jcode-linux-aarch64
- os: macos-latest
target: aarch64-apple-darwin
artifact: jcode-macos-aarch64
- os: macos-15-intel
target: x86_64-apple-darwin
artifact: jcode-macos-x86_64
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.IS_RELEASE == 'true' && env.RELEASE_TAG || github.sha }}
# build-meta and build_linux_compat.sh embed git log -700 for /changelog.
fetch-depth: 0
- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
cache-all-crates: "true"
# Tag-scoped caches can't be read by the next tag; only custom saves.
save-if: ${{ github.ref == 'refs/heads/custom' }}
- name: Build native binary
run: cargo build --locked --release --target ${{ matrix.target }}
env:
JCODE_RELEASE_BUILD: "1"
JCODE_CI_BUILD: "1"
JCODE_BUILD_SEMVER: ${{ env.RELEASE_TAG }}
- name: Package Linux binary
if: runner.os == 'Linux'
run: |
# Launcher plus .bin, the layout build_linux_compat.sh also produces. jcode's updater installs the launcher (the non-.bin entry)
# and the files beside it; harness-update extracts the .bin.
mkdir -p dist
cp target/${{ matrix.target }}/release/jcode dist/${{ matrix.artifact }}.bin
cat > dist/${{ matrix.artifact }} <<'LAUNCHER'
#!/usr/bin/env sh
set -eu
self_path=$0
if command -v readlink >/dev/null 2>&1; then
resolved=$(readlink -f -- "$0" 2>/dev/null || true)
if [ -n "$resolved" ]; then
self_path=$resolved
fi
fi
self_dir=$(CDPATH= cd -- "$(dirname -- "$self_path")" && pwd)
exec "$self_dir/${{ matrix.artifact }}.bin" "$@"
LAUNCHER
chmod +x dist/${{ matrix.artifact }} dist/${{ matrix.artifact }}.bin
cd dist && tar czf ${{ matrix.artifact }}.tar.gz ${{ matrix.artifact }} ${{ matrix.artifact }}.bin
- name: Package macOS binary
if: runner.os == 'macOS'
run: |
mkdir -p dist
cp target/${{ matrix.target }}/release/jcode dist/${{ matrix.artifact }}
chmod +x dist/${{ matrix.artifact }}
# Stable ad-hoc signing identity (see upstream release.yml, #621).
codesign --force --sign - --identifier com.jcode.cli dist/${{ matrix.artifact }}
cd dist && tar czf ${{ matrix.artifact }}.tar.gz ${{ matrix.artifact }}
- name: Check embedded version
if: env.IS_RELEASE == 'true'
shell: bash
run: |
set -euo pipefail
bin=dist/${{ matrix.artifact }}
[ -f "$bin.bin" ] && bin="$bin.bin"
version="$("$bin" --no-update --no-selfdev version 2>/dev/null | head -1 || "$bin" --version)"
echo "$version"
case "$version" in
*"${RELEASE_TAG#v}"*) ;;
*) echo "binary does not report ${RELEASE_TAG}" >&2; exit 1 ;;
esac
- uses: actions/upload-artifact@v4
if: env.IS_RELEASE == 'true'
with:
name: ${{ matrix.artifact }}
path: dist/${{ matrix.artifact }}.tar.gz
build-linux-compat:
name: Build (portable Linux x86_64, manual)
if: github.repository == 'camerontaylor/jcode' && github.event_name == 'workflow_dispatch' && inputs.linux_compat
runs-on: ubuntu-22.04
timeout-minutes: 120
steps:
- uses: actions/checkout@v4
with:
ref: ${{ env.IS_RELEASE == 'true' && env.RELEASE_TAG || github.sha }}
fetch-depth: 0
- name: Build portable Linux x86_64 binary (glibc 2.17)
run: scripts/build_linux_compat.sh dist
env:
JCODE_RELEASE_BUILD: "1"
JCODE_CI_BUILD: "1"
JCODE_BUILD_SEMVER: ${{ env.RELEASE_TAG }}
JCODE_COMPAT_ARTIFACT: jcode-linux-x86_64
# Not named jcode-*: the release job only publishes jcode-* artifacts.
- uses: actions/upload-artifact@v4
with:
name: compat-jcode-linux-x86_64
path: dist/jcode-linux-x86_64.tar.gz
release:
name: Publish release
needs: [preflight, build]
if: (inputs.tag || github.ref_type == 'tag') && needs.preflight.result == 'success' && needs.build.result == 'success'
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
path: dist
pattern: jcode-*
merge-multiple: true
- name: Publish
env:
GH_TOKEN: ${{ github.token }}
TAGGED_SHA: ${{ needs.preflight.outputs.tagged_sha }}
UPSTREAM_SHA: ${{ needs.preflight.outputs.upstream_sha }}
CUSTOM_SHA: ${{ needs.preflight.outputs.custom_sha }}
run: |
set -euo pipefail
cd dist
for a in jcode-linux-x86_64 jcode-linux-aarch64 jcode-macos-aarch64 jcode-macos-x86_64; do
test -s "$a.tar.gz"
done
sha256sum *.tar.gz > SHA256SUMS
cat SHA256SUMS
version=${RELEASE_TAG#v}
version=${version%%+*}
preview=${RELEASE_TAG##*+fork.p}
upstream_tag="v1.0.0-preview.$preview"
cat > release-notes.txt <<EOF
Fork release $RELEASE_TAG
Tagged commit: $TAGGED_SHA
Upstream base: $upstream_tag ($UPSTREAM_SHA)
Custom base SHA: $CUSTOM_SHA
EOF
gh release create "$RELEASE_TAG" --repo "$GITHUB_REPOSITORY" \
--title "jcode fork $version (upstream $upstream_tag)" --latest \
--notes-file release-notes.txt \
./*.tar.gz SHA256SUMS