Skip to content

Commit 1ef915e

Browse files
author
David Cavazos
committed
feat: support testing on forked repos
1 parent fd6ec65 commit 1ef915e

2 files changed

Lines changed: 2 additions & 264 deletions

File tree

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

Lines changed: 0 additions & 116 deletions
This file was deleted.

.github/workflows/custard-ci.yaml

Lines changed: 2 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -12,100 +12,15 @@
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
16+
1617
on:
1718
push:
1819
branches:
1920
- main
2021
pull_request:
21-
# schedule:
22-
# # https://crontab.guru/#0_12_*_*_0
23-
# - cron: 0 12 * * 0 # At 12:00 on Sunday
24-
25-
env:
26-
GO_VERSION: ^1.22.0
2722

2823
jobs:
29-
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
62-
63-
lint:
64-
needs: affected
65-
runs-on: ubuntu-latest
66-
timeout-minutes: 5
67-
steps:
68-
- name: Checkout
69-
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
70-
- name: Setup Node
71-
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
72-
with:
73-
node-version: 20
74-
- run: npm install
75-
- name: Run lint
76-
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
77-
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-
}
108-
10924
region-tags:
11025
name: region tags
11126
runs-on: ubuntu-latest
@@ -116,64 +31,3 @@ jobs:
11631
with:
11732
node-version: 20
11833
- run: ./.github/workflows/utils/region-tags-tests.sh
119-
120-
test:
121-
needs: affected
122-
runs-on: ubuntu-latest
123-
timeout-minutes: 120 # 2 hours hard limit
124-
permissions:
125-
id-token: write # needed for google-github-actions/auth
126-
strategy:
127-
fail-fast: false
128-
matrix:
129-
path: ${{ fromJson(github.event_name == 'pull_request' && needs.affected.outputs.nodejs-paths || '[]') }}
130-
env:
131-
GOOGLE_SAMPLES_PROJECT: long-door-651
132-
GOOGLE_SERVICE_ACCOUNT: kokoro-system-test@long-door-651.iam.gserviceaccount.com
133-
CI_SETUP: ${{ toJson(fromJson(needs.affected.outputs.nodejs-setups)[matrix.path])}}
134-
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
141-
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 }}
166-
with:
167-
secrets: ${{ fromJson(steps.vars.outputs.result).secrets }}
168-
export_to_environment: true
169-
- name: Run tests for ${{ matrix.path }}
170-
run: |
171-
timeout ${{ fromJson(env.CI_SETUP).timeout-minutes }}m \
172-
make test dir=${{ matrix.path }}
173-
# - name: Upload test results for FlakyBot workflow
174-
# if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
175-
# uses: actions/upload-artifact@v4
176-
# with:
177-
# name: test-results
178-
# path: ${{ matrix.package }}/${{ env.MOCHA_REPORTER_OUTPUT }}
179-
# retention-days: 1

0 commit comments

Comments
 (0)