• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# Github action job to test core java library features on
15# downstream client libraries before they are released.
16on:
17  pull_request:
18name: auto-release
19jobs:
20  approve:
21    runs-on: ubuntu-latest
22    if: contains(github.head_ref, 'release-please')
23    steps:
24    - uses: actions/github-script@v6
25      with:
26        github-token: ${{secrets.YOSHI_APPROVER_TOKEN}}
27        debug: true
28        script: |
29          // only approve PRs from release-please[bot]
30          if (context.payload.pull_request.user.login !== "release-please[bot]") {
31            return;
32          }
33
34          // only approve PRs like "chore(main): release <release version>"
35          if (  !context.payload.pull_request.title.startsWith("chore(main): release") ) {
36            return;
37          }
38
39          // only approve PRs with pom.xml and versions.txt changes
40          const filesPromise = github.rest.pulls.listFiles.endpoint({
41            owner: context.repo.owner,
42            repo: context.repo.repo,
43            pull_number: context.payload.pull_request.number,
44          });
45          const changed_files = await github.paginate(filesPromise)
46
47          if ( changed_files.length < 1 ) {
48            console.log( "Not proceeding since PR is empty!" )
49            return;
50          }
51
52          if ( !changed_files.some(v => v.filename.includes("pom")) || !changed_files.some(v => v.filename.includes("versions.txt")) ) {
53            console.log( "PR file changes do not have pom.xml or versions.txt -- something is wrong. PTAL!" )
54            return;
55          }
56
57          // trigger auto-release when
58          // 1) it is a SNAPSHOT release (auto-generated post regular release)
59          // 2) there are dependency updates only
60          // 3) there are no open dependency update PRs in this repo (to avoid multiple releases)
61          if (
62            context.payload.pull_request.body.includes("Fix") ||
63            context.payload.pull_request.body.includes("Build") ||
64            context.payload.pull_request.body.includes("Documentation") ||
65            context.payload.pull_request.body.includes("BREAKING CHANGES") ||
66            context.payload.pull_request.body.includes("Features")
67          ) {
68            console.log( "Not auto-releasing since it is not a dependency-update-only release." );
69            return;
70          }
71
72          const promise = github.rest.pulls.list.endpoint({
73            owner: context.repo.owner,
74            repo: context.repo.repo,
75            state: 'open'
76          });
77          const open_pulls = await github.paginate(promise)
78
79          if ( open_pulls.length > 1 && !context.payload.pull_request.title.includes("SNAPSHOT") ) {
80            for ( const pull of open_pulls ) {
81              if ( pull.title.startsWith("deps: update dependency") ) {
82                console.log( "Not auto-releasing yet since there are dependency update PRs open in this repo." );
83                return;
84              }
85            }
86          }
87
88          // approve release PR
89          await github.rest.pulls.createReview({
90            owner: context.repo.owner,
91            repo: context.repo.repo,
92            body: 'Rubber stamped release!',
93            pull_number: context.payload.pull_request.number,
94            event: 'APPROVE'
95          });
96
97          // attach kokoro:force-run and automerge labels
98          await github.rest.issues.addLabels({
99            owner: context.repo.owner,
100            repo: context.repo.repo,
101            issue_number: context.payload.pull_request.number,
102            labels: ['kokoro:force-run', 'automerge']
103          });
104