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-merge-readme 19jobs: 20 approve: 21 runs-on: ubuntu-latest 22 if: github.repository_owner == 'googleapis' && github.head_ref == 'autosynth-readme' 23 steps: 24 - uses: actions/github-script@v6 25 with: 26 github-token: ${{secrets.YOSHI_APPROVER_TOKEN}} 27 script: | 28 // only approve PRs from yoshi-automation 29 if (context.payload.pull_request.user.login !== "yoshi-automation") { 30 return; 31 } 32 33 // only approve PRs like "chore: release <release version>" 34 if (!context.payload.pull_request.title === "chore: regenerate README") { 35 return; 36 } 37 38 // only approve PRs with README.md and synth.metadata changes 39 const files = new Set( 40 ( 41 await github.paginate( 42 github.pulls.listFiles.endpoint({ 43 owner: context.repo.owner, 44 repo: context.repo.repo, 45 pull_number: context.payload.pull_request.number, 46 }) 47 ) 48 ).map(file => file.filename) 49 ); 50 if (files.size != 2 || !files.has("README.md") || !files.has(".github/readme/synth.metadata/synth.metadata")) { 51 return; 52 } 53 54 // approve README regeneration PR 55 await github.pulls.createReview({ 56 owner: context.repo.owner, 57 repo: context.repo.repo, 58 body: 'Rubber stamped PR!', 59 pull_number: context.payload.pull_request.number, 60 event: 'APPROVE' 61 }); 62 63 // attach automerge label 64 await github.issues.addLabels({ 65 owner: context.repo.owner, 66 repo: context.repo.repo, 67 issue_number: context.payload.pull_request.number, 68 labels: ['automerge'] 69 }); 70