|
| 1 | +name: Release PR |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["CI"] |
| 6 | + types: [completed] |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: write |
| 10 | + pull-requests: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: release-pr |
| 14 | + cancel-in-progress: false |
| 15 | + |
| 16 | +jobs: |
| 17 | + release-pr: |
| 18 | + if: >- |
| 19 | + github.event.workflow_run.conclusion == 'success' && |
| 20 | + github.event.workflow_run.head_branch == 'master' |
| 21 | + runs-on: ubuntu-latest |
| 22 | + timeout-minutes: 15 |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 25 | + with: |
| 26 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 27 | + fetch-depth: 0 |
| 28 | + persist-credentials: false |
| 29 | + |
| 30 | + - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 |
| 31 | + with: |
| 32 | + node-version-file: .nvmrc |
| 33 | + |
| 34 | + - name: Look for changes that never shipped |
| 35 | + id: detect |
| 36 | + run: | |
| 37 | + last=$(git log -1 --format=%H -G'"version":' -- package.json) |
| 38 | + if [ -z "$last" ]; then |
| 39 | + echo "no commit found that changed the version field" >&2 |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + echo "last release commit: $last" |
| 43 | +
|
| 44 | + changed=$(git diff --name-only "$last..HEAD" -- src index.js tsconfig.json ':(exclude)src/test') |
| 45 | + git show "$last:package.json" > "$RUNNER_TEMP/old-package.json" |
| 46 | + deps=$(node scripts/dependencies-changed.js "$RUNNER_TEMP/old-package.json" package.json) |
| 47 | +
|
| 48 | + if [ -z "$changed" ] && [ "$deps" = "false" ]; then |
| 49 | + echo "nothing to release" |
| 50 | + echo "release=false" >> "$GITHUB_OUTPUT" |
| 51 | + exit 0 |
| 52 | + fi |
| 53 | + echo "changed files:" |
| 54 | + echo "$changed" |
| 55 | + echo "dependencies changed: $deps" |
| 56 | + echo "release=true" >> "$GITHUB_OUTPUT" |
| 57 | + git log --first-parent --format=%s "$last..HEAD" > "$RUNNER_TEMP/titles.txt" |
| 58 | +
|
| 59 | + - name: Prepare the bump |
| 60 | + if: steps.detect.outputs.release == 'true' |
| 61 | + id: prepare |
| 62 | + run: | |
| 63 | + mapfile -t titles < "$RUNNER_TEMP/titles.txt" |
| 64 | + version=$(node scripts/prepare-release.js "${titles[@]}") |
| 65 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Open or update the release PR |
| 68 | + if: steps.detect.outputs.release == 'true' |
| 69 | + env: |
| 70 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 71 | + VERSION: ${{ steps.prepare.outputs.version }} |
| 72 | + run: | |
| 73 | + if git ls-remote --exit-code --heads origin release/next >/dev/null 2>&1; then |
| 74 | + git fetch origin release/next |
| 75 | + author=$(git log -1 --format=%an FETCH_HEAD) |
| 76 | + if [ "$author" != "github-actions[bot]" ]; then |
| 77 | + echo "release/next carries a commit by $author, leaving it alone" |
| 78 | + exit 0 |
| 79 | + fi |
| 80 | + fi |
| 81 | +
|
| 82 | + git config user.name "github-actions[bot]" |
| 83 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 84 | + git checkout -B release/next |
| 85 | + git commit -m "chore: release $VERSION" package.json CHANGELOG.md |
| 86 | + git push --force "https://x-access-token:$GH_TOKEN@github.com/$GITHUB_REPOSITORY" release/next |
| 87 | +
|
| 88 | + if [ -z "$(gh pr list --head release/next --state open --json number --jq '.[].number')" ]; then |
| 89 | + gh pr create --base master --head release/next \ |
| 90 | + --title "Release $VERSION" \ |
| 91 | + --body "Merging this uploads $VERSION to Zapier and promotes it. Edit the changelog entry if the generated one reads badly. Once you commit to this branch the bot leaves it alone, so it will stop adding later changes from master." |
| 92 | + fi |
0 commit comments