-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update release task to use PR workflow
- Loading branch information
1 parent
683ee6d
commit a31bcc0
Showing
1 changed file
with
43 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }} | ||
|
@@ -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 | ||
|
@@ -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 }} | ||
|
@@ -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 |