From 701aa1ddd7194bd0b4e3047370c6686cb9370c7c Mon Sep 17 00:00:00 2001 From: yoshi-automation Date: Tue, 22 Sep 2020 01:48:40 -0700 Subject: [PATCH] build(ci): enable auto-release for dependency-update-only releases Automatically perform a Java client library release when: 1. Only dependency updates are going out in the release since any releases containing bug fixes, build changes or new features should be supervised; 2. There are no outstanding/open dependency update pull requests in the repo. This is to avoid multiple/redundant releases; 3. It is a SNAPSHOT release which is automatically generated post regular release -- this requires no human supervision. Testing done in 5 java-bigquery* client library repos. Example: [chore: release 0.3.4 ](https://github.com/googleapis/java-bigqueryconnection/pull/130) [chore: release 0.3.5-SNAPSHOT](https://github.com/googleapis/java-bigqueryconnection/pull/131) Source-Author: Stephanie Wang Source-Date: Thu Sep 17 15:30:02 2020 -0400 Source-Repo: googleapis/synthtool Source-Sha: 538a68019eb4a36a0cdfa4021f324dd01b784395 Source-Link: https://github.com/googleapis/synthtool/commit/538a68019eb4a36a0cdfa4021f324dd01b784395 --- .github/workflows/auto-release.yaml | 69 +++++++++++++++++++++++++++++ synth.metadata | 5 ++- 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/auto-release.yaml diff --git a/.github/workflows/auto-release.yaml b/.github/workflows/auto-release.yaml new file mode 100644 index 00000000000..d26427e468a --- /dev/null +++ b/.github/workflows/auto-release.yaml @@ -0,0 +1,69 @@ +on: + pull_request: +name: auto-release +jobs: + approve: + runs-on: ubuntu-latest + steps: + - uses: actions/github-script@v3.0.0 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + debug: true + script: | + // only approve PRs from release-please[bot] + if (context.payload.pull_request.user.login !== "release-please[bot]") { + return; + } + + // only approve PRs like "chore: release " + if ( !context.payload.pull_request.title.startsWith("chore: release") ) { + return; + } + + // trigger auto-release when + // 1) it is a SNAPSHOT release (auto-generated post regular release) + // 2) there are dependency updates only + // 3) there are no open dependency update PRs in this repo (to avoid multiple releases) + if ( + context.payload.pull_request.body.includes("Fix") || + context.payload.pull_request.body.includes("Build") || + context.payload.pull_request.body.includes("Documentation") || + context.payload.pull_request.body.includes("BREAKING CHANGES") || + context.payload.pull_request.body.includes("Features") + ) { + console.log( "Not auto-releasing since it is not a dependency-update-only release." ); + return; + } + + const promise = github.pulls.list.endpoint({ + owner: context.repo.owner, + repo: context.repo.repo, + state: 'open' + }); + const open_pulls = await github.paginate(promise) + + if ( open_pulls.length > 1 && !context.payload.pull_request.title.includes("SNAPSHOT") ) { + for ( const pull of open_pulls ) { + if ( pull.title.startsWith("deps: update dependency") ) { + console.log( "Not auto-releasing yet since there are dependency update PRs open in this repo." ); + return; + } + } + } + + // approve release PR + await github.pulls.createReview({ + owner: context.repo.owner, + repo: context.repo.repo, + body: 'Rubber stamped release!', + pull_number: context.payload.pull_request.number, + event: 'APPROVE' + }); + + // attach kokoro:force-run and automerge labels + await github.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.payload.pull_request.number, + labels: ['kokoro:force-run', 'automerge'] + }); \ No newline at end of file diff --git a/synth.metadata b/synth.metadata index cdd58d65a9b..8badadea597 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,7 +4,7 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/java-spanner.git", - "sha": "51d07f0e17a1de36ccb219f6fac88c575dd0e99e" + "sha": "73f97337f7fddaed538c0e262d8a481770e8ef3d" } }, { @@ -19,7 +19,7 @@ "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "019c7168faa0e56619f792693a8acdb30d6de19b" + "sha": "538a68019eb4a36a0cdfa4021f324dd01b784395" } } ], @@ -60,6 +60,7 @@ ".github/PULL_REQUEST_TEMPLATE.md", ".github/release-please.yml", ".github/trusted-contribution.yml", + ".github/workflows/auto-release.yaml", ".github/workflows/ci.yaml", ".github/workflows/samples.yaml", ".kokoro/build.bat",