Bump version number #42
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bump Version (release) | |
on: | |
push: | |
branches: | |
- release | |
jobs: | |
build: | |
name: Bump version | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token | |
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.10' | |
- name: Set env variables | |
run: | | |
echo "${{ github.event.head_commit.message }}" | |
- name: Install dependencies | |
run: | | |
pip install -e .[build] | |
- name: Bump version (patch) | |
if: contains(github.event.head_commit.message, '#patch') | |
run: | | |
hatch version patch | |
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV | |
- name: Bump version (minor) | |
if: contains(github.event.head_commit.message, '#minor') | |
run: | | |
hatch version minor | |
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV | |
- name: Bump version (major) | |
if: contains(github.event.head_commit.message, '#major') | |
run: | | |
hatch version major | |
echo "TAG_NEW=v$(hatch version)" >> $GITHUB_ENV | |
- name: Commit files | |
if: | | |
contains(github.event.head_commit.message, '#patch') || | |
contains(github.event.head_commit.message, '#minor') || | |
contains(github.event.head_commit.message, '#major') | |
run: | | |
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY} | |
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.PUSH_ACTION_TOKEN }}@github.com/${REPOSITORY}.git" | |
git config --local user.email "action@github.com" | |
git config --local user.name "GitHub Action" | |
# Commit version bump to release | |
git commit -m "Bump version number" -a | |
git push "${remote_repo}" release | |
- name: Create Pull Request to merge back release into dev | |
uses: repo-sync/pull-request@v2 | |
with: | |
source_branch: "release" # If blank, default: triggered branch | |
destination_branch: "dev" # If blank, default: master | |
pr_title: "Merge release -> dev to propagate version number bump" | |
pr_body: "Changes made to the release branch (e.g. hotfixes), plus the version bump." | |
pr_assignee: "jgostick,ma-sadeghi" # Comma-separated list (no spaces) | |
pr_label: "high priority" # Comma-separated list (no spaces) | |
pr_draft: false # Creates pull request as draft | |
pr_allow_empty: true # Creates pull request even if there are no changes | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create new tag | |
run: | | |
REPOSITORY=${INPUT_REPOSITORY:-$GITHUB_REPOSITORY} | |
remote_repo="https://${GITHUB_ACTOR}:${{ secrets.PUSH_ACTION_TOKEN }}@github.com/${REPOSITORY}.git" | |
if [ -z "$TAG_NEW" ] | |
then | |
echo "New tag not created." | |
else | |
git tag $TAG_NEW | |
git push "${remote_repo}" $TAG_NEW | |
echo "Pushed a new tag: $TAG_NEW" | |
fi |