|
| 1 | +name: Update Version on PR Merge |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: |
| 6 | + - closed |
| 7 | + |
| 8 | +jobs: |
| 9 | + update_version: |
| 10 | + if: github.event.pull_request.merged == true |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + # Checkout the code |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + # Set up Python |
| 19 | + - name: Set up Python |
| 20 | + uses: actions/setup-python@v4 |
| 21 | + with: |
| 22 | + python-version: '3.8' |
| 23 | + |
| 24 | + # Install poetry |
| 25 | + - name: Install Poetry |
| 26 | + run: | |
| 27 | + pipx install poetry==1.8.4 |
| 28 | + echo "$HOME/.local/bin" >> $GITHUB_PATH |
| 29 | +
|
| 30 | + # Install project dependencies |
| 31 | + - name: Install dependencies |
| 32 | + run: poetry install |
| 33 | + |
| 34 | + # Determine the version bump type |
| 35 | + - name: Determine version bump type |
| 36 | + id: version_type |
| 37 | + run: | |
| 38 | + JSON_LABELS='${{ toJson(github.event.pull_request.labels) }}' |
| 39 | + if echo "$JSON_LABELS" | jq -e '.[] | select(.name == "major")' >/dev/null; then |
| 40 | + echo "type=major" >> $GITHUB_ENV |
| 41 | + elif echo "$JSON_LABELS" | jq -e '.[] | select(.name == "minor")' >/dev/null; then |
| 42 | + echo "type=minor" >> $GITHUB_ENV |
| 43 | + elif echo "$JSON_LABELS" | jq -e '.[] | select(.name == "patch")' >/dev/null; then |
| 44 | + echo "type=patch" >> $GITHUB_ENV |
| 45 | + else |
| 46 | + echo "No version bump label found." |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | +
|
| 50 | + # Bump the version using poetry |
| 51 | + - name: Bump version |
| 52 | + run: | |
| 53 | + poetry version ${{ env.type }} |
| 54 | + NEW_VERSION=$(poetry version -s) |
| 55 | + echo "new_version=${NEW_VERSION}" >> $GITHUB_ENV |
| 56 | +
|
| 57 | + # Commit the version change |
| 58 | + - name: Commit version update |
| 59 | + run: | |
| 60 | + git config user.name "github-actions[bot]" |
| 61 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 62 | + git add pyproject.toml |
| 63 | + git commit -m "Bump version to ${{ env.new_version }}" |
| 64 | +
|
| 65 | + # Push the changes |
| 66 | + - name: Push changes |
| 67 | + run: | |
| 68 | + git push origin HEAD |
| 69 | +
|
| 70 | + # Create a Git tag |
| 71 | + - name: Create Git tag |
| 72 | + run: | |
| 73 | + git tag -a v${{ env.new_version }} -m "Version ${{ env.new_version }}" |
| 74 | + git push origin v${{ env.new_version }} |
0 commit comments