From 2cdb7420264810396b42d35827291d1dc080d416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Gryta?= Date: Thu, 29 Aug 2024 14:22:55 +0200 Subject: [PATCH] Add GitHub action with support for commit/tag push workflow trigger --- README.md | 33 +++++++++++++++++++++++++++++++++ action.yml | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ pyproject.toml | 4 ++++ 3 files changed, 87 insertions(+) create mode 100644 action.yml diff --git a/README.md b/README.md index 4c7c359..ab790d8 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,39 @@ The full development and release path now is: +### GitHub Actions + +You can use `bump-my-version` as part of a GHA workflow. Here is an example of a workflow that bumps the version, commits the change, and tags the commit. + +```yaml title="GitHub Actions Workflow" +name: Bump version + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Bump version + uses: callowayproject/bump-my-version@master + with: + args: "major" +``` + +Inputs for the bump-my-version action are: +1. `args` - The arguments to pass to the `bump-my-version bump [args]` command. See the CLI documentation for more information. +2. `github-token` - The GitHub token to use for committing and tagging. This is optional. + +Output: +1. `bump` - Boolean flag for whether the version was bumped. +2. `version` - [TODO] The new version number. + +If you want to ensure that workflows set up with on-push trigger will also start based on those newly pushed commits or tags, you need to provide a custom PAT (`github-token`). See [here](https://github.com/orgs/community/discussions/25702). + ## Development & Contributing Thank you, contributors! You can find a full list here: https://github.com/callowayproject/bump-my-version/graphs/contributors diff --git a/action.yml b/action.yml new file mode 100644 index 0000000..af60ca1 --- /dev/null +++ b/action.yml @@ -0,0 +1,50 @@ +name: Bump My Version +description: Bump version of a project +inputs: + args: + description: 'May contain any of the following: VERSION_PART (e.g. minor), FILES (additional file(s) to modify).' + required: false + default: '' + github-token: + description: 'GitHub Token to use instead of the default one.' + required: false + default: ${{ github.token }} +outputs: + bumped: + description: 'Whether there was a bump or not [true|false]' + value: ${{ steps.bump.outputs.bumped }} +runs: + using: 'composite' + steps: + - name: Checkout the code + uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Setting up git config + shell: bash + env: + GH_TOKEN: ${{ inputs.github-token }} + run: | + git config --global user.email "${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" + git config --global user.name "$(gh api /users/${GITHUB_ACTOR} | jq .name -r)" + git config -l + - name: Install Python + uses: actions/setup-python@v5.1.1 + with: + python-version: '3.12' + - name: Install bump-my-version + shell: bash + run: pip install "bump-my-version==0.26.0" + - name: Pass Inputs to Shell + id: bump + shell: bash + run: | + bump-my-version bump ${{ inputs.args }} + exitcode="$?" + ([[ ${exitcode} -gt 0 ]] && echo "bumped=false" || echo "bumped=true") >> $GITHUB_OUTPUT + - name: Push changes to GitHub + uses: ad-m/github-push-action@master + with: + github_token: ${{ inputs.github-token }} + force: true + diff --git a/pyproject.toml b/pyproject.toml index c3a204a..bd0106d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -244,6 +244,10 @@ filename = "CHANGELOG.md" search = "{current_version}...HEAD" replace = "{current_version}...{new_version}" +[[tool.bumpversion.files]] +filename = "action.yml" +search = "bump-my-version=={current_version}" +replace = "bump-my-version=={new_version}" [tool.pydoclint] style = "google"