| 1 |
name: Bump version |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- master |
| 7 |
|
| 8 |
jobs: |
| 9 |
bump-version: |
| 10 |
if: ${{ github.repository == 'commitizen-tools/commitizen' && !startsWith(github.event.head_commit.message, 'bump:') }} |
| 11 |
runs-on: ubuntu-latest |
| 12 |
name: "Bump version and create changelog with commitizen" |
| 13 |
permissions: |
| 14 |
contents: write |
| 15 |
actions: write |
| 16 |
steps: |
| 17 |
- uses: actions/create-github-app-token@v3 |
| 18 |
id: app-token |
| 19 |
with: |
| 20 |
app-id: ${{ vars.APP_ID }} |
| 21 |
private-key: ${{ secrets.PRIVATE_KEY }} |
| 22 |
- name: Check out |
| 23 |
uses: actions/checkout@v7 |
| 24 |
with: |
| 25 |
token: ${{ steps.app-token.outputs.token }} |
| 26 |
fetch-depth: 0 |
| 27 |
fetch-tags: true |
| 28 |
- name: Get GitHub App User ID |
| 29 |
id: get-user-id |
| 30 |
run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" |
| 31 |
env: |
| 32 |
GH_TOKEN: ${{ steps.app-token.outputs.token }} |
| 33 |
- uses: commitizen-tools/setup-cz@main |
| 34 |
with: |
| 35 |
# Information extracted from the app token |
| 36 |
# Under actions/create-github-app-token is documented how to generate username and email for the bot |
| 37 |
git-user-name: "${{ steps.app-token.outputs.app-slug }}[bot]" |
| 38 |
git-user-email: "${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" |
| 39 |
- id: bump-version |
| 40 |
run: | |
| 41 |
old_sha="$(git rev-parse HEAD)" |
| 42 |
cz --no-raise 21 bump --yes |
| 43 |
|
| 44 |
if [ "$(git rev-parse HEAD)" = "$old_sha" ]; then |
| 45 |
echo "No bump-eligible commits found, skipping release." |
| 46 |
echo "bumped=false" >> $GITHUB_OUTPUT |
| 47 |
exit 0 |
| 48 |
fi |
| 49 |
|
| 50 |
echo "bumped=true" >> $GITHUB_OUTPUT |
| 51 |
git push --follow-tags |
| 52 |
new_version="$(cz version -p)" |
| 53 |
echo "new_version=$new_version" >> $GITHUB_OUTPUT |
| 54 |
new_version_tag="$(cz version -p --tag)" |
| 55 |
echo "new_version_tag=$new_version_tag" >> $GITHUB_OUTPUT |
| 56 |
- name: Build changelog for Release |
| 57 |
if: steps.bump-version.outputs.bumped == 'true' |
| 58 |
env: |
| 59 |
NEW_VERSION: ${{ steps.bump-version.outputs.new_version }} |
| 60 |
run: | |
| 61 |
cz changelog --dry-run "${NEW_VERSION}" > .changelog.md |
| 62 |
- name: Release |
| 63 |
if: steps.bump-version.outputs.bumped == 'true' |
| 64 |
env: |
| 65 |
GH_TOKEN: ${{ github.token }} |
| 66 |
NEW_VERSION_TAG: ${{ steps.bump-version.outputs.new_version_tag }} |
| 67 |
run: | |
| 68 |
gh release create "${NEW_VERSION_TAG}" --notes-file .changelog.md |