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

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

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Changes from all 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
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 }}
Loading