Skip to content

Commit e904314

Browse files
authored
feat: add SHA-suffixed PR release tags (#8702)
This PR enhances the PR release workflow to create both short format and SHA-suffixed release tags. Creates both pr-release-{PR_NUMBER} and pr-release-{PR_NUMBER}-{SHORT_SHA} tags, generates separate releases for both formats, adds separate GitHub status checks, and updates Batteries/Mathlib testing branches to use SHA-suffixed tags for exact commit traceability. This removes the need for downstream repositories to deal with the toolchain changing without the toolchain name changing.
1 parent 0ebd320 commit e904314

File tree

1 file changed

+53
-9
lines changed

1 file changed

+53
-9
lines changed

.github/workflows/pr-release.yml

Lines changed: 53 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,28 @@ jobs:
4848
git -C lean4.git remote add origin https://github.com/${{ github.repository_owner }}/lean4.git
4949
git -C lean4.git fetch -n origin master
5050
git -C lean4.git fetch -n origin "${{ steps.workflow-info.outputs.sourceHeadSha }}"
51+
52+
# Create both the original tag and the SHA-suffixed tag
53+
SHORT_SHA="${{ steps.workflow-info.outputs.sourceHeadSha }}"
54+
SHORT_SHA="${SHORT_SHA:0:7}"
55+
56+
# Export the short SHA for use in subsequent steps
57+
echo "SHORT_SHA=${SHORT_SHA}" >> "$GITHUB_ENV"
58+
5159
git -C lean4.git tag -f pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }} "${{ steps.workflow-info.outputs.sourceHeadSha }}"
60+
git -C lean4.git tag -f pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-"${SHORT_SHA}" "${{ steps.workflow-info.outputs.sourceHeadSha }}"
61+
5262
git -C lean4.git remote add pr-releases https://foo:'${{ secrets.PR_RELEASES_TOKEN }}'@github.com/${{ github.repository_owner }}/lean4-pr-releases.git
5363
git -C lean4.git push -f pr-releases pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}
64+
git -C lean4.git push -f pr-releases pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-"${SHORT_SHA}"
5465
- name: Delete existing release if present
5566
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
5667
run: |
57-
# Try to delete any existing release for the current PR.
68+
# Try to delete any existing release for the current PR (just the version without the SHA suffix).
5869
gh release delete --repo ${{ github.repository_owner }}/lean4-pr-releases pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }} -y || true
5970
env:
6071
GH_TOKEN: ${{ secrets.PR_RELEASES_TOKEN }}
61-
- name: Release
72+
- name: Release (short format)
6273
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
6374
uses: softprops/action-gh-release@v2
6475
with:
@@ -73,7 +84,22 @@ jobs:
7384
# The token used here must have `workflow` privileges.
7485
GITHUB_TOKEN: ${{ secrets.PR_RELEASES_TOKEN }}
7586

76-
- name: Report release status
87+
- name: Release (SHA-suffixed format)
88+
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
89+
uses: softprops/action-gh-release@v2
90+
with:
91+
name: Release for PR ${{ steps.workflow-info.outputs.pullRequestNumber }} (${{ steps.workflow-info.outputs.sourceHeadSha }})
92+
# There are coredumps files here as well, but all in deeper subdirectories.
93+
files: artifacts/*/*
94+
fail_on_unmatched_files: true
95+
draft: false
96+
tag_name: pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}
97+
repository: ${{ github.repository_owner }}/lean4-pr-releases
98+
env:
99+
# The token used here must have `workflow` privileges.
100+
GITHUB_TOKEN: ${{ secrets.PR_RELEASES_TOKEN }}
101+
102+
- name: Report release status (short format)
77103
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
78104
uses: actions/github-script@v7
79105
with:
@@ -87,6 +113,20 @@ jobs:
87113
description: "${{ github.repository_owner }}/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}",
88114
});
89115
116+
- name: Report release status (SHA-suffixed format)
117+
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
118+
uses: actions/github-script@v7
119+
with:
120+
script: |
121+
await github.rest.repos.createCommitStatus({
122+
owner: context.repo.owner,
123+
repo: context.repo.repo,
124+
sha: "${{ steps.workflow-info.outputs.sourceHeadSha }}",
125+
state: "success",
126+
context: "PR toolchain (SHA-suffixed)",
127+
description: "${{ github.repository_owner }}/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}",
128+
});
129+
90130
- name: Add label
91131
if: ${{ steps.workflow-info.outputs.pullRequestNumber != '' }}
92132
uses: actions/github-script@v7
@@ -282,16 +322,18 @@ jobs:
282322
if [ "$EXISTS" = "0" ]; then
283323
echo "Branch does not exist, creating it."
284324
git switch -c lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }} "$BASE"
285-
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}" > lean-toolchain
325+
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}" > lean-toolchain
286326
git add lean-toolchain
287327
git commit -m "Update lean-toolchain for testing https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
288328
else
289-
echo "Branch already exists, pushing an empty commit."
329+
echo "Branch already exists, updating lean-toolchain."
290330
git switch lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }}
291331
# The Batteries `nightly-testing` or `nightly-testing-YYYY-MM-DD` branch may have moved since this branch was created, so merge their changes.
292332
# (This should no longer be possible once `nightly-testing-YYYY-MM-DD` is a tag, but it is still safe to merge.)
293333
git merge "$BASE" --strategy-option ours --no-commit --allow-unrelated-histories
294-
git commit --allow-empty -m "Trigger CI for https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
334+
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}" > lean-toolchain
335+
git add lean-toolchain
336+
git commit -m "Update lean-toolchain for https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
295337
fi
296338
297339
- name: Push changes
@@ -346,21 +388,23 @@ jobs:
346388
if [ "$EXISTS" = "0" ]; then
347389
echo "Branch does not exist, creating it."
348390
git switch -c lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }} "$BASE"
349-
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}" > lean-toolchain
391+
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}" > lean-toolchain
350392
git add lean-toolchain
351393
sed -i 's,require "leanprover-community" / "batteries" @ git ".\+",require "leanprover-community" / "batteries" @ git "lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }}",' lakefile.lean
352394
lake update batteries
353395
git add lakefile.lean lake-manifest.json
354396
git commit -m "Update lean-toolchain for testing https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
355397
else
356-
echo "Branch already exists, merging $BASE and bumping Batteries."
398+
echo "Branch already exists, updating lean-toolchain and bumping Batteries."
357399
git switch lean-pr-testing-${{ steps.workflow-info.outputs.pullRequestNumber }}
358400
# The Mathlib `nightly-testing` branch or `nightly-testing-YYYY-MM-DD` tag may have moved since this branch was created, so merge their changes.
359401
# (This should no longer be possible once `nightly-testing-YYYY-MM-DD` is a tag, but it is still safe to merge.)
360402
git merge "$BASE" --strategy-option ours --no-commit --allow-unrelated-histories
403+
echo "leanprover/lean4-pr-releases:pr-release-${{ steps.workflow-info.outputs.pullRequestNumber }}-${{ env.SHORT_SHA }}" > lean-toolchain
404+
git add lean-toolchain
361405
lake update batteries
362406
git add lake-manifest.json
363-
git commit --allow-empty -m "Trigger CI for https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
407+
git commit -m "Update lean-toolchain for https://github.com/leanprover/lean4/pull/${{ steps.workflow-info.outputs.pullRequestNumber }}"
364408
fi
365409
366410
- name: Push changes

0 commit comments

Comments
 (0)