Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ Note: Before submitting a pull request, please open an issue for discussion if y
- [ ] I have followed guidelines from [CONTRIBUTING.MD](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md) and [Samples Style Guide](https://googlecloudplatform.github.io/samples-style-guide/)
- [ ] **Tests** pass: `npm test` (see [Testing](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md#run-the-tests-for-a-single-sample))
- [ ] **Lint** pass: `npm run lint` (see [Style](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md#style))
- [ ] **Required CI tests** pass (see [CI testing](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md#ci-testing))
- [ ] These samples need a new **API enabled** in testing projects to pass (let us know which ones)
- [ ] These samples need a new/updated **env vars** in testing projects set to pass (let us know which ones)
- [ ] This pull request is from a branch created directly off of `GoogleCloudPlatform/nodejs-docs-samples`. Not a fork.
- [ ] This sample adds a new sample directory, and I updated the [CODEOWNERS file](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CODEOWNERS) with the codeowners for this sample
- [ ] This sample adds a new sample directory, and I created [GitHub Actions workflow](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md#adding-new-samples) for this sample
- [ ] This sample adds a new **Product API**, and I updated the [Blunderbuss issue/PR auto-assigner](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/.github/blunderbuss.yml) with the codeowners for this sample
- [ ] Please **merge** this PR for me once it is approved

> **Note**: Any check with `(dev)`, `(experimental)`, or `(legacy)` can be ignored and should **not block** your PR from merging (see [CI testing](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/CONTRIBUTING.md#ci-testing)).
7 changes: 4 additions & 3 deletions .github/workflows/custard-ci-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: Custard CI (dev)
name: (legacy dev) Custard CI
on:
push:
branches:
Expand All @@ -27,41 +27,42 @@

jobs:
affected:
name: Finding affected tests
name: (legacy) Finding affected tests
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
nodejs-paths: ${{ steps.nodejs.outputs.paths }}
nodejs-setups: ${{ steps.nodejs.outputs.setups }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: GoogleCloudPlatform/cloud-samples-tools
ref: v0.3.2
path: cloud-samples-tools
- name: Create `bin` directory for cloud-samples-tools binaries
run: mkdir bin
working-directory: cloud-samples-tools
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build Custard (from cloud-samples-tools)
run: go build -o ../bin -v ./...
working-directory: cloud-samples-tools/custard
- name: Get diffs
run: git --no-pager diff --name-only HEAD origin/main | tee diffs.txt
- name: Find Node.js affected packages
id: nodejs
run: |
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs-dev.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
cat paths.txt
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs-dev.jsonc paths.txt)" >> $GITHUB_OUTPUT

nodejs-test:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
name: test
if: github.event.pull_request && github.event.pull_request.head.repo.fork == false
name: (legacy) test
needs: affected
runs-on: ubuntu-latest
timeout-minutes: 120 # 2 hours hard limit
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/custard-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# IMPORTANT: DO NOT CHANGE THE NAME OF THIS WORKFLOW!
# The workflow named "Custard CI" triggers both custard-run.yaml and custard-run-dev.yaml.
# TODO: To sunset old tests remove `affected`, `lint`, and `test` jobs (only keep `region-tags`).
name: Custard CI
on:
push:
Expand All @@ -28,40 +31,40 @@
# TODO: remove all jobs except region-tags (should be tested by custard-run workflows)
jobs:
affected:
name: Finding affected tests
name: (legacy) Finding affected tests
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
nodejs-paths: ${{ steps.nodejs.outputs.paths }}
nodejs-setups: ${{ steps.nodejs.outputs.setups }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
fetch-depth: 0
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
with:
repository: GoogleCloudPlatform/cloud-samples-tools
ref: v0.3.2
path: cloud-samples-tools
- name: Create `bin` directory for cloud-samples-tools binaries
run: mkdir bin
working-directory: cloud-samples-tools
- uses: actions/setup-go@0aaccfd150d50ccaeb58ebd88d36e91967a5f35b # v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Build Custard (from cloud-samples-tools)
run: go build -o ../bin -v ./...
working-directory: cloud-samples-tools/custard
- name: Get diffs
run: git --no-pager diff --name-only HEAD origin/main | tee diffs.txt
- name: Find Node.js affected packages
id: nodejs
run: |
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
cat paths.txt
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs.jsonc paths.txt)" >> $GITHUB_OUTPUT

lint:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
needs: affected
runs-on: ubuntu-latest
timeout-minutes: 5
Expand Down Expand Up @@ -119,6 +122,8 @@
- run: ./.github/workflows/utils/region-tags-tests.sh

test:
if: github.event.pull_request && github.event.pull_request.head.repo.fork == false
name: (legacy) test
needs: affected
runs-on: ubuntu-latest
timeout-minutes: 120 # 2 hours hard limit
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/custard-run-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: (experimental / dev) Custard run
name: (dev) Custard run

on:
# Run tests when a pull request is created or updated.
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
head-sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
config-file: .github/config/nodejs-dev.jsonc
paths: ${{ (inputs.run-all && '.') || inputs.paths || '' }}
check-name: (experimental / dev) Custard CI
check-name: (dev) Custard CI / tests
create-check-if: ${{ !!github.event.workflow_run }}

test:
Expand All @@ -77,7 +77,7 @@ jobs:
id: queued
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
name: (experimental / dev) Custard CI / ${{ github.job }} (${{ matrix.path }})
name: (dev) Custard CI / ${{ github.job }} (${{ matrix.path }})
job-name: ${{ github.job }} (${{ matrix.path }})
if: ${{ !!github.event.workflow_run }}
- name: Checkout
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/custard-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

name: (experimental) Custard run
name: Custard run

on:
# Run tests when a pull request is created or updated.
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
head-sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
config-file: .github/config/nodejs.jsonc
paths: ${{ (inputs.run-all && '.') || inputs.paths || '' }}
check-name: (experimental) Custard CI
check-name: Custard CI / tests
create-check-if: ${{ !!github.event.workflow_run }}

lint:
Expand All @@ -73,7 +73,7 @@ jobs:
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
status: in_progress
name: (experimental) Custard CI / ${{ github.job }}
name: Custard CI / ${{ github.job }}
if: ${{ !!github.event.workflow_run }}
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
id: queued
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
name: (experimental) Custard CI / ${{ github.job }} (${{ matrix.path }})
name: Custard CI / ${{ github.job }} (${{ matrix.path }})
job-name: ${{ github.job }} (${{ matrix.path }})
if: ${{ !!github.event.workflow_run }}
- name: Checkout
Expand Down
57 changes: 29 additions & 28 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,34 +64,35 @@ const assert = require('node:assert/strict');

### CI testing

For new samples, a GitHub Actions workflow should be created to run your tests
on the CI system:

1. Check that your new samples and sample tests are on a branch created directly from this repo `GoogleCloudPlatform/nodejs-docs-samples`. Not a fork.

1. Add an entry to
[.github/workflows/utils/workflows.json](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/blob/main/.github/workflows/utils/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. 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/utils/generate.js -s [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.
>
> Add a **build configuration file (`.cfg`)** for your samples in
> **[`.kokoro/`](https://github.com/GoogleCloudPlatform/nodejs-docs-samples/tree/main/.kokoro)**.
> Check existing config files for the right format.
>
> All tests need a corresponding job file outside of GitHub. If you are a
> Googler, please provide the CL alongside your PR. See the internal codelab for
> Kokoro for details. If you don't work at Google, the person reviewing your PR
> will create the job config for you.
> **tl;dr**: Any check with `(dev)`, `(experimental)`, or `(legacy)` can be ignored and should **not block** your PR from merging.

This repository uses the 🍮 **Custard CI** from
[`GoogleCloudPlatform/cloud-samples-tools`](https://github.com/GoogleCloudPlatform/cloud-samples-tools)
to set up and run tests.

First, it checks which files changed in a PR to find which packages were affected.
In this repo, a _package_ is defined as a directory containing a `package.json` file.

If a global file (not belonging to a package) is changed, all packages are marked as affected.
Global files are can contain repo-level configurations that could affect other packages.
Typically, contributors should only modify files in a package.

Only affected packages are linted and tested.
For tests, we use a
[matrix strategy](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow)
to generate isolated jobs for each affected test.

We're working to improve the testing infrastructure, while keeping tests stable.
This means you'll sometimes see some new experimental tests, you can generally ignore them.
Or two versions of one test running while we make sure the new version works well.

Here's a list of which tests are required and which ones you can ignore.
* `Custard CI / lint`: (**required**) runs only for affected packages
* `Custard CI / tests`: (**required**) this runs until all tests have finished
* `Custard CI / test (package)`: (**required**) runs only for affected packages
* `(dev) Custard CI / test (package)`: (_ignore_) this test has errors we're working on
* `(experimental) Custard CI / ...`: (_ignore_) this is a new unstable version
* `Custard CI / (legacy) ...`: (_ignore_) this is the old version running while we make sure the new one works

### TypeScript Support

Expand Down
Loading