Skip to content

Commit 07e9c52

Browse files
Merge pull request #31 from lukewilliamboswell/fix-release-workflow-protected-main
Respect branch protection in release workflow
2 parents dfabb89 + 9fadb37 commit 07e9c52

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ jobs:
118118
release_tag: ${{ steps.prepare_release.outputs.release_tag }}
119119
permissions:
120120
contents: write
121+
pull-requests: write
121122
defaults:
122123
run:
123124
shell: bash
@@ -146,12 +147,14 @@ jobs:
146147
BUNDLE_FILENAME: ${{ needs.build-bundle.outputs.bundle_filename }}
147148
RAW_RELEASE_VERSION: ${{ github.event.inputs.release_version }}
148149
REF_TYPE: ${{ github.ref_type }}
150+
GH_TOKEN: ${{ github.token }}
149151
run: |
150152
if [ "$REF_TYPE" != "branch" ]; then
151-
echo "Release workflow must be run from a branch so it can commit updated example URLs."
153+
echo "Release workflow must be run from a branch."
152154
exit 1
153155
fi
154156
157+
SOURCE_COMMIT=$(git rev-parse HEAD)
155158
RELEASE_VERSION="${RAW_RELEASE_VERSION#v}"
156159
if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
157160
echo "Release version must use x.y.z format, e.g. 0.11.0"
@@ -180,13 +183,39 @@ jobs:
180183
if git diff --cached --quiet; then
181184
echo "Release docs and example URLs are already current."
182185
else
186+
RELEASE_ARTIFACTS_BRANCH="release-artifacts/${RELEASE_VERSION}"
183187
git commit -m "Prepare ${RELEASE_VERSION} release artifacts"
184-
git push origin HEAD:${{ github.ref_name }}
188+
git push --force-with-lease origin HEAD:"$RELEASE_ARTIFACTS_BRANCH"
189+
190+
PR_NUMBER=$(gh pr list \
191+
--base "${{ github.ref_name }}" \
192+
--head "$RELEASE_ARTIFACTS_BRANCH" \
193+
--state open \
194+
--json number \
195+
--jq '.[0].number // empty')
196+
197+
if [ -z "$PR_NUMBER" ]; then
198+
gh pr create \
199+
--base "${{ github.ref_name }}" \
200+
--head "$RELEASE_ARTIFACTS_BRANCH" \
201+
--title "Prepare ${RELEASE_VERSION} release artifacts" \
202+
--body "Generated docs and updated example package URLs for release ${RELEASE_VERSION}."
203+
else
204+
gh pr comment "$PR_NUMBER" \
205+
--body "Updated generated docs and example package URLs for release ${RELEASE_VERSION}."
206+
fi
185207
fi
186208
187-
echo "release_commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
209+
echo "release_commit=$SOURCE_COMMIT" >> "$GITHUB_OUTPUT"
188210
echo "release_tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT"
189211
212+
- name: Upload generated docs artifact
213+
uses: actions/upload-artifact@v4
214+
with:
215+
name: release-docs
216+
path: www
217+
retention-days: 30
218+
190219
- name: Create release
191220
env:
192221
GH_TOKEN: ${{ github.token }}
@@ -217,10 +246,11 @@ jobs:
217246
url: ${{ steps.deployment.outputs.page_url }}
218247

219248
steps:
220-
- name: Checkout release commit
221-
uses: actions/checkout@v4
249+
- name: Download generated docs artifact
250+
uses: actions/download-artifact@v4
222251
with:
223-
ref: ${{ needs.create-release.outputs.release_commit }}
252+
name: release-docs
253+
path: ./www
224254

225255
- name: Setup Pages
226256
uses: actions/configure-pages@v5

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ CI skips `examples/markdown.roc` because the latest Roc nightly overflows the co
4545

4646
Bundle the package for distribution using `scripts/bundle.sh --output-dir dist`.
4747

48-
Run the release workflow from GitHub Actions with a release version such as `0.11.0`. It builds and tests the bundle, updates example package URLs, regenerates versioned docs, updates the docs redirect, creates the GitHub release, and deploys the docs to GitHub Pages.
48+
Run the release workflow from GitHub Actions with a release version such as `0.11.0`. It builds and tests the bundle, creates the GitHub release, deploys generated docs to GitHub Pages, and opens a release-artifacts PR with updated example package URLs plus the generated `www/` docs.

0 commit comments

Comments
 (0)