|
| 1 | +on: |
| 2 | +pull_request: |
| 3 | +name: auto-release |
| 4 | +jobs: |
| 5 | +approve: |
| 6 | +runs-on: ubuntu-latest |
| 7 | +if: contains(.head_ref, 'release-please') |
| 8 | +steps: |
| 9 | +- uses: actions/-script@v3 |
| 10 | +with: |
| 11 | +-token: ${{secrets.YOSHI_APPROVER_TOKEN}} |
| 12 | +debug: true |
| 13 | +script: | |
| 14 | +// only approve PRs from release-please[bot] |
| 15 | +if (context.payload.pull_request.user.login !== "release-please[bot]") { |
| 16 | +return; |
| 17 | +} |
| 18 | +
|
| 19 | +// only approve PRs like "chore: release <release version>" |
| 20 | +if ( !context.payload.pull_request.title.startsWith("chore: release") ) { |
| 21 | +return; |
| 22 | +} |
| 23 | +
|
| 24 | +// only approve PRs with pom.xml and versions.txt changes |
| 25 | +const filesPromise = .pulls.listFiles.endpoint({ |
| 26 | +owner: context.repo.owner, |
| 27 | +repo: context.repo.repo, |
| 28 | +pull_number: context.payload.pull_request.number, |
| 29 | +}); |
| 30 | +const changed_files = await .paginate(filesPromise) |
| 31 | +
|
| 32 | +if ( changed_files.length < 1 ) { |
| 33 | +console.log( "Not proceeding since PR is empty!" ) |
| 34 | +return; |
| 35 | +} |
| 36 | +
|
| 37 | +if ( !changed_files.some(v => v.filename.includes("pom")) || !changed_files.some(v => v.filename.includes("versions.txt")) ) { |
| 38 | +console.log( "PR file changes do not have pom.xml or versions.txt -- something is wrong. PTAL!" ) |
| 39 | +return; |
| 40 | +} |
| 41 | +
|
| 42 | +// trigger auto-release when |
| 43 | +// 1) it is a SNAPSHOT release (auto-generated post regular release) |
| 44 | +// 2) there are dependency updates only |
| 45 | +// 3) there are no open dependency update PRs in this repo (to avoid multiple releases) |
| 46 | +if ( |
| 47 | +context.payload.pull_request.body.includes("Fix") || |
| 48 | +context.payload.pull_request.body.includes("Build") || |
| 49 | +context.payload.pull_request.body.includes("Documentation") || |
| 50 | +context.payload.pull_request.body.includes("BREAKING CHANGES") || |
| 51 | +context.payload.pull_request.body.includes("Features") |
| 52 | +) { |
| 53 | +console.log( "Not auto-releasing since it is not a dependency-update-only release." ); |
| 54 | +return; |
| 55 | +} |
| 56 | +
|
| 57 | +const promise = .pulls.list.endpoint({ |
| 58 | +owner: context.repo.owner, |
| 59 | +repo: context.repo.repo, |
| 60 | +state: 'open' |
| 61 | +}); |
| 62 | +const open_pulls = await .paginate(promise) |
| 63 | +
|
| 64 | +if ( open_pulls.length > 1 && !context.payload.pull_request.title.includes("SNAPSHOT") ) { |
| 65 | +for ( const pull of open_pulls ) { |
| 66 | +if ( pull.title.startsWith("deps: update dependency") ) { |
| 67 | +console.log( "Not auto-releasing yet since there are dependency update PRs open in this repo." ); |
| 68 | +return; |
| 69 | +} |
| 70 | +} |
| 71 | +} |
| 72 | +
|
| 73 | +// approve release PR |
| 74 | +await .pulls.createReview({ |
| 75 | +owner: context.repo.owner, |
| 76 | +repo: context.repo.repo, |
| 77 | +body: 'Rubber stamped release!', |
| 78 | +pull_number: context.payload.pull_request.number, |
| 79 | +event: 'APPROVE' |
| 80 | +}); |
| 81 | +
|
| 82 | +// attach kokoro:force-run and automerge labels |
| 83 | +await .issues.addLabels({ |
| 84 | +owner: context.repo.owner, |
| 85 | +repo: context.repo.repo, |
| 86 | +issue_number: context.payload.pull_request.number, |
| 87 | +labels: ['kokoro:force-run', 'automerge'] |
| 88 | +}); |
0 commit comments