Skip to content

chore: Add github action to update discovery artifacts #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Copyright 2021 Google LLC

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

# https://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: A workflow for updating discovery artifacts
# Controls when the action will run.

on:
schedule:
# * is a special character in YAML so you have to quote this string
# Run this Github Action every day at 7 AM UTC
- cron: '* 7 * * *'

jobs:
build:
name: Update Discovery Artifacts PR
runs-on: ubuntu-latest
steps:
- name: Get current date
id: date
run: echo "::set-output name=current_date::$(date +'%Y-%m-%d')"

- name: Check out master branch
uses: actions/checkout@v2
with:
ref: refs/heads/master

- name: Create branch
run: |
git checkout -b update-discovery-artifacts-${{ steps.date.outputs.current_date }}

- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9

- name: Install google-api-python-client
run: pip3 install -e .

- name: Install script dependencies
run: pip3 install -r requirements.txt
working-directory: ./scripts

# Apply a workaround to discovery.py to avoid DefaultCredentialsError
# which is raised when calling `build_from_document()` as a result of
# `google.auth.default()`. The workaround is to bypass the code block that
# attempts to load default credentials.
- name: Workaround to avoid DefaultCredentialsError in discovery.py
run: sed -i -e 's/if credentials is None/if False/g' googleapiclient/discovery.py

- name: Run Change Summary
run: python3 updatediscoveryartifacts.py
working-directory: ./scripts

- name: Commit changes
run: ./createcommits.sh
working-directory: ./scripts

- name: Push changes
run: git push -f --set-upstream origin update-discovery-artifacts-${{ steps.date.outputs.current_date }}

- name: Prepare summary for PR Body
id: pr_body
shell: bash
run: |
python3 buildprbody.py
output=$(cat temp/allapis.summary)
output="${output//'%'/'%25'}"
output="${output//$'\n'/'%0A'}"
output="${output//$'\r'/'%0D'}"
echo "::set-output name=change_summary::$output"
working-directory: ./scripts

- name: Create PR
uses: actions/[email protected]
with:
github-token: ${{secrets.YOSHI_CODE_BOT_TOKEN}}
script: |
async function createPR () {
const { owner, repo } = context.repo
const branch = 'update-discovery-artifacts-${{ steps.date.outputs.current_date }}'
let prBody = `${{ steps.pr_body.outputs.change_summary }}`
const prTitle = 'chore: Update discovery artifacts'
const pullRequests = await github.pulls.list({
owner: owner,
repo: repo,
head: `${owner}:${branch}`,
state: 'open'
})

if (pullRequests.data.length === 1) {
prNumber = pullRequests.data[0].number
await github.pulls.update({
owner: owner,
repo: repo,
pull_number: prNumber,
title: prTitle,
body: prBody
})
console.log('Updated PR')
} else {
const createPrResult = await github.pulls.create({
owner: owner,
repo: repo,
base: 'master',
head: `${owner}:${branch}`,
title: prTitle,
body: prBody
})
prNumber = createPrResult.data.number
console.log('Created PR')
}
}
createPR()