Skip to content

Commit 9dfbe46

Browse files
committed
ci(release): allow explicit current-tag rebuilds
1 parent 09e6b10 commit 9dfbe46

2 files changed

Lines changed: 51 additions & 9 deletions

File tree

‎.github/scripts/upstream-release-sync.sh‎

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,9 @@ patch_id_for_commit() {
215215
write_metadata() {
216216
local file="$1" bundle_digest="$2" base_sha="$3" tag="$4" upstream_sha="$5"
217217
local candidate_sha="$6" candidate_tree="$7" head_sha="$8" patch_file="$9"
218+
local rebuild_current="${10}"
218219
jq -n -S \
219-
--argjson schema 1 \
220+
--argjson schema 2 \
220221
--arg repository "$EXPECTED_REPOSITORY" \
221222
--arg base_branch "$BASE_BRANCH" \
222223
--arg generated_ref "$GENERATED_REF" \
@@ -229,12 +230,14 @@ write_metadata() {
229230
--arg head_tree "$candidate_tree" \
230231
--arg bundle_sha256 "$bundle_digest" \
231232
--argjson dry_run "${DRY_RUN:-false}" \
233+
--argjson rebuild_current "$rebuild_current" \
232234
--slurpfile patches "$patch_file" \
233235
'{schema: $schema, repository: $repository, base_branch: $base_branch,
234236
generated_ref: $generated_ref, base_sha: $base_sha, upstream_tag: $upstream_tag,
235237
upstream_sha: $upstream_sha, candidate_sha: $candidate_sha,
236238
candidate_tree: $candidate_tree, head_sha: $head_sha, head_tree: $head_tree,
237-
bundle_sha256: $bundle_sha256, dry_run: $dry_run, patches: $patches}' >"$file"
239+
bundle_sha256: $bundle_sha256, dry_run: $dry_run,
240+
rebuild_current: $rebuild_current, patches: $patches}' >"$file"
238241
}
239242

240243
prepare() {
@@ -243,6 +246,7 @@ prepare() {
243246
local tag marker comparison upstream_sha base_sha candidate_dir candidate_sha candidate_tree head_sha
244247
local index branch tip parent_line parent_count actual_patch_id classification disposition
245248
local patch_file bundle bundle_digest metadata_digest applied=0 skipped=0
249+
local rebuild_current="${REBUILD_CURRENT:-false}"
246250

247251
require_command git
248252
require_command gh
@@ -255,6 +259,14 @@ prepare() {
255259
artifact_name="release-sync-candidate-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
256260
output artifact_name "$artifact_name"
257261
[[ "${DRY_RUN:-false}" == "true" || "${DRY_RUN:-false}" == "false" ]] || die "DRY_RUN must be true or false"
262+
[[ "$rebuild_current" == "true" || "$rebuild_current" == "false" ]] ||
263+
die "REBUILD_CURRENT must be true or false"
264+
if [[ "$rebuild_current" == "true" ]]; then
265+
[[ "${GITHUB_EVENT_NAME:-}" == "workflow_dispatch" ]] ||
266+
die "REBUILD_CURRENT=true is allowed only for workflow_dispatch"
267+
[[ -z "${LATEST_TAG_OVERRIDE:-}" ]] ||
268+
die "REBUILD_CURRENT=true cannot be combined with a tag override"
269+
fi
258270
fetch_inputs
259271
base_sha="$(git rev-parse "${BASE_REF}^{commit}")"
260272
marker="$(git show "${base_sha}:${MARKER_FILE}")" || die "missing release marker on ${BASE_BRANCH}"
@@ -269,6 +281,7 @@ prepare() {
269281
output latest_tag "$tag"
270282
output previous_tag "$marker"
271283
output dry_run "${DRY_RUN:-false}"
284+
output rebuild_current "$rebuild_current"
272285
summary "## Upstream release preparation"
273286
summary "- Base: \`${BASE_BRANCH}@${base_sha}\`"
274287
summary "- Tracked release: \`${marker}\`"
@@ -277,8 +290,13 @@ prepare() {
277290
if [[ -z "${LATEST_TAG_OVERRIDE:-}" ]]; then
278291
((comparison >= 0)) || die "refusing upstream rollback from $marker to $tag"
279292
if ((comparison == 0)); then
280-
summary "- Result: clean no-op"
281-
return
293+
if [[ "$rebuild_current" == "false" ]]; then
294+
summary "- Result: clean no-op"
295+
return
296+
fi
297+
summary "- Current-tag rebuild: explicitly requested by workflow dispatch"
298+
elif [[ "$rebuild_current" == "true" ]]; then
299+
die "REBUILD_CURRENT=true requires the latest upstream tag to equal the tracked marker ($marker); got $tag"
282300
fi
283301
elif ((comparison == 0)); then
284302
summary "- Result: dry-run override equals the marker; clean no-op"
@@ -355,12 +373,14 @@ prepare() {
355373
"$BUNDLE_BASE_REF" "$BUNDLE_UPSTREAM_REF" "$BUNDLE_CANDIDATE_REF" "$BUNDLE_HEAD_REF"
356374
bundle_digest="$(sha256sum "$bundle" | awk '{print $1}')"
357375
write_metadata "$artifact_dir/metadata.json" "$bundle_digest" "$base_sha" "$tag" \
358-
"$upstream_sha" "$candidate_sha" "$candidate_tree" "$head_sha" "$patch_file"
376+
"$upstream_sha" "$candidate_sha" "$candidate_tree" "$head_sha" "$patch_file" \
377+
"$rebuild_current"
359378
metadata_digest="$(sha256sum "$artifact_dir/metadata.json" | awk '{print $1}')"
360379

361380
output state update
362381
output latest_tag "$tag"
363382
output dry_run "${DRY_RUN:-false}"
383+
output rebuild_current "$rebuild_current"
364384
output base_sha "$base_sha"
365385
output head_sha "$head_sha"
366386
output candidate_tree "$candidate_tree"
@@ -385,9 +405,10 @@ validate_metadata() {
385405
--argjson patch_tips "$(printf '%s\n' "${PATCH_TIPS[@]}" | jq -R . | jq -s .)" '
386406
(keys | sort) == (["base_branch", "base_sha", "bundle_sha256", "candidate_sha",
387407
"candidate_tree", "dry_run", "generated_ref", "head_sha", "head_tree", "patches",
388-
"repository", "schema", "upstream_sha", "upstream_tag"] | sort) and
389-
.schema == 1 and .repository == $repository and .base_branch == $base_branch and
408+
"rebuild_current", "repository", "schema", "upstream_sha", "upstream_tag"] | sort) and
409+
.schema == 2 and .repository == $repository and .base_branch == $base_branch and
390410
.generated_ref == $generated_ref and (.dry_run | type) == "boolean" and
411+
(.rebuild_current | type) == "boolean" and
391412
(.upstream_tag | test("^v(0|[1-9][0-9]{0,8})\\.(0|[1-9][0-9]{0,8})\\.(0|[1-9][0-9]{0,8})$")) and
392413
([.base_sha, .upstream_sha, .candidate_sha, .candidate_tree, .head_sha, .head_tree,
393414
.bundle_sha256] | all(test("^[0-9a-f]{40}$") or test("^[0-9a-f]{64}$"))) and
@@ -431,7 +452,8 @@ metadata_value() {
431452
import_artifact() {
432453
local artifact_dir="$1" repo="$2"
433454
local metadata="$artifact_dir/metadata.json" bundle="$artifact_dir/candidate.bundle"
434-
local base_sha upstream_sha candidate_sha candidate_tree head_sha head_tree ref
455+
local base_sha base_marker upstream_sha upstream_tag candidate_sha candidate_tree head_sha head_tree
456+
local rebuild_current ref
435457
validate_artifact "$artifact_dir"
436458
git bundle verify "$bundle" >/dev/null
437459
git init -q "$repo"
@@ -441,7 +463,9 @@ import_artifact() {
441463
"$BUNDLE_CANDIDATE_REF:$BUNDLE_CANDIDATE_REF" \
442464
"$BUNDLE_HEAD_REF:$BUNDLE_HEAD_REF"
443465
base_sha="$(metadata_value "$metadata" .base_sha)"
466+
rebuild_current="$(metadata_value "$metadata" '.rebuild_current | tostring')"
444467
upstream_sha="$(metadata_value "$metadata" .upstream_sha)"
468+
upstream_tag="$(metadata_value "$metadata" .upstream_tag)"
445469
candidate_sha="$(metadata_value "$metadata" .candidate_sha)"
446470
candidate_tree="$(metadata_value "$metadata" .candidate_tree)"
447471
head_sha="$(metadata_value "$metadata" .head_sha)"
@@ -456,8 +480,19 @@ import_artifact() {
456480
[[ "$candidate_tree" == "$head_tree" ]] || die "tested and generated trees differ"
457481
[[ "$(git -C "$repo" rev-list --parents -n 1 "$head_sha")" == "$head_sha $base_sha" ]] ||
458482
die "generated head does not have exactly the recorded base parent"
459-
[[ "$(git -C "$repo" show "${head_sha}:${MARKER_FILE}")" == "$(metadata_value "$metadata" .upstream_tag)" ]] ||
483+
[[ "$(git -C "$repo" show "${head_sha}:${MARKER_FILE}")" == "$upstream_tag" ]] ||
460484
die "candidate marker does not match metadata"
485+
base_marker="$(git -C "$repo" show "${base_sha}:${MARKER_FILE}")" ||
486+
die "recorded base is missing its release marker"
487+
if [[ "$rebuild_current" == "true" ]]; then
488+
[[ "${GITHUB_EVENT_NAME:-}" == "workflow_dispatch" ]] ||
489+
die "current-tag rebuild artifacts are valid only for workflow_dispatch"
490+
[[ "$upstream_tag" == "$base_marker" ]] ||
491+
die "current-tag rebuild metadata does not match the base marker"
492+
else
493+
[[ "$upstream_tag" != "$base_marker" ]] ||
494+
die "non-rebuild artifact unexpectedly retains the base marker"
495+
fi
461496
if git -C "$repo" ls-tree -r --name-only "$head_sha" -- "$WORKFLOW_FILE" "$HELPER_FILE" | grep -q .; then
462497
die "candidate contains dev-only automation files"
463498
fi

‎.github/workflows/upstream-release-sync.yml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ on:
1414
required: false
1515
default: false
1616
type: boolean
17+
rebuild_current:
18+
description: "Rebuild the tracked current stable tag after custom patch-stack changes"
19+
required: false
20+
default: false
21+
type: boolean
1722

1823
permissions: {}
1924

@@ -32,6 +37,7 @@ jobs:
3237
latest_tag: ${{ steps.prepare.outputs.latest_tag }}
3338
previous_tag: ${{ steps.prepare.outputs.previous_tag }}
3439
dry_run: ${{ steps.prepare.outputs.dry_run }}
40+
rebuild_current: ${{ steps.prepare.outputs.rebuild_current }}
3541
base_sha: ${{ steps.prepare.outputs.base_sha }}
3642
head_sha: ${{ steps.prepare.outputs.head_sha }}
3743
candidate_tree: ${{ steps.prepare.outputs.candidate_tree }}
@@ -50,6 +56,7 @@ jobs:
5056
GH_TOKEN: ${{ github.token }}
5157
LATEST_TAG_OVERRIDE: ${{ inputs.latest_tag }}
5258
DRY_RUN: ${{ inputs.dry_run || false }}
59+
REBUILD_CURRENT: ${{ inputs.rebuild_current || false }}
5360
run: .github/scripts/upstream-release-sync.sh prepare "$RUNNER_TEMP/release-sync-artifact"
5461
- name: Upload immutable candidate bundle and metadata
5562
id: upload

0 commit comments

Comments
 (0)