Skip to content

Commit 82b80c6

Browse files
committed
chore: Add github action to update discovery artifacts
1 parent aff037a commit 82b80c6

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

.github/workflows/main.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Copyright 2021 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+
# https://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+
15+
name: A workflow for updating discovery artifacts
16+
# Controls when the action will run.
17+
18+
on:
19+
schedule:
20+
# * is a special character in YAML so you have to quote this string
21+
# Run this Github Action every day at 7 AM UTC
22+
- cron: '* 7 * * *'
23+
24+
# Triggers the workflow on pull request events but only for the master branch
25+
pull_request:
26+
branches: [ master ]
27+
28+
jobs:
29+
build:
30+
name: Update Discovery Artifacts PR
31+
runs-on: ubuntu-latest
32+
if: |
33+
${{github.event.pull_request.user.login == 'parthea' && github.event.pull_request.title == 'chore: Add github action to update discovery artifacts'}}
34+
steps:
35+
- name: Check out master branch
36+
uses: actions/checkout@v2
37+
with:
38+
ref: refs/heads/master
39+
40+
- name: Create branch
41+
run: |
42+
git checkout -b update-discovery-artifacts
43+
44+
- name: Set up Python 3.9
45+
uses: actions/setup-python@v1
46+
with:
47+
python-version: 3.9
48+
49+
- name: Install google-api-python-client
50+
run: pip3 install -e .
51+
52+
- name: Install script dependencies
53+
run: pip3 install -r scripts/requirements.txt
54+
55+
# Apply a workaround to discovery.py to avoid DefaultCredentialsError
56+
# which is raised when calling `build_from_document()` as a result of
57+
# `google.auth.default()`. The workaround is to bypass the code block that
58+
# attempts to load default credentials.
59+
- name: Workaround to avoid DefaultCredentialsError in discovery.py
60+
run: sed -i -e 's/if credentials is None/if False/g' googleapiclient/discovery.py
61+
62+
- name: Run Change Summary
63+
run: python3 scripts/updatediscoveryartifacts.py
64+
65+
- name: Commit changes
66+
run: scripts/createcommits.sh
67+
68+
- name: Push changes
69+
run: git push -f --set-upstream origin update-discovery-artifacts
70+
71+
- name: Prepare summary for PR Body
72+
id: pr_body
73+
shell: bash
74+
run: |
75+
python3 buildprbody.py
76+
output=$(cat temp/allapis.summary)
77+
output="${output//'%'/'%25'}"
78+
output="${output//$'\n'/'%0A'}"
79+
output="${output//$'\r'/'%0D'}"
80+
echo "::set-output name=change_summary::$output"
81+
82+
- name: Create PR
83+
uses: actions/[email protected]
84+
with:
85+
github-token: ${{secrets.YOSHI_CODE_BOT_TOKEN}}
86+
script: |
87+
async function createPR () {
88+
const { owner, repo } = context.repo
89+
const branch = 'update-discovery-artifacts'
90+
let prBody = `${{ steps.pr_body.outputs.change_summary }}`
91+
const prTitle = 'chore: Update discovery artifacts'
92+
const pullRequests = await github.pulls.list({
93+
owner: owner,
94+
repo: repo,
95+
head: `${owner}:${branch}`,
96+
state: 'open'
97+
})
98+
99+
if (pullRequests.data.length === 1) {
100+
prNumber = pullRequests.data[0].number
101+
await github.pulls.update({
102+
owner: owner,
103+
repo: repo,
104+
pull_number: prNumber,
105+
title: prTitle,
106+
body: prBody
107+
})
108+
console.log('Updated PR')
109+
} else {
110+
const createPrResult = await github.pulls.create({
111+
owner: owner,
112+
repo: repo,
113+
base: 'master',
114+
head: `${owner}:${branch}`,
115+
title: prTitle,
116+
body: prBody
117+
})
118+
prNumber = createPrResult.data.number
119+
console.log('Created PR')
120+
}
121+
}
122+
createPR()

0 commit comments

Comments
 (0)