Skip to content

Commit

Permalink
build: switch codegen to GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
chingor13 committed Feb 23, 2022
1 parent 3aefd29 commit 4e8dd4b
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/codegen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
schedule:
# daily at 12:30 am
- cron: '30 0 * * *'
workflow_dispatch:

name: codegen
jobs:
discovery:
uses: googleapis/discovery-artifact-manager/.github/workflows/list-services.yml@master

generate:
runs-on: ubuntu-latest
needs: discovery
strategy:
fail-fast: false
max-parallel: 4
matrix:
service: ['abusiveexperiencereport', 'admin', 'admob']
# service: ${{fromJson(needs.discovery.outputs.services)}}
steps:
- run: echo generating ${{ matrix.service }}
- uses: actions/checkout@v2
with:
fetch-depth: 1
path: google-api-php-client-services
- uses: actions/checkout@v2
with:
repository: googleapis/discovery-artifact-manager
fetch-depth: 1
path: discovery-artifact-manager
- uses: actions/setup-python@v2
with:
python-version: 2.7
- id: find-preferred-versions
run: |
versions=$( cat discovery-artifact-manager/discoveries/index.json | jq -r '[.items[] | select(.name == "${{ matrix.service }}" and .name != "discovery" and .name != "websecurityscanner") | select(.name == "admin" or .preferred).version] | join(",")' )
echo "::set-output name=versions::$versions"
- run: ./google-api-php-client-services/.github/workflows/generate.sh ${{ matrix.service }} ${{ steps.find-preferred-versions.outputs.versions }}
- uses: googleapis/code-suggester@v2 # takes the changes from git directory
env:
ACCESS_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
with:
command: pr
upstream_owner: ${{ github.repository_owner }}
upstream_repo: google-api-php-client-services
description: 'Generated in GitHub action: https://github.com/${{ github.repository_owner }}/${{ github.repository }}/actions/workflows/codegen.yaml'
title: 'Regenerate ${{ matrix.service }} client'
message: 'Regenerate ${{ matrix.service }} client'
branch: regenerate-${{ matrix.service }}
git_dir: 'google-api-php-client-services/src'
primary: main
force: true
fork: true
57 changes: 57 additions & 0 deletions .github/workflows/generate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

# Copyright 2022 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.

set -ex

SERVICE=$1
VERSIONS=$2
ROOT_DIR=$(realpath $(dirname "${BASH_SOURCE[0]}")/../../../)

if [[ -z "${SERVICE}" ]]
then
echo "Usage: ${0} <service> <versions>"
exit 1
fi

if [[ -z "${VERSIONS}" ]]
then
echo "Usage: ${0} <service> <versions>"
exit 1
fi

# install the local generators
python2 -m pip install -e ${ROOT_DIR}/google-api-php-client-services/generator --user -q

pushd ${ROOT_DIR}/discovery-artifact-manager

OIFS=$IFS
IFS=','
for VERSION in ${VERSIONS}
do
DISCOVERY=discoveries/${SERVICE}.${VERSION}.json
OUTPUT_DIR=${ROOT_DIR}/google-api-php-client-services/src
echo "Discovery: ${DISCOVERY}"
echo "Version: ${VERSION}"
echo "Output: ${OUTPUT_DIR}"
# run the local generator
python2 -m googleapis.codegen \
--output_dir=${OUTPUT_DIR} \
--input=${DISCOVERY} \
--language=php \
--language_variant=default \
--package_path=api/services
done
IFS=${OIFS}

0 comments on commit 4e8dd4b

Please sign in to comment.