Skip to content

Commit

Permalink
ci: another attempt ro fix CI for changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Mcdostone committed Jan 25, 2025
1 parent c9919c3 commit 88e9949
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 43 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- id: release
run: echo "version=$(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/v${{ 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/v${{ steps.release.outputs.version }}" --force
- name: Check out repository
uses: actions/checkout@v4
with:
ref: "changelog/v${{ steps.release.outputs.version }}"
- name: Create pull request for changelog
run: |
alreadyExists=$(gh pr list --json headRefName | jq '.[] | select(.headRefName == "changelog/v${{ 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 }}
44 changes: 2 additions & 42 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,49 +53,9 @@ jobs:

changelog:
needs: [version, create-release]
uses: ./.github/workflows/changelog.yml
name: Create changelog
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v4
- run: git fetch --tags origin
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- 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/v${{ needs.version.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/v${{ needs.version.outputs.version }}" --force
- name: Check out repository
uses: actions/checkout@v4
- name: Create pull request for changelog
run: |
git pull
alreadyExists=$(gh pr list --json headRefName | jq '.[] | select(.headRefName == "changelog/v${{ needs.version.outputs.version }}") | any')
if [[ "$alreadyExists" == "" ]]; then
branch=$(git branch --show-current)
gh pr create --head "$branch" --title "Changelog for ${{ needs.version.outputs.version }}" --body "This PR updates the changelog for version ${{ needs.version.outputs.version }}."
fi
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
secrets: inherit

build-and-publish:
needs: [version, create-release]
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ lol/rust/Cargo.lock
semver-checks/
demo.sh
ee.json
.github/

crates/**/*.cdx.xml
crates/**/*.cdx.json
Expand Down

0 comments on commit 88e9949

Please sign in to comment.