From 083bb24bf1d548a432c7cb8e47220413c4b6cfc7 Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Tue, 11 Nov 2025 18:14:50 +0000 Subject: [PATCH] feat: add more output information BREAKING CHANGE: This update requires commitizen > 4.10 in order to use --minor and --major --- .github/workflows/test_action.yml | 18 ++++++++++++++---- README.md | 22 +++++++++++++++++----- action.yml | 14 +++++++++++++- entrypoint.sh | 17 +++++++++++++++++ 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test_action.yml b/.github/workflows/test_action.yml index b24f794..bacb6e0 100644 --- a/.github/workflows/test_action.yml +++ b/.github/workflows/test_action.yml @@ -8,11 +8,11 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v5 with: ref: "${{ github.event.pull_request.head.ref }}" repository: "${{ github.event.pull_request.head.repo.full_name }}" - fetch-depth: 0 # ensures that tags are fetched, seems to be needed + fetch-depth: 0 # ensures that tags are fetched, seems to be needed - name: Capture commit id id: capture run: | @@ -28,15 +28,25 @@ jobs: git commit -m "feat: test feature" - name: test action uses: ./ + id: cz with: github_token: "${{ secrets.GITHUB_TOKEN }}" commit: false push: false - - uses: actions/checkout@v2 + - name: check outputs + run: | + echo "version: ${{ steps.cz.outputs.version }}" + echo "next_version: ${{ steps.cz.outputs.next_version }}" + echo "next_version_major: ${{ steps.cz.outputs.next_version_major }}" + echo "next_version_minor: ${{ steps.cz.outputs.next_version_minor }}" + echo "previous_version: ${{ steps.cz.outputs.previous_version }}" + echo "previous_version_major: ${{ steps.cz.outputs.previous_version_major }}" + echo "previous_version_minor: ${{ steps.cz.outputs.previous_version_minor }}" + - uses: actions/checkout@v5 with: ref: "${{ github.event.pull_request.head.ref }}" repository: "${{ github.event.pull_request.head.repo.full_name }}" - fetch-depth: 0 # ensures that tags are fetched, seems to be needed + fetch-depth: 0 # ensures that tags are fetched, seems to be needed path: new_head - name: Test push run: | diff --git a/README.md b/README.md index b49d76b..8ccb4c2 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ jobs: name: "Bump version and create changelog with commitizen" steps: - name: Check out - uses: actions/checkout@v3 + uses: actions/checkout@v5 with: fetch-depth: 0 token: "${{ secrets.GITHUB_TOKEN }}" @@ -80,7 +80,7 @@ jobs: | `push` | Define if the changes should be pushed to the branch. | true | | `merge` | Define if the changes should be pushed even on the pull_request event, immediately merging the pull request. | false | | `commit` | Define if the changes should be committed to the branch. | true | -| `commitizen_version` | Specify the version to be used by commitizen. Eg: `2.21. | latest | +| `commitizen_version` | Specify the version to be used by commitizen. Eg: `4.10.0` | latest | | `changelog` | Create changelog when bumping the version | true | | `no_raise` | Don't raise the given comma-delimited exit codes (e.g., no_raise: '20,21'). Use with caution! Open an issue in [commitizen](https://github.com/commitizen-tools/commitizen/issues) if you need help thinking about your workflow. | [21](https://commitizen-tools.github.io/commitizen/exit_codes/) | | `increment` | Manually specify the desired increment {MAJOR,MINOR, PATCH} | - | @@ -90,9 +90,15 @@ jobs: ## Outputs -| Name | Description | -| --------- | --------------- | -| `version` | The new version | +| Name | Description | +| ------------------------ | ----------------------------------------------------------------------- | +| `version` | The next version (same as `next_version`, kept for historical purposes) | +| `next_version` | Next version | +| `next_version_major` | Only the major version of the next version | +| `next_version_minor` | Only the minor version of the next version | +| `previous_version` | Version before the bump | +| `previous_version_major` | Only the major version of the previous version | +| `previous_version_minor` | Only the minor version of the previous version | The new version is also available as an environment variable under `REVISION` or you can access using `${{ steps.cz.outputs.version }}` @@ -176,6 +182,12 @@ To solve it, you must use a personal access token in the checkout and the commit Follow the instructions in [commitizen's documentation][cz-docs-ga]. +Alternatively, you can try using the `gh` cli in your github action: + +```sh +gh workflow run ... +``` + ## I'm not using conventional commits, I'm using my own set of rules on commits If your rules can be parsed, then you can build your own commitizen rules, diff --git a/action.yml b/action.yml index a817f96..f6f715f 100644 --- a/action.yml +++ b/action.yml @@ -7,8 +7,20 @@ branding: icon: "git-commit" color: "purple" outputs: - version: + version: # old classic next_version description: "New version" + next_version: + description: "Next version" + next_version_major: + description: "Only the major version of the next version" + next_version_minor: + description: "Only the minor version of the next version" + previous_version: + description: "Version before the bump" + previous_version_major: + description: "Only the major version of the previous version" + previous_version_minor: + description: "Only the minor version of the previous version" inputs: working_directory: description: "Change to this directory before running" diff --git a/entrypoint.sh b/entrypoint.sh index 40850ff..3121bad 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -40,6 +40,15 @@ fi PREV_REV="$(cz version --project)" echo "PREVIOUS_REVISION=${PREV_REV}" >>"$GITHUB_ENV" +echo "previous_version=${PREV_REV}" >>"$GITHUB_OUTPUT" + +PREV_REV_MAJOR="$(cz version --project --major)" +echo "PREVIOUS_REVISION_MAJOR=${PREV_REV_MAJOR}" >>"$GITHUB_ENV" +echo "previous_version_major=${PREV_REV_MAJOR}" >>"$GITHUB_OUTPUT" +PREV_REV_MINOR="$(cz version --project --minor)" +echo "PREVIOUS_REVISION_MINOR=${PREV_REV_MINOR}" >>"$GITHUB_ENV" +echo "previous_version_minor=${PREV_REV_MINOR}" >>"$GITHUB_OUTPUT" + CZ_CMD=('cz') if [[ $INPUT_DEBUG == 'true' ]]; then @@ -102,6 +111,14 @@ if [[ $REV == "$PREV_REV" ]]; then fi echo "REVISION=${REV}" >>"$GITHUB_ENV" echo "version=${REV}" >>"$GITHUB_OUTPUT" +echo "next_version=${REV}" >>"$GITHUB_OUTPUT" + +NEXT_REV_MAJOR="$(cz version --project --major)" +echo "NEXT_REVISION_MAJOR=${NEXT_REV_MAJOR}" >>"$GITHUB_ENV" +echo "next_version_major=${REV}" >>"$GITHUB_OUTPUT" +NEXT_REV_MINOR="$(cz version --project --minor)" +echo "NEXT_REVISION_MINOR=${NEXT_REV_MINOR}" >>"$GITHUB_ENV" +echo "next_version_minor=${REV}" >>"$GITHUB_OUTPUT" GITHUB_DOMAIN=${GITHUB_SERVER_URL#*//} CURRENT_BRANCH="$(git branch --show-current)"