diff --git a/README.md b/README.md index 4c7c359c..2a88eb0f 100644 --- a/README.md +++ b/README.md @@ -231,6 +231,58 @@ 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: + bump-type: + description: 'Bump type' + required: true + default: 'patch' + type: choice + options: + - major + - minor + - patch + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Bump version + id: bump + uses: callowayproject/bump-my-version@master + env: + BUMPVERSION_TAG: "true" + with: + args: ${{ inputs.bump-type }} + github-token: ${{ secrets.GH_TOKEN }} + + - name: Check + if: steps.bump.outputs.bumped == 'true' + run: | + echo "Version was bumped from ${{ steps.bump.outputs.previous-version }} to ${{ steps.bump.outputs.current-version }}!" +``` + +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. `bumped` - Boolean flag for whether the version was bumped. +2. `previous-version` - Version before bump was performed. +3. `current-version` - Version after performing bump. + +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 00000000..71976e83 --- /dev/null +++ b/action.yml @@ -0,0 +1,58 @@ +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 }} + previous-version: + description: 'Previous version' + value: ${{ steps.bump.outputs.previous-version }} + current-version: + description: 'Updated version' + value: ${{ steps.bump.outputs.current-version }} +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: | + echo "previous-version=$(bump-my-version show current_version)" >> $GITHUB_OUTPUT + + bump-my-version bump ${{ inputs.args }} + ([[ $? -gt 0 ]] && echo "bumped=false" || echo "bumped=true") >> $GITHUB_OUTPUT + echo "current-version=$(bump-my-version show current_version)" >> $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 c3a204ae..bd0106d9 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"