|
| 1 | +name: Changelog |
| 2 | + |
| 3 | +env: |
| 4 | + CARGO_TERM_COLOR: always |
| 5 | + RUST_BACKTRACE: 1 |
| 6 | + RUSTFLAGS: "-D warnings" |
| 7 | + RUSTDOCFLAGS: '--deny warnings' |
| 8 | + |
| 9 | +permissions: |
| 10 | + id-token: write |
| 11 | + packages: write |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +on: |
| 16 | + workflow_dispatch: |
| 17 | + workflow_call: |
| 18 | + |
| 19 | +jobs: |
| 20 | + changelog: |
| 21 | + name: Create changelog |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - name: Check out repository |
| 25 | + uses: actions/checkout@v4 |
| 26 | + - name: Install Rust |
| 27 | + uses: dtolnay/rust-toolchain@stable |
| 28 | + - uses: Swatinem/rust-cache@v2 |
| 29 | + - id: release |
| 30 | + run: echo "version=$(cargo pkgid --manifest-path crates/bin/Cargo.toml | cut -d '@' -f2)" >> "$GITHUB_OUTPUT" |
| 31 | + - name: Install git-cliff |
| 32 | + run: cargo install git-cliff |
| 33 | + - name: Generate a changelog |
| 34 | + run: | |
| 35 | + if [ -f CHANGELOG.md ]; then |
| 36 | + git-cliff --config github --prepend CHANGELOG.md --latest |
| 37 | + else |
| 38 | + git-cliff --config github --output CHANGELOG.md |
| 39 | + fi |
| 40 | + env: |
| 41 | + OUTPUT: CHANGELOG.md |
| 42 | + GITHUB_REPO: ${{ github.repository }} |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + - name: Commit changelog |
| 45 | + run: | |
| 46 | + git checkout -b "changelog/v${{ steps.release.outputs.version }}" |
| 47 | + git config user.name 'github-actions[bot]' |
| 48 | + git config user.email 'github-actions[bot]@users.noreply.github.com' |
| 49 | + set +e |
| 50 | + git add CHANGELOG.md |
| 51 | + git commit -m "chore: Update changelog" |
| 52 | + git push origin "changelog/v${{ steps.release.outputs.version }}" --force |
| 53 | + - name: Check out repository |
| 54 | + uses: actions/checkout@v4 |
| 55 | + with: |
| 56 | + ref: "changelog/v${{ steps.release.outputs.version }}" |
| 57 | + - name: Create pull request for changelog |
| 58 | + run: | |
| 59 | + alreadyExists=$(gh pr list --json headRefName | jq '.[] | select(.headRefName == "changelog/v${{ steps.release.outputs.version }}") | any') |
| 60 | + if [[ "$alreadyExists" == "" ]]; then |
| 61 | + branch=$(git branch --show-current) |
| 62 | + gh pr create --head "$branch" --title "Changelog for ${{ steps.release.outputs.version }}" --body "This PR updates the changelog for version ${{ steps.release.outputs.version }}." |
| 63 | + fi |
| 64 | + env: |
| 65 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments