|
| 1 | +name: Sync Release-As from release PR title |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [edited] |
| 6 | + |
| 7 | +permissions: |
| 8 | + contents: write |
| 9 | + |
| 10 | +jobs: |
| 11 | + sync: |
| 12 | + if: >- |
| 13 | + github.event.pull_request.base.ref == 'master' && |
| 14 | + startsWith(github.event.pull_request.head.ref, 'release-please--') && |
| 15 | + github.event.changes.title != null |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Extract versions from old and new title |
| 19 | + id: parse |
| 20 | + env: |
| 21 | + NEW_TITLE: ${{ github.event.pull_request.title }} |
| 22 | + OLD_TITLE: ${{ github.event.changes.title.from }} |
| 23 | + run: | |
| 24 | + # Anchored on pull-request-title-pattern "release: ${version}" from release-please-config.json. |
| 25 | + extract() { |
| 26 | + echo "$1" | grep -oE '^release:[[:space:]]+v?[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?' \ |
| 27 | + | sed -E 's/^release:[[:space:]]+v?//' |
| 28 | + } |
| 29 | + NEW_VERSION=$(extract "$NEW_TITLE") |
| 30 | + OLD_VERSION=$(extract "$OLD_TITLE") |
| 31 | + echo "old=$OLD_VERSION" |
| 32 | + echo "new=$NEW_VERSION" |
| 33 | + if [ -z "$NEW_VERSION" ]; then |
| 34 | + echo "::notice::No semver in new title; nothing to do." |
| 35 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 36 | + exit 0 |
| 37 | + fi |
| 38 | + if [ "$NEW_VERSION" = "$OLD_VERSION" ]; then |
| 39 | + echo "::notice::Version unchanged ($NEW_VERSION); not pushing." |
| 40 | + echo "skip=true" >> "$GITHUB_OUTPUT" |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | + echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
| 44 | +
|
| 45 | + - name: Check out master |
| 46 | + if: steps.parse.outputs.skip != 'true' |
| 47 | + uses: actions/checkout@v6 |
| 48 | + with: |
| 49 | + ref: master |
| 50 | + token: ${{ secrets.RELEASE_PLEASE_TOKEN }} |
| 51 | + fetch-depth: 1 |
| 52 | + |
| 53 | + - name: Push empty Release-As commit |
| 54 | + if: steps.parse.outputs.skip != 'true' |
| 55 | + env: |
| 56 | + VERSION: ${{ steps.parse.outputs.version }} |
| 57 | + run: | |
| 58 | + git config user.name "release-as-bot" |
| 59 | + git config user.email "release-as-bot@users.noreply.github.com" |
| 60 | + git commit --allow-empty -m "chore: pin next release |
| 61 | +
|
| 62 | + Release-As: ${VERSION}" |
| 63 | + git push origin master |
0 commit comments