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

ci: add option to generate one workflow #2822

Merged
merged 4 commits into from
Nov 10, 2022
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
16 changes: 11 additions & 5 deletions .github/workflows/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ const fs = require('fs').promises;

async function main() {
nunjucks.configure('.github/workflows', {autoescape: true});

// Optional filter to generate one workflow
const specificWorkflowPath = process.argv.slice(2)[0];

for (const workflow of workflows) {
const path = workflow;
const name = workflow.split('/').join('-');
const suite = name.split('-').join('_');
const data = nunjucks.render('ci.yaml.njk', {path, name, suite});
await fs.writeFile(`.github/workflows/${name}.yaml`, data);
if (!specificWorkflowPath || specificWorkflowPath === workflow) {
const path = workflow;
const name = workflow.split('/').join('-');
const suite = name.split('-').join('_');
const data = nunjucks.render('ci.yaml.njk', {path, name, suite});
await fs.writeFile(`.github/workflows/${name}.yaml`, data);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ For new samples, a GitHub Actions workflow should be created to run your tests o

1. Add an entry to [.github/workflows/workflows.json](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/.github/workflows/workflows.json) matching the directory with your sample code.

1. From the root of the repo, generate a new workflow in the [workflows](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/.github/workflows) directory:
1. From the root of the repo, generate a new workflow in the [workflows](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/.github/workflows) directory. You can specify a `path` to only generate the specific workflow, e.g. `cloud-tasks`. If the path is omitted, all workflows will be generated.

node .github/workflows/generate.js
node .github/workflows/generate.js [path]

> **Note**
> There are some existing samples that use an alternative CI system. It is recommended to use GitHub Actions for new samples, but these instructions are provided below for your reference.
Expand Down