Skip to content

Commit

Permalink
Feat(ci): new changelog workflow (#82)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
hoangdv2429 and github-actions committed May 15, 2024
1 parent 63f000e commit a342c17
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
84 changes: 52 additions & 32 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,80 @@
# style (formatting, missing semi colons, etc.), refactor (code refactoring), test (adding missing tests),
# chore (changes to the build process or auxiliary tools and libraries such as documentation generation)
# e.g: feat(ci): Add auto generate changelog workflow
name: Changelog Update
name: Auto Changelog Update

on:
pull_request:
push:
branches:
- main
types: [closed]

permissions: write-all

jobs:
update_changelog:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: Checkout code
- name: Checkout the repository
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.merge_commit_sha }}
fetch-depth: 1

- name: Set up Node.js
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: "18"

- name: Install conventional-changelog-cli
run: npm install -g conventional-changelog-cli
node-version: '18'

- name: Configure Git
run: |
git config user.name 'github-actions'
git config user.email 'github-actions@github.com'
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
- name: Simulate commit for PR title
- name: Check if "auto-changelog-update-do-not-create-manually" branch exists
id: check_branch
run: |
echo "${{ github.event.pull_request.title }}" > temp_message.txt
git commit --allow-empty -F temp_message.txt
if [ -n "$(git ls-remote --heads origin auto-changelog-update-do-not-create-manually)" ]; then
git fetch origin auto-changelog-update-do-not-create-manually
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Generate changelog
- name: Generate Changelog Update and update if branch exists
run: |
conventional-changelog -p angular -i CHANGELOG.md -s -r 0
npm install -g conventional-changelog-cli
if [ "$branch_exists" == "true" ]; then
git checkout auto-changelog-update-do-not-create-manually
git merge main --strategy-option theirs --allow-unrelated-histories --no-edit
conventional-changelog -p angular -i CHANGELOG.md -s -r 0 --append
git add CHANGELOG.md
git commit -m "Update CHANGELOG.md [skip ci]"
git push origin auto-changelog-update-do-not-create-manually
exit 0
else
git checkout main
git checkout -b auto-changelog-update-do-not-create-manually
git push origin auto-changelog-update-do-not-create-manually
conventional-changelog -p angular -i CHANGELOG.md -s -r 0 --append
fi
- name: Show git status and changelog contents
run: |
git status
echo "Changelog contents:"
cat CHANGELOG.md
- name: Create Pull Request
if: env.branch_exists == 'false'
id: cpr
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Update CHANGELOG.md [skip ci]"
title: "Chore(changelog): Automated Changelog Update [skip ci]"
body: "Update the CHANGELOG.md with recent pushes to branch main."
base: "main"
branch: "auto-changelog-update-do-not-create-manually"
delete-branch: true

- name: Revert temporary commit
run: git reset HEAD~
- name: Check outputs
if: env.branch_exists == 'false'
run: |
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
- name: Commit and push changelog update
- name: Log if PR updated
if: steps.cpr.outputs.pull-request-operation == 'updated'
run: |
git add CHANGELOG.md
git diff --staged --quiet || git commit -m "Update CHANGELOG.md based on PR #${{ github.event.pull_request.number }} title"
git push origin HEAD:refs/heads/main
echo "Changelog PR updated due to new commit to main."
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
* **be:** bumps `block-explorer-rpc-cosmos v1.0.2` & `wasm-block-explorer-rpc-cosmos v1.0.2` ([#42](https://github.com/dymensionxyz/rollapp-wasm/issues/42)) ([eab8283](https://github.com/dymensionxyz/rollapp-wasm/commit/eab82830f8ac5586cdc5d67f134fe52cda48f502))
* **be:** bumps `block-explorer-rpc-cosmos v1.0.3` & `wasm-block-explorer-rpc-cosmos v1.0.3` ([#45](https://github.com/dymensionxyz/rollapp-wasm/issues/45)) ([349bb7c](https://github.com/dymensionxyz/rollapp-wasm/commit/349bb7cf51b954aba087f951bdce02f914d32d6c))
* **be:** bumps `block-explorer-rpc-cosmos v1.1.2` & `wasm-block-explorer-rpc-cosmos v1.1.2` ([#55](https://github.com/dymensionxyz/rollapp-wasm/issues/55)) ([15c563b](https://github.com/dymensionxyz/rollapp-wasm/commit/15c563b10b8e2e5be4d85acfa4362ddd711bf377))
* **be:** bumps `block-explorer-rpc-cosmos v1.2.3` ([#76](https://github.com/dymensionxyz/rollapp-wasm/issues/76))
* **be:** bumps `block-explorer-rpc-cosmos v1.2.3` ([#76](https://github.com/dymensionxyz/rollapp-wasm/issues/76))

0 comments on commit a342c17

Please sign in to comment.