From 9879a84afe53a4e83710e0016c40273e60873feb Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Sun, 8 Dec 2019 16:07:44 -0800 Subject: [PATCH 1/3] build: auto-run generation and submit prs --- package.json | 3 +- src/generator/synth.ts | 68 ++++++++++++++++++++++++++++++++++++++++++ synth.py | 15 +++------- 3 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 src/generator/synth.ts diff --git a/package.json b/package.json index 2bf331adab..d9f3b05521 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,8 @@ "generate": "node build/src/generator/generate.js", "postgenerate": "npm run fix", "docs-test": "linkinator docs", - "predocs-test": "npm run docs" + "predocs-test": "npm run docs", + "submit-prs": "node build/src/generator/synth.js" }, "author": "Google Inc.", "keywords": [ diff --git a/src/generator/synth.ts b/src/generator/synth.ts new file mode 100644 index 0000000000..477c2883b3 --- /dev/null +++ b/src/generator/synth.ts @@ -0,0 +1,68 @@ +// Copyright 2019 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 +// +// http://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. + +import * as execa from 'execa'; +import * as path from 'path'; +import * as fs from 'fs'; +import * as gaxios from 'gaxios'; + +async function main() { + const statusResult = await execa('git', ['status']); + const status = statusResult.stdout; + const apiDir = path.resolve('./src/apis'); + const files = fs.readdirSync(apiDir); + const token = process.env.GITHUB_TOKEN; + if (!token) { + throw new Error('please include a GITHUB_TOKEN'); + } + const dirs = files.filter(f => { + return ( + fs.statSync(path.join(apiDir, f)).isDirectory() && + status.includes(`src/apis/${f}`) + ); + }); + console.log(`Changes found in ${dirs.length} APIs`); + for (const dir of dirs) { + try { + console.log(`Submitting change for ${dir}...`); + const branch = `api-${dir}`; + const title = `feat(${dir}): update the API`; + await execa('git', ['checkout', '-B', branch]); + await execa('git', ['add', path.join('src/apis', dir)]); + await execa('git', ['commit', '-m', title]); + await execa('git', ['push', 'origin', branch, '--force']); + await gaxios.request({ + method: 'POST', + headers: { + Authorization: `token ${token}`, + }, + url: + 'https://api.github.com/repos/googleapis/google-api-nodejs-client/pulls', + data: { + title, + head: branch, + base: 'master', + }, + }); + } catch (e) { + console.error(e); + } finally { + await execa('git', ['checkout', 'master']); + } + } +} + +main().catch(err => { + console.error(err); + process.exit(2); +}); diff --git a/synth.py b/synth.py index f36a3d5c3b..d600f641c3 100644 --- a/synth.py +++ b/synth.py @@ -13,10 +13,8 @@ # limitations under the License. import synthtool as s -import synthtool.log as log -import synthtool.shell as shell -import synthtool.sources.git as git import synthtool.gcp as gcp +import subprocess import logging logging.basicConfig(level=logging.DEBUG) @@ -26,11 +24,6 @@ templates = common_templates.node_library() s.copy(templates, excludes=[".github/CONTRIBUTING.md", "README.md"]) -# repository_url = "https://github.com/googleapis/google-api-nodejs-client.git" -# log.debug(f"Cloning {repository_url}.") -# repository = git.clone(repository_url, depth=1) -# log.debug("Installing dependencies.") -# shell.run(["npm", "install"], cwd=repository) -# log.debug("Generating all libraries...") -# shell.run(["npm", "run", "generate"], cwd=repository) -# s.copy(repository / "src") +subprocess.run(["npm", "install"]) +subprocess.run(["npm", "run", "generate"]) +subprocess.run(["npm", "run", "submit-prs"]) From b84a3ab3e2959f08fc1c8980cacf02af1e7d3878 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Tue, 14 Jan 2020 18:44:15 -0800 Subject: [PATCH 2/3] github actions maybe --- .github/workflows/generator.yaml | 17 +++++++++++++++++ synth.py | 4 ---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/generator.yaml diff --git a/.github/workflows/generator.yaml b/.github/workflows/generator.yaml new file mode 100644 index 0000000000..0e923e77d2 --- /dev/null +++ b/.github/workflows/generator.yaml @@ -0,0 +1,17 @@ +name: generator +on: + schedule: + - cron: '0 4 * * *' +jobs: + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-node@v1 + with: + node-version: 12 + - run: npm install + - run: npm run generate + - run: npm run submit-prs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/synth.py b/synth.py index d600f641c3..610a147c02 100644 --- a/synth.py +++ b/synth.py @@ -23,7 +23,3 @@ common_templates = gcp.CommonTemplates() templates = common_templates.node_library() s.copy(templates, excludes=[".github/CONTRIBUTING.md", "README.md"]) - -subprocess.run(["npm", "install"]) -subprocess.run(["npm", "run", "generate"]) -subprocess.run(["npm", "run", "submit-prs"]) From f121b0e6e52319a3059f073c77798103a00d5c76 Mon Sep 17 00:00:00 2001 From: Justin Beckwith Date: Fri, 28 Feb 2020 08:17:47 -0800 Subject: [PATCH 3/3] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 84631779ed..41bc3a8779 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "postgenerate": "npm run fix", "docs-test": "linkinator docs", "predocs-test": "npm run docs", - "submit-prs": "node build/src/generator/synth.js" + "submit-prs": "node build/src/generator/synth.js", "prelint": "cd samples; npm link ../; npm i" }, "author": "Google Inc.",