|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: release |
| 10 | + cancel-in-progress: true |
| 11 | + |
| 12 | +permissions: |
| 13 | + contents: write |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + name: Tag, Release, and Version Bump |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + |
| 26 | + - name: Read version from pantheon.php |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + VERSION=$(grep -oP "define\( 'PANTHEON_MU_PLUGIN_VERSION', '\K[^']+" pantheon.php) |
| 30 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 31 | + echo "Detected version: $VERSION" |
| 32 | +
|
| 33 | + - name: Check whether this is a release version |
| 34 | + id: check |
| 35 | + run: | |
| 36 | + VERSION="${{ steps.version.outputs.version }}" |
| 37 | + if [[ "$VERSION" == *-dev ]]; then |
| 38 | + echo "is_release=false" >> "$GITHUB_OUTPUT" |
| 39 | + echo "Version $VERSION ends in -dev — skipping release." |
| 40 | + else |
| 41 | + echo "is_release=true" >> "$GITHUB_OUTPUT" |
| 42 | + echo "Version $VERSION is a release candidate — proceeding." |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Configure git identity |
| 46 | + if: steps.check.outputs.is_release == 'true' |
| 47 | + run: | |
| 48 | + git config user.email "bot@getpantheon.com" |
| 49 | + git config user.name "Pantheon Robot" |
| 50 | +
|
| 51 | + - name: Create Git tag |
| 52 | + if: steps.check.outputs.is_release == 'true' |
| 53 | + run: | |
| 54 | + VERSION="${{ steps.version.outputs.version }}" |
| 55 | + git tag "$VERSION" |
| 56 | + git push origin "$VERSION" |
| 57 | +
|
| 58 | + - name: Create GitHub Release |
| 59 | + if: steps.check.outputs.is_release == 'true' |
| 60 | + run: | |
| 61 | + VERSION="${{ steps.version.outputs.version }}" |
| 62 | + gh release create "$VERSION" \ |
| 63 | + --generate-notes \ |
| 64 | + --title "$VERSION" |
| 65 | + env: |
| 66 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 67 | + |
| 68 | + - name: Compute next dev version |
| 69 | + if: steps.check.outputs.is_release == 'true' |
| 70 | + id: next |
| 71 | + run: | |
| 72 | + VERSION="${{ steps.version.outputs.version }}" |
| 73 | + IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION" |
| 74 | + NEXT_PATCH=$(( PATCH + 1 )) |
| 75 | + NEXT_VERSION="${MAJOR}.${MINOR}.${NEXT_PATCH}-dev" |
| 76 | + echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT" |
| 77 | + echo "Next dev version: $NEXT_VERSION" |
| 78 | +
|
| 79 | + - name: Bump version in pantheon.php |
| 80 | + if: steps.check.outputs.is_release == 'true' |
| 81 | + run: | |
| 82 | + NEXT="${{ steps.next.outputs.next_version }}" |
| 83 | + sed -i "s/^\( \* Version: \).*/\1${NEXT}/" pantheon.php |
| 84 | + sed -i "s/\(define( 'PANTHEON_MU_PLUGIN_VERSION', '\)[^']*\(.*\)/\1${NEXT}\2/" pantheon.php |
| 85 | +
|
| 86 | + - name: Verify both version strings were updated |
| 87 | + if: steps.check.outputs.is_release == 'true' |
| 88 | + run: | |
| 89 | + NEXT="${{ steps.next.outputs.next_version }}" |
| 90 | + COUNT=$(grep -c "$NEXT" pantheon.php) |
| 91 | + if [ "$COUNT" -lt 2 ]; then |
| 92 | + echo "ERROR: Expected at least 2 occurrences of $NEXT in pantheon.php, found $COUNT" |
| 93 | + grep -n "Version\|PANTHEON_MU_PLUGIN_VERSION" pantheon.php |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | + echo "Both version strings updated to $NEXT" |
| 97 | + grep -n "Version\|PANTHEON_MU_PLUGIN_VERSION" pantheon.php |
| 98 | +
|
| 99 | + - name: Open version bump PR |
| 100 | + if: steps.check.outputs.is_release == 'true' |
| 101 | + run: | |
| 102 | + NEXT="${{ steps.next.outputs.next_version }}" |
| 103 | + BRANCH="chore/bump-version-${NEXT}" |
| 104 | + git checkout -b "$BRANCH" |
| 105 | + git add pantheon.php |
| 106 | + git commit -m "chore: bump version to ${NEXT}" |
| 107 | + git push origin "$BRANCH" |
| 108 | + gh pr create \ |
| 109 | + --title "chore: bump version to ${NEXT}" \ |
| 110 | + --body "Automated version bump after release. Merges automatically." \ |
| 111 | + --base main \ |
| 112 | + --head "$BRANCH" |
| 113 | + gh pr merge "$BRANCH" --auto --squash |
| 114 | + env: |
| 115 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments