Skip to content

PR merge시 label에 맞추어 패키지의 버전을 자동으로 올리는 worflow 추가 #1

PR merge시 label에 맞추어 패키지의 버전을 자동으로 올리는 worflow 추가

PR merge시 label에 맞추어 패키지의 버전을 자동으로 올리는 worflow 추가 #1

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 }}