From 4e8dd4ba1a9e0c87a80f2e8d002a56cf594785cf Mon Sep 17 00:00:00 2001 From: Jeff Ching Date: Tue, 22 Feb 2022 15:47:46 -0800 Subject: [PATCH] build: switch codegen to GitHub actions --- .github/workflows/codegen.yml | 54 +++++++++++++++++++++++++++++++++ .github/workflows/generate.sh | 57 +++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 .github/workflows/codegen.yml create mode 100755 .github/workflows/generate.sh diff --git a/.github/workflows/codegen.yml b/.github/workflows/codegen.yml new file mode 100644 index 0000000000..a80f6d9cb5 --- /dev/null +++ b/.github/workflows/codegen.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/generate.sh b/.github/workflows/generate.sh new file mode 100755 index 0000000000..69710e8eeb --- /dev/null +++ b/.github/workflows/generate.sh @@ -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} " + exit 1 +fi + +if [[ -z "${VERSIONS}" ]] +then + echo "Usage: ${0} " + 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}