Repository navigation
308 lines (289 loc) · 13.9 KB
/
Copy pathrelease.yml
File metadata and controls
308 lines (289 loc) · 13.9 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
name: Release
# Fires when a release PR (dev -> master, titled vX.Y.Z) is merged, or via manual
# dispatch (re-run / bootstrap). The git tag is the single source of truth: this
# workflow builds the optimized binary per platform with the version injected at
# compile time (make ... RAY_VERSION=X.Y.Z) and publishes a GitHub Release. No
# source file is bumped and nothing is pushed to the protected master branch —
# only a tag ref and a release, which GITHUB_TOKEN can do without a bypass token.
# The one push is the merge-back job, which updates dev and needs the PAT secret.
# Non-release merges to master (title not vX.Y.Z) are ignored.
#
# IMPORTANT: a DRAFT release does NOT create its git tag yet — the tag is only
# materialized when the release is published (the `publish` job, draft=false). So
# the `build` job must check out the target COMMIT, never the not-yet-existing
# tag. (This is the bug that broke the first v2.1.0 attempt.)
on:
pull_request:
branches: [master]
types: [closed]
workflow_dispatch:
inputs:
version:
description: "Release version, no leading v (e.g. 2.1.0)"
required: true
permissions:
contents: write # create the tag + the GitHub Release
jobs:
prepare:
permissions:
contents: write
pull-requests: read # exact merged release PR source provenance
# Manual dispatch always runs; the PR path only on an actual merge whose
# title declares a release version.
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.title, 'v'))
runs-on: ubuntu-latest
outputs:
version: ${{ steps.parse.outputs.version }}
sha: ${{ steps.parse.outputs.sha }}
steps:
# Full history + tags so the changelog generator can scope to the previous
# release tag.
- uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
- name: Resolve version + target, ensure draft release
id: parse
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
GITHUB_REPOSITORY: ${{ github.repository }}
EVENT: ${{ github.event_name }}
PR_TITLE: ${{ github.event.pull_request.title }}
MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
PR_SOURCE_SHA: ${{ github.event.pull_request.head.sha }}
INPUT_VERSION: ${{ github.event.inputs.version }}
DISPATCH_SHA: ${{ github.sha }}
run: |
set -euo pipefail
if [ "$EVENT" = "workflow_dispatch" ]; then
VERSION="$INPUT_VERSION"
SHA="$DISPATCH_SHA"
else
if [[ ! "$PR_TITLE" =~ ^v([0-9]+\.[0-9]+\.[0-9]+)$ ]]; then
echo "Merged PR title '$PR_TITLE' is not a release version — skipping."
exit 1
fi
VERSION="${BASH_REMATCH[1]}"
SHA="$MERGE_SHA"
fi
if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Version '$VERSION' is not X.Y.Z"; exit 1
fi
# Idempotent: reuse an existing draft (so re-runs don't error), and
# always build from the release's OWN target so the artifacts match the
# tag that publish will create at that commit.
if gh release view "v$VERSION" >/dev/null 2>&1; then
SHA="$(gh release view "v$VERSION" --json targetCommitish -q .targetCommitish)"
echo "Release v$VERSION already exists — building from its target $SHA."
else
# Feature-oriented changelog (grouped by conventional-commit type),
# not GitHub's default author/PR ledger.
# Pin only the notes source; SHA remains the artifact/build/tag target.
notes_args=("$VERSION" "$SHA")
if [ "$EVENT" = "workflow_dispatch" ]; then
notes_args+=(--allow-direct-merge)
else
export RELEASE_SOURCE_SHA="$PR_SOURCE_SHA"
fi
bash .github/release-notes.sh "${notes_args[@]}" > "$RUNNER_TEMP/notes.md"
gh release create "v$VERSION" \
--target "$SHA" \
--title "v$VERSION" \
--notes-file "$RUNNER_TEMP/notes.md" \
--draft
echo "Created draft release v$VERSION at $SHA."
fi
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
build:
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# Distributables must be PORTABLE, not -march=native: a native binary
# built on a runner can SIGILL on a different/older CPU. x86-64-v3 =
# AVX2 baseline (~2013+), which keeps the engine's vectorized reductions
# fast. The macOS runner is the oldest Apple-Silicon class, so native
# there is effectively a safe floor (arm64 has no x86-style optional-ISA
# traps, and baselining to armv8-a would only lose M1 tuning).
include:
- os: ubuntu-latest
march: x86-64-v3
- os: macos-latest
march: native
# Windows is not build-ready yet (IOCP stub, unguarded POSIX in
# main.c/heap.c, no Makefile path). Add once the port lands:
# - os: windows-latest
steps:
# The tag does not exist yet (the release is still a draft); check out the
# target COMMIT directly — never `ref: v$VERSION`.
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.sha }}
# The Linux distributable is built with the pinned upstream Clang that
# ci.yml's clang-current job tests with, not with whatever Clang the
# runner image ships: the release compiler then changes when the action
# is bumped, not when ubuntu-latest moves. macOS keeps Apple Clang. A
# release target that predates the action (a re-run of an older release)
# builds with the runner's Clang, as it did.
- name: Install the current Clang (Linux)
if: runner.os == 'Linux' && hashFiles('.github/actions/setup-clang-current/action.yml') != ''
uses: ./.github/actions/setup-clang-current
- name: Build release artifact (portable)
run: make dist RAY_VERSION=${{ needs.prepare.outputs.version }} RAY_MARCH=${{ matrix.march }} ${CLANG_CURRENT:+CC=$CLANG_CURRENT}
- name: Upload artifacts to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
set -euo pipefail
gh release upload "v${{ needs.prepare.outputs.version }}" \
dist/*.tar.gz dist/*.sha256 --clobber
# Package the just-built (already-portable) Linux binary as a .deb —
# `make dist` left ./rayforce in place, so no rebuild is needed.
- name: Build .deb (Linux)
if: matrix.os == 'ubuntu-latest'
env:
RAY_VERSION: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
ver="$(curl -fsSL https://api.github.com/repos/goreleaser/nfpm/releases/latest | grep -oP '"tag_name":\s*"\K[^"]+')"
curl -fsSL "https://github.com/goreleaser/nfpm/releases/download/${ver}/nfpm_${ver#v}_amd64.deb" -o /tmp/nfpm.deb
sudo dpkg -i /tmp/nfpm.deb
mkdir -p dist
nfpm pkg --packager deb --config packaging/nfpm.yaml --target dist/
ls -l dist/*.deb
- name: Upload .deb to release (Linux)
if: matrix.os == 'ubuntu-latest'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release upload "v${{ needs.prepare.outputs.version }}" dist/*.deb --clobber
publish:
needs: [prepare, build]
runs-on: ubuntu-latest
steps:
# Flipping the draft to public is what creates the git tag vX.Y.Z at the
# release's target commit — the single source of truth for the version.
- name: Publish release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: gh release edit "v${{ needs.prepare.outputs.version }}" --draft=false
# Merge the release commit back into dev, so the next release PR isn't out of
# date with master or full of phantom conflicts after a squash. It needs only
# `prepare`: the commit is on master whether or not the build succeeds. It is
# NOT best-effort: a failure here blocks the next release, so it must show red.
# Manual dispatch has no PR head to verify against, so it skips this job.
merge-back:
needs: prepare
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
# The helper runs from the release commit, not from whatever dev holds
# when the job starts: the release is immutable and was reviewed as part
# of the release PR, and dev is the branch the helper is about to write.
# GITHUB_TOKEN can't push past dev's required checks; the PAT's owner can.
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 0
token: ${{ secrets.PAT }}
- name: Merge the release into dev
env:
VERSION: ${{ needs.prepare.outputs.version }}
PR: ${{ github.event.pull_request.number }}
RELEASE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
run: |
set -euo pipefail
git config user.name "rayforce-release"
git config user.email "[email protected]"
# The helper switches the working tree to dev, so run a copy that
# the switch can't replace while bash is still reading it.
cp .github/release-merge-back.sh "$RUNNER_TEMP/merge-back.sh"
bash "$RUNNER_TEMP/merge-back.sh" "$VERSION" "$PR" "$RELEASE_SHA" "$HEAD_SHA"
# Post the release announcement to Zulip (#Announcements > Rayforce) once the
# release is public. Best-effort: skipped when ZULIP_API_KEY isn't configured,
# and continue-on-error so a Zulip hiccup never reds an already-shipped release.
announce:
needs: [prepare, publish]
runs-on: ubuntu-latest
env:
ZULIP_API_KEY: ${{ secrets.ZULIP_API_KEY }}
steps:
- name: Announce on Zulip
if: ${{ env.ZULIP_API_KEY != '' }}
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
VERSION: ${{ needs.prepare.outputs.version }}
run: |
set -euo pipefail
url="https://github.com/${GH_REPO}/releases/tag/v${VERSION}"
# Changelog highlights = the release body minus the collapsed
# "Maintenance & internal" block and hidden provenance (not user-facing).
notes="$(gh release view "v$VERSION" --json body -q .body | sed -e '/<details>/,/<\/details>/d' -e '/^<!-- release-notes-source-v1 /d')"
content="$(printf '🚀 **Rayforce v%s** is out!\n\n%s\n\n📦 Release & downloads: %s' "$VERSION" "$notes" "$url")"
resp="$(curl -sS -X POST 'https://rayforcedb.zulipchat.com/api/v1/messages' \
-u "[email protected]:${ZULIP_API_KEY}" \
--data-urlencode 'type=stream' \
--data-urlencode 'to=Announcements' \
--data-urlencode 'topic=Rayforce' \
--data-urlencode "content=${content}")"
echo "Zulip response: $resp"
echo "$resp" | grep -q '"result": *"success"'
# Bump the Homebrew tap (RayforceDB/homebrew-tap → Formula/rayforce.rb) to this
# release. Best-effort: skipped when HOMEBREW_TAP_TOKEN isn't configured, and
# continue-on-error so a tap hiccup never reds an already-shipped release.
homebrew:
needs: [prepare, publish]
runs-on: ubuntu-latest
env:
HOMEBREW_TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }}
steps:
- uses: actions/checkout@v5
with:
ref: ${{ needs.prepare.outputs.sha }}
- name: Update tap formula
id: update_tap_formula
if: ${{ env.HOMEBREW_TAP_TOKEN != '' }}
continue-on-error: true
env:
VERSION: ${{ needs.prepare.outputs.version }}
GH_REPO: ${{ github.repository }}
TAP_REPO: RayforceDB/homebrew-tap
run: |
set -euo pipefail
# Build-from-source formula: point at the GitHub source tarball for the
# tag and pin its sha256.
url="https://github.com/${GH_REPO}/archive/refs/tags/v${VERSION}.tar.gz"
sha="$(curl -fsSL "$url" | sha256sum | cut -d' ' -f1)"
tmp="$(mktemp -d)"
git clone --depth 1 "https://x-access-token:${HOMEBREW_TAP_TOKEN}@github.com/${TAP_REPO}.git" "$tmp"
mkdir -p "$tmp/Formula"
sed -e "s|__URL__|${url}|" -e "s|__SHA256__|${sha}|" \
packaging/homebrew-formula.rb.tmpl > "$tmp/Formula/rayforce.rb"
cd "$tmp"
git config user.name "rayforce-release"
git config user.email "[email protected]"
git add Formula/rayforce.rb
git commit -m "rayforce ${VERSION}" || { echo "formula unchanged — nothing to push"; exit 0; }
git push origin HEAD
- name: Report failed tap update
if: ${{ steps.update_tap_formula.outcome == 'failure' }}
continue-on-error: true
run: |
echo "::warning title=Homebrew tap update failed::The core release job succeeded, but its best-effort Homebrew update failed. Inspect the tap step before claiming the formula advanced."
{
echo "### Homebrew tap update failed"
echo "The core release job succeeded, but the best-effort tap update did not complete successfully."
echo "Inspect the Update tap formula log and repair the cause privately; do not print credentials."
echo "A green core release does not confirm the Homebrew formula version."
} >> "$GITHUB_STEP_SUMMARY"