Skip to content
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

build: auto-run generation and submit prs #1905

Merged
merged 6 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
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
17 changes: 17 additions & 0 deletions .github/workflows/generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: generator
on:
schedule:
- cron: '0 4 * * *'
jobs:
JustinBeckwith marked this conversation as resolved.
Show resolved Hide resolved
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 }}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"postgenerate": "npm run fix",
"docs-test": "linkinator docs",
"predocs-test": "npm run docs",
"submit-prs": "node build/src/generator/synth.js",
"prelint": "cd samples; npm link ../; npm i"
},
"author": "Google Inc.",
Expand Down
68 changes: 68 additions & 0 deletions src/generator/synth.ts
Original file line number Diff line number Diff line change
@@ -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);
});
13 changes: 1 addition & 12 deletions synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,12 +23,3 @@
common_templates = gcp.CommonTemplates()
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")