Skip to content

Commit

Permalink
prevent bumping version twice
Browse files Browse the repository at this point in the history
  • Loading branch information
gpmayorga committed Dec 20, 2024
1 parent 387aa55 commit f8b168e
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
push:
branches:
- main
- fix_yarn_version_cli
pull_request_review:
types: [submitted]

Expand All @@ -16,13 +15,32 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}
ref: ${{ github.event.pull_request.head.ref || github.ref_name }}

- name: Check if version was already bumped
id: version_check
run: |
if [ "${{ github.event_name }}" == "pull_request_review" ]; then
CURRENT_SHA=$(git rev-parse HEAD)
COMMITS=$(git log --format=%B -n 10)
if echo "$COMMITS" | grep -q "\[bot\] New pkg version:"; then
echo "Version was already bumped in this branch"
echo "skip_bump=true" >> $GITHUB_OUTPUT
else
echo "No version bump found in recent commits"
echo "skip_bump=false" >> $GITHUB_OUTPUT
fi
else
echo "skip_bump=false" >> $GITHUB_OUTPUT
fi
- name: Check last PR labels
id: check_labels
if: |
steps.version_check.outputs.skip_bump != 'true' &&
github.event.review.state == 'approved'
env:
GH_TOKEN: ${{ github.token }}
# if: github.event.review.state == 'approved'
run: |
LAST_PR_NUMBER=$(gh pr list --state merged --json number --jq '.[0].number')
LABELS=$(gh pr view "$LAST_PR_NUMBER" --json labels --jq '.labels[].name')
Expand All @@ -45,7 +63,10 @@ jobs:
- name: Bump version
id: bump
# if: github.event.review.state == 'approved' && steps.check_labels.outputs.version != 'no-release'
if: |
steps.version_check.outputs.skip_bump != 'true' &&
steps.check_labels.outputs.version != 'no-release' &&
github.event.review.state == 'approved'
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
Expand All @@ -57,7 +78,10 @@ jobs:
git push
- name: Create GitHub Release
if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.check_labels.outputs.version != 'no-release'
if: |
github.event_name == 'push' &&
github.ref == 'refs/heads/main' &&
steps.check_labels.outputs.version != 'no-release'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
Expand Down

0 comments on commit f8b168e

Please sign in to comment.