Skip to content

Commit 0e0c99b

Browse files
authored
feat: support testing on forked repos (#4057)
* feat: support testing on forked repos * add pull_request to test on PR * remove prod suffix * decode json on matrix paths * add experimental to check names * add experimental to job names * run test only if paths is not empty * test explicitly against empty array * move experimental as a prefix * success check if no paths are found * always set check to done * remove pull_request trigger * rearrange if check * add more comments
1 parent 9d14925 commit 0e0c99b

File tree

5 files changed

+309
-4
lines changed

5 files changed

+309
-4
lines changed
File renamed without changes.

.github/workflows/custard-ci-dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: custard CI (dev)
15+
name: Custard CI (dev)
1616
on:
1717
push:
1818
branches:

.github/workflows/custard-ci.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
name: custard CI
15+
name: Custard CI
1616
on:
1717
push:
1818
branches:
@@ -25,6 +25,7 @@ on:
2525
env:
2626
GO_VERSION: ^1.22.0
2727

28+
# TODO: remove all jobs except region-tags (should be tested by custard-run workflows)
2829
jobs:
2930
affected:
3031
name: Finding affected tests
@@ -56,9 +57,9 @@ jobs:
5657
- name: Find Node.js affected packages
5758
id: nodejs
5859
run: |
59-
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs-prod.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
60+
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
6061
cat paths.txt
61-
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs-prod.jsonc paths.txt)" >> $GITHUB_OUTPUT
62+
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs.jsonc paths.txt)" >> $GITHUB_OUTPUT
6263
6364
lint:
6465
needs: affected
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: (experimental / dev) Custard run
16+
17+
on:
18+
# Run tests when a pull request is created or updated.
19+
# This allows to run tests from forked repos (after reviewer's approval).
20+
workflow_run:
21+
workflows:
22+
- Custard CI # .github/workflows/custard-ci.yaml
23+
types:
24+
- in_progress
25+
26+
# Run tests again as validation when a PR merge into main.
27+
push:
28+
branches:
29+
- main
30+
31+
# To do manual runs through the Actions UI.
32+
workflow_dispatch:
33+
inputs:
34+
run-all:
35+
description: Run all tests
36+
type: boolean
37+
default: false
38+
paths:
39+
description: Comma separated packages to test
40+
type: string
41+
ref:
42+
description: Branch, tag, or commit SHA to run tests on
43+
type: string
44+
default: main
45+
46+
jobs:
47+
affected:
48+
uses: GoogleCloudPlatform/cloud-samples-tools/.github/workflows/[email protected]
49+
permissions:
50+
statuses: write
51+
with:
52+
head-sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
53+
config-file: .github/config/nodejs-dev.jsonc
54+
paths: ${{ (inputs.run-all && '.') || inputs.paths || '' }}
55+
check-name: (experimental / dev) Custard CI
56+
create-check-if: ${{ !!github.event.workflow_run }}
57+
58+
test:
59+
if: needs.affected.outputs.paths != '[]'
60+
needs: affected
61+
runs-on: ubuntu-latest
62+
timeout-minutes: 120 # 2 hours hard limit
63+
permissions:
64+
statuses: write
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
path: ${{ needs.affected.outputs.paths }}
69+
continue-on-error: true
70+
env:
71+
GOOGLE_SAMPLES_PROJECT: long-door-651
72+
GOOGLE_SERVICE_ACCOUNT: [email protected]
73+
steps:
74+
- name: Check queued
75+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
76+
id: queued
77+
with:
78+
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
79+
name: (experimental / dev) Custard CI / ${{ github.job }} (${{ matrix.path }})
80+
job-name: ${{ github.job }} (${{ matrix.path }})
81+
if: ${{ !!github.event.workflow_run }}
82+
- name: Setup Custard
83+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
84+
with:
85+
path: ${{ matrix.path }}
86+
ci-setup: ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }}
87+
project-id: ${{ env.GOOGLE_SAMPLES_PROJECT }}
88+
workload-identity-provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
89+
service-account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
90+
- name: Check in_progress
91+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
92+
id: in_progress
93+
with:
94+
check: ${{ steps.queued.outputs.check }}
95+
status: in_progress
96+
- name: Run tests for ${{ matrix.path }}
97+
run: |
98+
timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].timeout-minutes }}m \
99+
make test dir=${{ matrix.path }}
100+
- name: Check success
101+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
102+
with:
103+
check: ${{ steps.in_progress.outputs.check }}
104+
status: success
105+
- name: Check failure
106+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
107+
if: failure()
108+
with:
109+
check: ${{ steps.in_progress.outputs.check }}
110+
status: failure
111+
# - name: Upload test results for FlakyBot workflow
112+
# if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
113+
# uses: actions/upload-artifact@v4
114+
# with:
115+
# name: test-results
116+
# path: ${{ matrix.path }}/${{ github.run_id }}_sponge_log.xml
117+
# retention-days: 1
118+
119+
done:
120+
needs: [affected, test]
121+
if: always()
122+
runs-on: ubuntu-latest
123+
permissions:
124+
statuses: write
125+
steps:
126+
- name: Check success
127+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
128+
with:
129+
check: ${{ needs.affected.outputs.check }}
130+
status: success

.github/workflows/custard-run.yaml

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: (experimental) Custard run
16+
17+
on:
18+
# Run tests when a pull request is created or updated.
19+
# This allows to run tests from forked repos (after reviewer's approval).
20+
workflow_run:
21+
workflows:
22+
- Custard CI # .github/workflows/custard-ci.yaml
23+
types:
24+
- in_progress
25+
26+
# Run tests again as validation when a PR merge into main.
27+
push:
28+
branches:
29+
- main
30+
31+
# To do manual runs through the Actions UI.
32+
workflow_dispatch:
33+
inputs:
34+
run-all:
35+
description: Run all tests
36+
type: boolean
37+
default: false
38+
paths:
39+
description: Comma separated packages to test
40+
type: string
41+
ref:
42+
description: Branch, tag, or commit SHA to run tests on
43+
type: string
44+
default: main
45+
46+
# For nightly tests.
47+
# schedule:
48+
# # https://crontab.guru/#0_12_*_*_0
49+
# - cron: 0 12 * * 0 # At 12:00 on Sunday
50+
51+
jobs:
52+
affected:
53+
uses: GoogleCloudPlatform/cloud-samples-tools/.github/workflows/[email protected]
54+
permissions:
55+
statuses: write
56+
with:
57+
head-sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
58+
config-file: .github/config/nodejs.jsonc
59+
paths: ${{ (inputs.run-all && '.') || inputs.paths || '' }}
60+
check-name: (experimental) Custard CI
61+
create-check-if: ${{ !!github.event.workflow_run }}
62+
63+
lint:
64+
needs: affected
65+
runs-on: ubuntu-latest
66+
permissions:
67+
statuses: write
68+
timeout-minutes: 5
69+
steps:
70+
- name: Check in_progress
71+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
72+
id: in_progress
73+
with:
74+
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
75+
status: in_progress
76+
name: (experimental) Custard CI / ${{ github.job }}
77+
if: ${{ !!github.event.workflow_run }}
78+
- name: Checkout
79+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
80+
- name: Setup Node
81+
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
82+
with:
83+
node-version: 20
84+
- run: npm install
85+
- name: npx gtx lint (${{ needs.affected.outputs.num-paths }} packages)
86+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
87+
with:
88+
command: npx gts lint
89+
paths: ${{ needs.affected.outputs.paths }}
90+
- name: Check success
91+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
92+
with:
93+
check: ${{ steps.in_progress.outputs.check }}
94+
status: success
95+
- name: Check failure
96+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
97+
if: failure()
98+
with:
99+
check: ${{ steps.in_progress.outputs.check }}
100+
status: failure
101+
102+
test:
103+
if: needs.affected.outputs.paths != '[]'
104+
needs: affected
105+
runs-on: ubuntu-latest
106+
timeout-minutes: 120 # 2 hours hard limit
107+
permissions:
108+
statuses: write
109+
strategy:
110+
fail-fast: false
111+
matrix:
112+
path: ${{ fromJson(needs.affected.outputs.paths) }}
113+
continue-on-error: true
114+
env:
115+
GOOGLE_SAMPLES_PROJECT: long-door-651
116+
GOOGLE_SERVICE_ACCOUNT: [email protected]
117+
steps:
118+
- name: Check queued
119+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
120+
id: queued
121+
with:
122+
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
123+
name: (experimental) Custard CI / ${{ github.job }} (${{ matrix.path }})
124+
job-name: ${{ github.job }} (${{ matrix.path }})
125+
if: ${{ !!github.event.workflow_run }}
126+
- name: Setup Custard
127+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
128+
with:
129+
path: ${{ matrix.path }}
130+
ci-setup: ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }}
131+
project-id: ${{ env.GOOGLE_SAMPLES_PROJECT }}
132+
workload-identity-provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
133+
service-account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
134+
- name: Check in_progress
135+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
136+
id: in_progress
137+
with:
138+
check: ${{ steps.queued.outputs.check }}
139+
status: in_progress
140+
- name: Run tests for ${{ matrix.path }}
141+
run: |
142+
timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].timeout-minutes }}m \
143+
make test dir=${{ matrix.path }}
144+
- name: Check success
145+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
146+
with:
147+
check: ${{ steps.in_progress.outputs.check }}
148+
status: success
149+
- name: Check failure
150+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
151+
if: failure()
152+
with:
153+
check: ${{ steps.in_progress.outputs.check }}
154+
status: failure
155+
# - name: Upload test results for FlakyBot workflow
156+
# if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
157+
# uses: actions/upload-artifact@v4
158+
# with:
159+
# name: test-results
160+
# path: ${{ matrix.path }}/${{ github.run_id }}_sponge_log.xml
161+
# retention-days: 1
162+
163+
done:
164+
needs: [affected, lint, test]
165+
if: always()
166+
runs-on: ubuntu-latest
167+
permissions:
168+
statuses: write
169+
steps:
170+
- name: Check success
171+
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
172+
with:
173+
check: ${{ needs.affected.outputs.check }}
174+
status: success

0 commit comments

Comments
 (0)