Make bon builders optional #77
Workflow file for this run
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
name: Release and publish | |
on: | |
workflow_dispatch: | |
pull_request_target: | |
types: | |
- closed | |
permissions: | |
contents: write | |
pull-requests: write | |
jobs: | |
prepare: | |
if: ${{ github.event_name == 'workflow_dispatch' }} | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
outputs: | |
version: ${{ steps.version-label.outputs.version }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: true | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Actions Auto Build" | |
- 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: Get previous version | |
id: previous-version-label | |
run: | | |
PREVIOUS_VERSION=$(gh api "/repos/${{ github.repository }}/tags?per_page=1" | jq -r '.[] | .name?') | |
echo "previous_version=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT | |
- name: Generate Release Notes | |
id: generate-release-notes | |
run: | | |
generate() { | |
gh api \ | |
--method POST \ | |
-H "Accept: application/vnd.github+json" \ | |
-H "X-GitHub-Api-Version: 2022-11-28" \ | |
/repos/${{ github.repository }}/releases/generate-notes \ | |
-f tag_name='v${{ steps.version-label.outputs.version }}' \ | |
-f previous_tag='v${{ steps.previous-version-label.outputs.previous_version }}' \ | |
| jq -r ".body" | |
} | |
echo "changelog<<EOF"$'\n'"$(generate)"$'\n'EOF >> $GITHUB_OUTPUT | |
- name: Update changelog.txt | |
run: | | |
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 | |
mv changelog.txt.tmp changelog.txt | |
- name: Update README | |
run: | | |
cargo run --example update-readme | |
- name: Commit Changelog and README | |
run: git add -f changelog.txt README.md | |
- name: Create Pull Request | |
id: cpr | |
uses: peter-evans/create-pull-request@v7 | |
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 }} | |
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }} | |
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 }} | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
- name: Configure Git | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "Actions Auto Build" | |
- 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 |