2222 # # https://crontab.guru/#0_12_*_*_0
2323 # - cron: 0 12 * * 0 # At 12:00 on Sunday
2424
25- env :
26- GO_VERSION : ^1.22.0
27-
2825jobs :
2926 affected :
30- name : Finding affected tests
31- runs-on : ubuntu-latest
32- timeout-minutes : 2
33- outputs :
34- nodejs-paths : ${{ steps.nodejs.outputs.paths }}
35- nodejs-setups : ${{ steps.nodejs.outputs.setups }}
36- steps :
37- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
38- with :
39- fetch-depth : 0
40- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
41- with :
42- repository : GoogleCloudPlatform/cloud-samples-tools
43- ref : v0.2.1
44- path : cloud-samples-tools
45- - name : Create `bin` directory for cloud-samples-tools binaries
46- run : mkdir bin
47- working-directory : cloud-samples-tools
48- - uses : actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5
49- with :
50- go-version : ${{ env.GO_VERSION }}
51- - name : Build Custard (from cloud-samples-tools)
52- run : go build -o ../bin -v ./...
53- working-directory : cloud-samples-tools/custard
54- - name : Get diffs
55- run : git --no-pager diff --name-only HEAD origin/main | tee diffs.txt
56- - name : Find Node.js affected packages
57- id : nodejs
58- run : |
59- echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs-prod.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
60- cat paths.txt
61- echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs-prod.jsonc paths.txt)" >> $GITHUB_OUTPUT
27+ name : Find affected packages
28+ # TODO: use version tag when available
29+ uses : GoogleCloudPlatform/cloud-samples-tools/.github/workflows/find-affected.yaml@main
30+ with :
31+ config-file : .github/config/nodejs-prod.jsonc
32+ paths : tpu # TODO: remove this
6233
6334 lint :
6435 needs : affected
6536 runs-on : ubuntu-latest
66- timeout-minutes : 5
6737 steps :
6838 - name : Checkout
6939 uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
@@ -72,39 +42,12 @@ jobs:
7242 with :
7343 node-version : 20
7444 - run : npm install
75- - name : Run lint
76- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
45+ - name : Run linter
46+ # TODO: use version tag when available
47+ uses : GoogleCloudPlatform/cloud-samples-tools/.github/map-run@main
7748 with :
78- script : |
79- const { execSync } = await import("node:child_process");
80-
81- const cmd = 'npx gts lint';
82- const affected = ${{ needs.affected.outputs.nodejs-paths }};
83- if (affected.length === 0) {
84- console.log("No packages were affected, nothing to lint.")
85- }
86-
87- let failed = [];
88- for (const path of affected) {
89- try {
90- execSync(cmd, {cwd: path});
91- console.log(`✅ [${path}]: ${cmd}`);
92- } catch (e) {
93- failed.push(path)
94- console.log(`❌ [${path}]: ${cmd} (exit code ${e.status})`);
95- core.error(e.message);
96- console.log('--- stdout ---');
97- console.log(e.stdout.toString("utf8"));
98- console.log('--- stderr ---');
99- console.log(e.stderr.toString("utf8"));
100- }
101- }
102- console.log("=== Summary ===")
103- console.log(` Passed: ${affected.length - failed.length}`)
104- console.log(` Failed: ${failed.length}`)
105- if (failed.length > 0) {
106- core.setFailed(`Failed '${cmd}' on: ${failed.join(', ')}`)
107- }
49+ command : npx gts lint
50+ paths : ${{ needs.affected.outputs.paths }}
10851
10952 region-tags :
11053 name : region tags
@@ -122,53 +65,32 @@ jobs:
12265 runs-on : ubuntu-latest
12366 timeout-minutes : 120 # 2 hours hard limit
12467 permissions :
125- id-token : write # needed for google-github-actions/auth
68+ id-token : write # for google-github-actions/auth
12669 strategy :
12770 fail-fast : false
12871 matrix :
129- path : ${{ fromJson(github.event_name == 'pull_request' && needs.affected.outputs.nodejs- paths || '[]' ) }}
72+ path : ${{ fromJson(needs.affected.outputs.paths) }}
13073 env :
13174 GOOGLE_SAMPLES_PROJECT : long-door-651
13275 GOOGLE_SERVICE_ACCOUNT : kokoro-system-test@long-door-651.iam.gserviceaccount.com
133- CI_SETUP : ${{ toJson(fromJson(needs.affected.outputs.nodejs-setups)[matrix.path])}}
13476 steps :
135- - name : CI Setup
136- run : echo "${{ env.CI_SETUP }}"
137- - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
138- with :
139- ref : ${{ github.event.pull_request.head.sha }}
140- - uses : actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
77+ - name : Setup Custard
78+ # TODO: use version tag when available
79+ uses : GoogleCloudPlatform/cloud-samples-tools/.github/setup-custard@main
14180 with :
142- node-version : ${{ fromJson(env.CI_SETUP).node-version }}
143- - uses : google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2
144- id : auth
145- with :
146- project_id : ${{ env.GOOGLE_SAMPLES_PROJECT }}
147- workload_identity_provider : projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
148- service_account : ${{ env.GOOGLE_SERVICE_ACCOUNT }}
149- access_token_lifetime : 600s # 10 minutes
150- token_format : ' id_token'
151- id_token_audience : ' https://action.test/' # service must have this custom audience
152- id_token_include_email : true
153- - name : Export environment variables
154- uses : actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
155- id : vars
156- with :
157- script : |
158- const { default: setupVars } = await import('${{ github.workspace }}/.github/scripts/setup-vars.js');
159- const projectId = '${{ env.GOOGLE_SAMPLES_PROJECT }}';
160- const setup = JSON.parse(process.env.CI_SETUP);
161- const serviceAccount = '${{ env.GOOGLE_SERVICE_ACCOUNT }}';
162- const idToken = '${{ steps.auth.outputs.id_token }}';
163- return await setupVars({projectId, core, setup, serviceAccount, idToken})
164- - uses : google-github-actions/get-secretmanager-secrets@e5bb06c2ca53b244f978d33348d18317a7f263ce # v2
165- if : ${{ fromJson(steps.vars.outputs.result).secrets }}
81+ path : ${{ matrix.path }}
82+ ci-setup : ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }}
83+ project-id : ${{ env.GOOGLE_SAMPLES_PROJECT }}
84+ workload-identity-provider : projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
85+ service-account : ${{ env.GOOGLE_SERVICE_ACCOUNT }}
86+
87+ - name : Setup Node
88+ uses : actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
16689 with :
167- secrets : ${{ fromJson(steps.vars.outputs.result).secrets }}
168- export_to_environment : true
90+ node-version : ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].node-version }}
16991 - name : Run tests for ${{ matrix.path }}
17092 run : |
171- timeout ${{ fromJson(env.CI_SETUP) .timeout-minutes }}m \
93+ timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path] .timeout-minutes }}m \
17294 make test dir=${{ matrix.path }}
17395 # - name: Upload test results for FlakyBot workflow
17496 # if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
0 commit comments