Repository navigation
198 lines (179 loc) · 7.97 KB
/
Copy pathpatch-release.yml
File metadata and controls
198 lines (179 loc) · 7.97 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
name: Patch Release (re-upload assets to an existing tag)
# Use this workflow when you want to ship a small fix to an already-published
# release WITHOUT cutting a new version. It:
#
# 1. Rebuilds all five platform binaries from the current `main` HEAD.
# 2. Force-moves the existing tag forward to that HEAD so the source the
# tag points at matches the binaries.
# 3. Re-uploads the binary archives + install scripts to the existing
# release, overwriting the old assets.
# 4. Leaves the release page's title, body, contributors, and "Full
# Changelog" link untouched.
#
# Refuses to run if Cargo.toml has been bumped past the patched tag — that's a
# real release, not a patch, so use `.github/workflows/release.yml` instead.
#
# This force-moves a published tag. Users who already downloaded the old
# binary are unaffected (they keep what they have); users who install fresh
# get the patched build.
on:
workflow_dispatch:
inputs:
version:
description: 'Existing tag to amend (e.g., v0.1.0)'
required: true
type: string
patch_note:
description: 'Optional markdown bullet to prepend under "## 🩹 Patches". Leave blank to skip body edit.'
required: false
type: string
default: ''
# Share the normal release group so asset replacement cannot overlap a release.
concurrency:
group: coven-code-release-publication
cancel-in-progress: false
permissions:
contents: write
env:
CARGO_TERM_COLOR: always
PATCH_RELEASE_VERSION: ${{ inputs.version }}
jobs:
# ── Preflight ───────────────────────────────────────────────────────
preflight:
runs-on: ubuntu-latest
name: Preflight checks
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate version input
run: |
if [[ ! "$PATCH_RELEASE_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$ ]]; then
echo "::error::Invalid version: $PATCH_RELEASE_VERSION"
echo "::error::Expected a tag like v1.2.3 or v1.2.3-rc.1."
exit 1
fi
- name: Must be on main branch
run: |
if [[ "${{ github.ref }}" != "refs/heads/main" ]]; then
echo "::error::Patch releases must be triggered from the main branch (got ${{ github.ref }})"
exit 1
fi
- name: Target release must already exist
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if ! gh release view "$PATCH_RELEASE_VERSION" \
--repo "${{ github.repository }}" >/dev/null 2>&1; then
echo "::error::Release $PATCH_RELEASE_VERSION does not exist."
echo "::error::To cut a brand-new release, use the regular Release workflow instead."
exit 1
fi
- name: Cargo.toml version must still match the patched tag
run: |
CARGO_VERSION=$(grep '^version' src-rust/Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
TAG_VERSION="$PATCH_RELEASE_VERSION"
TAG_VERSION="${TAG_VERSION#v}" # strip leading v
if [[ "$CARGO_VERSION" != "$TAG_VERSION" ]]; then
echo "::error::Cargo.toml ($CARGO_VERSION) does not match patched tag ($TAG_VERSION)."
echo "::error::Patch releases must not bump the version — use the regular Release workflow if you intend to ship a new version."
exit 1
fi
echo "Version still pinned at $CARGO_VERSION — safe to patch in place."
# ── Build: the five targets, in release-build.yml ──────────────────
# Same build as release.yml, with the patch release's own inputs: its
# checkout keeps credentials and it installs libssl-dev.
build:
needs: preflight
uses: ./.github/workflows/release-build.yml
with:
persist-credentials: true
openssl: true
cargo-term-color: always
# ── Re-upload assets to the existing release ────────────────────────
patch:
needs: build
runs-on: ubuntu-latest
name: Replace release assets
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
path: artifacts
- uses: actions/setup-python@v6
with:
python-version: '3.12'
- name: Validate and package release artifacts
run: |
python scripts/package-release.py artifacts release
node scripts/generate-release-checksums.mjs release
ls -lh release/
# Force-move the tag to the current HEAD so that source pinned by the
# tag matches the binaries we're about to upload. Without this, the
# tag still points at the original commit and the assets diverge from
# the source — confusing for anyone running `git checkout v0.1.0`.
- name: Move tag to patched HEAD
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -f "$PATCH_RELEASE_VERSION" "${{ github.sha }}"
git push -f origin "refs/tags/$PATCH_RELEASE_VERSION"
echo "Tag $PATCH_RELEASE_VERSION now points at ${{ github.sha }}."
# `gh release upload --clobber` overwrites assets one at a time without
# touching the release body, name, draft state, or prerelease flag.
# That's exactly what we want — the release page reads the same; only
# the download links serve fresh bytes.
- name: Replace release assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -euo pipefail
for f in release/*; do
echo "→ Uploading $(basename "$f")"
done
gh release upload "$PATCH_RELEASE_VERSION" \
release/coven-code-*.tar.gz \
release/coven-code-*.zip \
release/install.sh \
release/install.ps1 \
--repo "${{ github.repository }}" \
--clobber
# Publish the manifest last. A concurrent install can fail closed
# during replacement, but cannot accept new bytes with an old hash.
gh release upload "$PATCH_RELEASE_VERSION" release/SHA256SUMS \
--repo "${{ github.repository }}" \
--clobber
# Prepend the patch bullet to the release body, idempotent: if a
# `## 🩹 Patches` section already exists, subsequent bullets stack into
# the same list at the top instead of creating duplicate sections.
# Skipped when no patch_note was provided (e.g. manual asset-only
# re-upload from the Actions UI).
- name: Append patch note to release body
if: inputs.patch_note != ''
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
REPO: ${{ github.repository }}
TAG: ${{ inputs.version }}
PATCH_BULLET: ${{ inputs.patch_note }}
run: python3 scripts/append-patch-note.py
- name: Summary
env:
PATCH_RELEASE_NOTE: ${{ inputs.patch_note }}
run: |
{
echo "## ✅ Patched $PATCH_RELEASE_VERSION in place"
echo
echo "- Tag force-moved to commit \`${{ github.sha }}\`."
echo "- 5 binary archives + install scripts rebuilt and re-uploaded."
if [[ -n "$PATCH_RELEASE_NOTE" ]]; then
echo "- Release body received a new bullet under \`## 🩹 Patches\` at the top."
else
echo "- Release title, body, contributors, and Full Changelog link unchanged."
fi
echo
echo "Anyone who installs fresh from \`releases/latest/download/…\` will pick up the patched build."
echo "Existing installs are **not** auto-updated — users must reinstall or run \`coven-code upgrade --force\`."
} >> "$GITHUB_STEP_SUMMARY"