|
| 1 | +--- |
| 2 | +name: Suggest Version Bump |
| 3 | + |
| 4 | +permissions: |
| 5 | + contents: read |
| 6 | + pull-requests: read |
| 7 | + statuses: read |
| 8 | + |
| 9 | +on: |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + paths: |
| 14 | + - 'database/**/*.sql' |
| 15 | + workflow_call: |
| 16 | + outputs: |
| 17 | + next_version: |
| 18 | + description: 'The next suggested version' |
| 19 | + value: ${{ jobs.suggest-bump.outputs.next_version }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + get-labels: |
| 23 | + name: Get PR Labels |
| 24 | + uses: ./.github/workflows/get-pr-labels.yml |
| 25 | + |
| 26 | + suggest-bump: |
| 27 | + name: Suggest Version Bump |
| 28 | + needs: get-labels |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + next_version: ${{ steps.next_version.outputs.next_version }} |
| 32 | + steps: |
| 33 | + - name: Checkout code |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - name: Determine bump type |
| 39 | + id: bump |
| 40 | + run: | |
| 41 | + LABELS="${{ needs.get-labels.outputs.labels }}" |
| 42 | + BUMP="patch" |
| 43 | + echo "$LABELS" | grep -q 'type: feature' && BUMP="minor" |
| 44 | + echo "$LABELS" | grep -q 'type: security' && BUMP="minor" |
| 45 | + echo "$LABELS" | grep -q 'type: breaking' && BUMP="major" |
| 46 | + echo "bump=$BUMP" >> "$GITHUB_OUTPUT" |
| 47 | +
|
| 48 | + - name: Get latest tag |
| 49 | + id: latest_tag |
| 50 | + run: | |
| 51 | + TAG=$(git tag --list 'v*' --sort=-v:refname | head -n1) |
| 52 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 53 | +
|
| 54 | + - name: Calculate next version |
| 55 | + id: next_version |
| 56 | + run: | |
| 57 | + TAG="${{ steps.latest_tag.outputs.tag }}" |
| 58 | + BUMP="${{ steps.bump.outputs.bump }}" |
| 59 | + if [ -z "$TAG" ]; then |
| 60 | + TAG="v0.0.0" |
| 61 | + fi |
| 62 | + VERSION=$(echo "$TAG" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+).*/\1/') |
| 63 | + PRERELEASE=$(echo "$TAG" | sed -nE 's/^v[0-9]+\.[0-9]+\.[0-9]+(-[A-Za-z0-9.-]+)?$/\1/p') |
| 64 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 65 | + case "$BUMP" in |
| 66 | + major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; |
| 67 | + minor) MINOR=$((MINOR + 1)); PATCH=0 ;; |
| 68 | + patch) PATCH=$((PATCH + 1)) ;; |
| 69 | + esac |
| 70 | + if [ -n "$PRERELEASE" ]; then |
| 71 | + NEXT_VERSION="v${MAJOR}.${MINOR}.${PATCH}${PRERELEASE}" |
| 72 | + else |
| 73 | + NEXT_VERSION="v${MAJOR}.${MINOR}.${PATCH}" |
| 74 | + fi |
| 75 | + echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" |
| 76 | +
|
| 77 | + - name: Report summary |
| 78 | + run: | |
| 79 | + { |
| 80 | + echo "### 🚀 Suggested Version Bump: **${{ steps.bump.outputs.bump }}**" |
| 81 | + echo "#### Latest tag: \`${{ steps.latest_tag.outputs.tag }}\`" |
| 82 | + echo "#### Next version: \`${{ steps.next_version.outputs.next_version }}\`" |
| 83 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments