Skip to content

feat: support testing on forked repos #4057

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

Merged
merged 17 commits into from
Apr 4, 2025
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
File renamed without changes.
2 changes: 1 addition & 1 deletion .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: Custard CI (dev)
on:
push:
branches:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/custard-ci.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
name: Custard CI
on:
push:
branches:
Expand All @@ -25,6 +25,7 @@ on:
env:
GO_VERSION: ^1.22.0

# TODO: remove all jobs except region-tags (should be tested by custard-run workflows)
jobs:
affected:
name: Finding affected tests
Expand Down Expand Up @@ -56,9 +57,9 @@ jobs:
- name: Find Node.js affected packages
id: nodejs
run: |
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs-prod.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT
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-prod.jsonc paths.txt)" >> $GITHUB_OUTPUT
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs.jsonc paths.txt)" >> $GITHUB_OUTPUT

lint:
needs: affected
Expand Down
130 changes: 130 additions & 0 deletions .github/workflows/custard-run-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: (experimental / dev) Custard run

on:
# Run tests when a pull request is created or updated.
# This allows to run tests from forked repos (after reviewer's approval).
workflow_run:
workflows:
- Custard CI # .github/workflows/custard-ci.yaml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, I don't understand this comment. Is it referencing that this workflow is related to the main ones. Or is it something that could be updated or just removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the workflow_run references workflows by name, not by filename. That comment is just the filename that contains that job name. For our own discoverability.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! I misunderstood. In that case... are the dev and prod versions of -run both running the same workflow by name then?

Copy link
Contributor Author

@davidcavazos davidcavazos Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, both are triggered by the same pull_request workflow.

types:
- in_progress

# Run tests again as validation when a PR merge into main.
push:
branches:
- main

# To do manual runs through the Actions UI.
workflow_dispatch:
inputs:
run-all:
description: Run all tests
type: boolean
default: false
paths:
description: Comma separated packages to test
type: string
ref:
description: Branch, tag, or commit SHA to run tests on
type: string
default: main

jobs:
affected:
uses: GoogleCloudPlatform/cloud-samples-tools/.github/workflows/[email protected]
permissions:
statuses: write
with:
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
create-check-if: ${{ !!github.event.workflow_run }}

test:
if: needs.affected.outputs.paths != '[]'
needs: affected
runs-on: ubuntu-latest
timeout-minutes: 120 # 2 hours hard limit
permissions:
statuses: write
strategy:
fail-fast: false
matrix:
path: ${{ needs.affected.outputs.paths }}
continue-on-error: true
env:
GOOGLE_SAMPLES_PROJECT: long-door-651
GOOGLE_SERVICE_ACCOUNT: [email protected]
steps:
- name: Check queued
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
id: queued
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
name: (experimental / dev) Custard CI / ${{ github.job }} (${{ matrix.path }})
job-name: ${{ github.job }} (${{ matrix.path }})
if: ${{ !!github.event.workflow_run }}
- name: Setup Custard
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
path: ${{ matrix.path }}
ci-setup: ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }}
project-id: ${{ env.GOOGLE_SAMPLES_PROJECT }}
workload-identity-provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
service-account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
- name: Check in_progress
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
id: in_progress
with:
check: ${{ steps.queued.outputs.check }}
status: in_progress
- name: Run tests for ${{ matrix.path }}
run: |
timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].timeout-minutes }}m \
make test dir=${{ matrix.path }}
- name: Check success
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
check: ${{ steps.in_progress.outputs.check }}
status: success
- name: Check failure
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
if: failure()
with:
check: ${{ steps.in_progress.outputs.check }}
status: failure
# - name: Upload test results for FlakyBot workflow
# if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
# uses: actions/upload-artifact@v4
# with:
# name: test-results
# path: ${{ matrix.path }}/${{ github.run_id }}_sponge_log.xml
# retention-days: 1

done:
needs: [affected, test]
if: always()
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Check success
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
check: ${{ needs.affected.outputs.check }}
status: success
174 changes: 174 additions & 0 deletions .github/workflows/custard-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: (experimental) Custard run
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to add a note or description (that would surface in the GH UI) or at least a code comment to let folks know that the purpose of the -run workflows are to "support to run tests on forked repos (after reviewer's approval)"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a bit more context around this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "Custard run" workflows are never visible from a PR, they're basically an implementation detail. That's why we're manually creating checks to reflect back on the PR. I added some comments on the purpose of every event trigger.


on:
# Run tests when a pull request is created or updated.
# This allows to run tests from forked repos (after reviewer's approval).
workflow_run:
workflows:
- Custard CI # .github/workflows/custard-ci.yaml
types:
- in_progress

# Run tests again as validation when a PR merge into main.
push:
branches:
- main

# To do manual runs through the Actions UI.
workflow_dispatch:
inputs:
run-all:
description: Run all tests
type: boolean
default: false
paths:
description: Comma separated packages to test
type: string
ref:
description: Branch, tag, or commit SHA to run tests on
type: string
default: main

# For nightly tests.
# schedule:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we ever want to schedule tests on forked runs? If not we could remove this comment.

Copy link
Contributor Author

@davidcavazos davidcavazos Apr 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The schedule runs from main always, not from forks. This would basically enable nightly tests. I haven't tested it yet so that's why it's commented out, but we eventually want to enable schedule for nightlies. There would be a special case handling on affected to run on everything if it's a schedule (rather than diffs).

# # https://crontab.guru/#0_12_*_*_0
# - cron: 0 12 * * 0 # At 12:00 on Sunday

jobs:
affected:
uses: GoogleCloudPlatform/cloud-samples-tools/.github/workflows/[email protected]
permissions:
statuses: write
with:
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
create-check-if: ${{ !!github.event.workflow_run }}

lint:
needs: affected
runs-on: ubuntu-latest
permissions:
statuses: write
timeout-minutes: 5
steps:
- name: Check in_progress
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may get an immediate renovate PR to bump all these versions to 0.2.4, but that might be a good follow up test for running tests from forks?

id: in_progress
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
status: in_progress
name: (experimental) Custard CI / ${{ github.job }}
if: ${{ !!github.event.workflow_run }}
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Setup Node
uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4
with:
node-version: 20
- run: npm install
- name: npx gtx lint (${{ needs.affected.outputs.num-paths }} packages)
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
command: npx gts lint
paths: ${{ needs.affected.outputs.paths }}
- name: Check success
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
check: ${{ steps.in_progress.outputs.check }}
status: success
- name: Check failure
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
if: failure()
with:
check: ${{ steps.in_progress.outputs.check }}
status: failure

test:
if: needs.affected.outputs.paths != '[]'
needs: affected
runs-on: ubuntu-latest
timeout-minutes: 120 # 2 hours hard limit
permissions:
statuses: write
strategy:
fail-fast: false
matrix:
path: ${{ fromJson(needs.affected.outputs.paths) }}
continue-on-error: true
env:
GOOGLE_SAMPLES_PROJECT: long-door-651
GOOGLE_SERVICE_ACCOUNT: [email protected]
steps:
- name: Check queued
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
id: queued
with:
sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }}
name: (experimental) Custard CI / ${{ github.job }} (${{ matrix.path }})
job-name: ${{ github.job }} (${{ matrix.path }})
if: ${{ !!github.event.workflow_run }}
- name: Setup Custard
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
path: ${{ matrix.path }}
ci-setup: ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }}
project-id: ${{ env.GOOGLE_SAMPLES_PROJECT }}
workload-identity-provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider
service-account: ${{ env.GOOGLE_SERVICE_ACCOUNT }}
- name: Check in_progress
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
id: in_progress
with:
check: ${{ steps.queued.outputs.check }}
status: in_progress
- name: Run tests for ${{ matrix.path }}
run: |
timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].timeout-minutes }}m \
make test dir=${{ matrix.path }}
- name: Check success
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
check: ${{ steps.in_progress.outputs.check }}
status: success
- name: Check failure
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
if: failure()
with:
check: ${{ steps.in_progress.outputs.check }}
status: failure
# - name: Upload test results for FlakyBot workflow
# if: github.event.action == 'schedule' && always() # always() submits logs even if tests fail
# uses: actions/upload-artifact@v4
# with:
# name: test-results
# path: ${{ matrix.path }}/${{ github.run_id }}_sponge_log.xml
# retention-days: 1

done:
needs: [affected, lint, test]
if: always()
runs-on: ubuntu-latest
permissions:
statuses: write
steps:
- name: Check success
uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected]
with:
check: ${{ needs.affected.outputs.check }}
status: success
Loading