Changelog #6
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: Changelog | |
env: | |
CARGO_TERM_COLOR: always | |
RUST_BACKTRACE: 1 | |
RUSTFLAGS: "-D warnings" | |
RUSTDOCFLAGS: '--deny warnings' | |
permissions: | |
id-token: write | |
packages: write | |
contents: write | |
pull-requests: write | |
on: | |
workflow_dispatch: | |
workflow_call: | |
jobs: | |
changelog: | |
name: Create changelog | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-tags: 'true' | |
fetch-depth: 0 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
- uses: Swatinem/rust-cache@v2 | |
- id: release | |
run: echo "version=v$(cargo pkgid --manifest-path crates/bin/Cargo.toml | cut -d '@' -f2)" >> "$GITHUB_OUTPUT" | |
- name: Install git-cliff | |
run: cargo install git-cliff | |
- name: Generate a changelog | |
run: | | |
if [ -f CHANGELOG.md ]; then | |
git-cliff --config github --prepend CHANGELOG.md --latest | |
else | |
git-cliff --config github --output CHANGELOG.md | |
fi | |
env: | |
OUTPUT: CHANGELOG.md | |
GITHUB_REPO: ${{ github.repository }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Commit changelog | |
run: | | |
git checkout -b "changelog/${{ steps.release.outputs.version }}" | |
git config user.name 'github-actions[bot]' | |
git config user.email 'github-actions[bot]@users.noreply.github.com' | |
set +e | |
git add CHANGELOG.md | |
git commit -m "chore: Update changelog" | |
git push origin "changelog/${{ steps.release.outputs.version }}" --force | |
- name: Check out repository | |
uses: actions/checkout@v4 | |
with: | |
ref: "changelog/${{ steps.release.outputs.version }}" | |
- name: Create pull request for changelog | |
run: | | |
alreadyExists=$(gh pr list --json headRefName | jq '.[] | select(.headRefName == "changelog/${{ steps.release.outputs.version }}") | any') | |
if [[ "$alreadyExists" == "" ]]; then | |
branch=$(git branch --show-current) | |
gh pr create --head "$branch" --title "Changelog for ${{ steps.release.outputs.version }}" --body "This PR updates the changelog for version ${{ steps.release.outputs.version }}." | |
fi | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |