diff --git a/.cz.toml b/.cz.toml index d7b6f03..fe795f2 100644 --- a/.cz.toml +++ b/.cz.toml @@ -1,6 +1,6 @@ [tool.commitizen] name = "cz_conventional_commits" -version = "0.21.0" +version = "0.26.0" format = "v$version" update_changelog_on_bump = true major_version_zero = true diff --git a/.github/workflows/bumpversion.yaml b/.github/workflows/bumpversion.yaml index 76e8e65..bb486f6 100644 --- a/.github/workflows/bumpversion.yaml +++ b/.github/workflows/bumpversion.yaml @@ -17,7 +17,7 @@ jobs: - name: Create bump and changelog uses: commitizen-tools/commitizen-action@master with: - github_token: "${{ secrets.GITHUB_TOKEN }}" + github_token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" changelog_increment_filename: body.md - name: Release uses: softprops/action-gh-release@v1 @@ -25,4 +25,4 @@ jobs: body_path: "body.md" tag_name: "${{ env.REVISION }}" env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + GITHUB_TOKEN: "${{ secrets.PERSONAL_ACCESS_TOKEN }}" 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/.github/workflows/update_semver.yml b/.github/workflows/update_semver.yml new file mode 100644 index 0000000..dc41a80 --- /dev/null +++ b/.github/workflows/update_semver.yml @@ -0,0 +1,19 @@ +name: Update Major Minor Tags + +on: + push: + branches-ignore: + - "**" + tags: + - "*.*.*" + workflow_dispatch: + +jobs: + update_major_minor_tags: + name: Make sure major and minor tags are up to date on a patch release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Run Update semver + uses: haya14busa/action-update-semver@v1 diff --git a/CHANGELOG.md b/CHANGELOG.md index ba63e75..ba5e9e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,39 @@ +## 0.26.0 (2025-11-19) + +### Feat + +- add gpg-agent + +## 0.25.0 (2025-11-16) + +### BREAKING CHANGE + +- This update requires commitizen > 4.10 in order to use --minor and --major + +### Feat + +- add more output information + +## 0.24.0 (2025-02-25) + +### Feat + +- add support for manual version bumping + +## 0.23.1 (2024-12-21) + +## 0.23.0 (2024-12-09) + +### Feat + +- **#55**: add ACTOR input parameter + +## 0.22.0 (2024-11-06) + +### Feat + +- add working-directory input + ## 0.21.0 (2024-03-05) ### Feat diff --git a/Dockerfile b/Dockerfile index f9daacf..695f34d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ RUN set -eux; \ git \ git-lfs \ gpg \ + gpg-agent \ alpine-sdk \ bash \ libffi-dev \ diff --git a/README.md b/README.md index dc780c6..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 }}" @@ -67,6 +67,7 @@ jobs: | Name | Description | Default | | ------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | | `github_token` | Token for the repo. Can be passed in using `${{ secrets.GITHUB_TOKEN }}`. Required if `push: true` | - | +| `working_directory` | Change to this directory before running | repo root directory | | `dry_run` | Run without creating commit, output to stdout | false | | `repository` | Repository name to push. Default or empty value represents current github repository | current one | | `branch` | Destination branch to push changes | Same as the one executing the action by default | @@ -79,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} | - | @@ -89,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 }}` @@ -175,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 5eed095..f6f715f 100644 --- a/action.yml +++ b/action.yml @@ -1,24 +1,39 @@ -name: 'Bump and changelog using commitizen' -description: 'Create a commit bumping the version of your project and creating a changelog file' +name: "Bump and changelog using commitizen" +description: "Create a commit bumping the version of your project and creating a changelog file" runs: - using: 'docker' - image: 'Dockerfile' + using: "docker" + image: "Dockerfile" branding: - icon: 'git-commit' - color: 'purple' + icon: "git-commit" + color: "purple" outputs: - version: - description: 'New 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" + required: false dry_run: - description: 'Run without creating commit, output to stdout' + description: "Run without creating commit, output to stdout" required: false commit: - description: 'If true a commit is created containing the bump changes' + description: "If true a commit is created containing the bump changes" required: false default: "true" push: - description: 'If true the bump commit is pushed to the remote repository' + description: "If true the bump commit is pushed to the remote repository" required: false default: "true" merge: @@ -28,62 +43,62 @@ inputs: required: false default: "false" prerelease: - description: 'Set as prerelease version' + description: "Set as prerelease version" required: false devrelease: - description: 'Non-negative integer for dev. release' + description: "Non-negative integer for dev. release" required: false local_version: - description: 'Bump only the local version portion' + description: "Bump only the local version portion" required: false default: "false" changelog: - description: 'Create changelog when bumping the version' + description: "Create changelog when bumping the version" default: "true" required: false github_token: description: 'Token for the repo. Can be passed in using $\{{ secrets.GITHUB_TOKEN }}' required: false repository: - description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})' - default: '' + description: "Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})" + default: "" required: false branch: - description: 'Destination branch to push changes' + description: "Destination branch to push changes" required: false - default: '' + default: "" extra_requirements: - description: 'Extra commitizen dependencies like your custom plugins or rules' + description: "Extra commitizen dependencies like your custom plugins or rules" required: false - default: '' + default: "" changelog_increment_filename: - description: 'Filename to store the incremented generated changelog. This is different to changelog as it only contains the changes for the just generated version' + description: "Filename to store the incremented generated changelog. This is different to changelog as it only contains the changes for the just generated version" required: false git_redirect_stderr: - description: 'Redirect git output to stderr. Useful if you do not want git output in your changelog' + description: "Redirect git output to stderr. Useful if you do not want git output in your changelog" required: false default: "false" git_name: - description: 'Name used to configure git (for git operations)' + description: "Name used to configure git (for git operations)" required: false - default: 'github-actions[bot]' + default: "github-actions[bot]" git_email: - description: 'Email address used to configure git (for git operations)' + description: "Email address used to configure git (for git operations)" required: false - default: 'github-actions[bot]@users.noreply.github.com' + default: "github-actions[bot]@users.noreply.github.com" commitizen_version: - description: 'Specify the version to be used by commitizen' + description: "Specify the version to be used by commitizen" required: false default: latest no_raise: description: "Don't raise the given comma-delimited exit codes" required: false - default: '21' + default: "21" increment: description: "Manually specify the desired increment" required: false check_consistency: - default: 'false' + default: "false" description: "check consistency among versions defined in commitizen configuration and version_files" required: false gpg_sign: @@ -97,3 +112,9 @@ inputs: description: "If true, prints debug output to GitHub Actions stdout." required: false default: "false" + actor: + description: "The account that will be used to perform git operations, defaults to the GITHUB_ACTOR" + required: false + manual_version: + description: "Manually specify the version to bump to" + required: false diff --git a/entrypoint.sh b/entrypoint.sh index a8a2987..3121bad 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -34,8 +34,21 @@ echo "${PIP_CMD[@]}" "${PIP_CMD[@]}" echo "Commitizen version: $(cz version)" +if [[ $INPUT_WORKING_DIRECTORY ]]; then + cd $INPUT_WORKING_DIRECTORY +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 @@ -61,7 +74,7 @@ if [[ $INPUT_DEVRELEASE ]]; then CZ_CMD+=('--devrelease' "$INPUT_DEVRELEASE") fi if [[ $INPUT_LOCAL_VERSION == 'true' ]]; then - CZ_CMD+=('--local_version') + CZ_CMD+=('--local-version') fi if [[ $INPUT_COMMIT == 'false' ]]; then CZ_CMD+=('--files-only') @@ -69,12 +82,15 @@ fi if [[ $INPUT_INCREMENT ]]; then CZ_CMD+=('--increment' "$INPUT_INCREMENT") fi -if [[ $INPUT_CHECK_CONSISTENCY ]]; then +if [[ $INPUT_CHECK_CONSISTENCY == 'true' ]]; then CZ_CMD+=('--check-consistency') fi if [[ $INPUT_GIT_REDIRECT_STDERR == 'true' ]]; then CZ_CMD+=('--git-output-to-stderr') fi +if [[ $INPUT_MANUAL_VERSION ]]; then + CZ_CMD+=("$INPUT_MANUAL_VERSION") +fi if [[ $INPUT_CHANGELOG_INCREMENT_FILENAME ]]; then CZ_CMD+=('--changelog-to-stdout') echo "${CZ_CMD[@]}" ">$INPUT_CHANGELOG_INCREMENT_FILENAME" @@ -83,6 +99,11 @@ else echo "${CZ_CMD[@]}" "${CZ_CMD[@]}" fi +if [[ $INPUT_ACTOR ]]; then + ACTOR=$INPUT_ACTOR +else + ACTOR=$GITHUB_ACTOR +fi REV="$(cz version --project)" if [[ $REV == "$PREV_REV" ]]; then @@ -90,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)" @@ -97,7 +126,7 @@ INPUT_BRANCH="${INPUT_BRANCH:-$CURRENT_BRANCH}" INPUT_REPOSITORY="${INPUT_REPOSITORY:-$GITHUB_REPOSITORY}" echo "Repository: ${INPUT_REPOSITORY}" -echo "Actor: ${GITHUB_ACTOR}" +echo "Actor: ${ACTOR}" if [[ $INPUT_PUSH == 'true' ]]; then if [[ $INPUT_MERGE != 'true' && $GITHUB_EVENT_NAME == 'pull_request' ]]; then @@ -105,7 +134,7 @@ if [[ $INPUT_PUSH == 'true' ]]; then echo "You probably want to run on push to your default branch instead." >&2 else echo "Pushing to branch..." - REMOTE_REPO="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${GITHUB_DOMAIN}/${INPUT_REPOSITORY}.git" + REMOTE_REPO="https://${ACTOR}:${INPUT_GITHUB_TOKEN}@${GITHUB_DOMAIN}/${INPUT_REPOSITORY}.git" git pull "$REMOTE_REPO" "$INPUT_BRANCH" git push "$REMOTE_REPO" "HEAD:${INPUT_BRANCH}" --tags fi