Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GitHub action with support for commit/tag push workflow trigger #232

Merged
merged 4 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,41 @@ 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
env:
BUMPVERSION_TAG: "true"
with:
args: "major"
coordt marked this conversation as resolved.
Show resolved Hide resolved
```

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.
coordt marked this conversation as resolved.
Show resolved Hide resolved

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).
coordt marked this conversation as resolved.
Show resolved Hide resolved

## Development & Contributing

Thank you, contributors! You can find a full list here: https://github.com/callowayproject/bump-my-version/graphs/contributors
Expand Down
58 changes: 58 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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/[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: |
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

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
Loading