Skip to content

Commit

Permalink
Update release task to use PR workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed May 7, 2024
1 parent 683ee6d commit a31bcc0
Showing 1 changed file with 43 additions and 21 deletions.
64 changes: 43 additions & 21 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ name: Release and publish

on:
workflow_dispatch:
pull_request_target:
types:
- closed

permissions:
contents: write
pull-requests: write

jobs:
release:
prepare:
runs-on: ubuntu-latest
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -55,7 +58,7 @@ jobs:
- name: Update changelog.txt
run: |
echo "## [v${{ steps.version-label.outputs.version }}] - `date +%d-%m-%Y`" >> changelog.txt.tmp
echo "# [v${{ steps.version-label.outputs.version }}] - `date +%d-%m-%Y`" >> changelog.txt.tmp
echo "${{steps.generate-release-notes.outputs.changelog}}" >> changelog.txt.tmp
echo '-n' >> changelog.txt
cat changelog.txt >> changelog.txt.tmp
Expand All @@ -66,29 +69,33 @@ jobs:
cargo run --example update-readme
- name: Commit Changelog and README
run: |
git config --local user.email "[email protected]"
git config --local user.name "Actions Auto Build"
git add -f changelog.txt README.md
git commit -m "[auto-docs][skip test]: update changelog" || true
run: git add -f changelog.txt README.md

- name: Push to protected branch
uses: CasperWA/push-protected@v2
- name: Create Pull Request
id: cpr
uses: peter-evans/create-pull-request@v6
with:
commit-message: "[skip test] update changelog"
title: "[skip test] Release v${{ steps.version-label.outputs.version }}"
body: >
This is an automated PR to build the latest changelog. Upon merging,
a new release will be created and published to crates.io.<br/>
Due to security considerations, PRs created by GitHub Actions cannot
be merged automatically. Please review the changes and merge the PR.<br/>
If you require the test suites to run, you can close the PR and reopen it to trigger
those workflows.
delete-branch: true
labels: release
branch: "release/v${{ steps.version-label.outputs.version }}"

- name: Enable Pull Request Automerge
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
branch: main
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}

- name: Create tag
run: |
git tag -a v${{ steps.version-label.outputs.version }} -m "Release v${{ steps.version-label.outputs.version }}"
git push origin --tags
- name: Publish GitHub release
run: |
gh release create v${{ steps.version-label.outputs.version }} --generate-notes
publish:
needs: release
release:
if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'release')) }}
runs-on: ubuntu-latest
env:
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
Expand All @@ -98,8 +105,23 @@ jobs:
with:
submodules: recursive

- name: Get current version
id: version-label
run: |
VERSION=$(grep version Cargo.toml | head -n 1 | cut -d'"' -f2)
echo "version=${VERSION}" >> $GITHUB_OUTPUT
- name: Create tag
run: |
git tag -a v${{ steps.version-label.outputs.version }} -m "Release v${{ steps.version-label.outputs.version }}"
git push origin --tags
- name: Login to Crates.io
run: cargo login ${CRATES_IO_TOKEN}

- name: Publish GitHub release
run: |
gh release create v${{ steps.version-label.outputs.version }} --generate-notes
- name: Publish crate
run: cargo publish

0 comments on commit a31bcc0

Please sign in to comment.