Skip to content

Commit

Permalink
feat(ci): add version bump logic to GitHub Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hanlee55 committed Nov 23, 2024
1 parent 8d404dc commit 5a0a006
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/update-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: Update Version on PR Merge

on:
pull_request:
types:
- closed

jobs:
update_version:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3

# Set up Python
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'

# Install poetry
- name: Install Poetry
run: |
pipx install poetry==1.8.4
echo "$HOME/.local/bin" >> $GITHUB_PATH
# Install project dependencies
- name: Install dependencies
run: poetry install

# Determine the version bump type
- name: Determine version bump type
id: version_type
run: |
JSON_LABELS='${{ toJson(github.event.pull_request.labels) }}'
if echo "$JSON_LABELS" | jq -e '.[] | select(.name == "major")' >/dev/null; then
echo "type=major" >> $GITHUB_ENV
elif echo "$JSON_LABELS" | jq -e '.[] | select(.name == "minor")' >/dev/null; then
echo "type=minor" >> $GITHUB_ENV
elif echo "$JSON_LABELS" | jq -e '.[] | select(.name == "patch")' >/dev/null; then
echo "type=patch" >> $GITHUB_ENV
else
echo "No version bump label found."
exit 1
fi
# Bump the version using poetry
- name: Bump version
run: |
poetry version ${{ env.type }}
NEW_VERSION=$(poetry version -s)
echo "new_version=${NEW_VERSION}" >> $GITHUB_ENV
# Commit the version change
- name: Commit version update
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml
git commit -m "Bump version to ${{ env.new_version }}"
# Push the changes
- name: Push changes
run: |
git push origin HEAD
# Create a Git tag
- name: Create Git tag
run: |
git tag -a v${{ env.new_version }} -m "Version ${{ env.new_version }}"
git push origin v${{ env.new_version }}

0 comments on commit 5a0a006

Please sign in to comment.