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