Skip to content

Commit

Permalink
Add GitHub action with support for commit/tag push workflow trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
rgryta committed Aug 29, 2024
1 parent db5ae36 commit 2cdb742
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,39 @@ The full development and release path now is:

<!--tutorial end-->

### 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
Expand Down
50 changes: 50 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2cdb742

Please sign in to comment.