-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from all commits
578dc66
9a57003
75f7e7f
5f8981e
f533de7
946d1fe
fe5c455
4696f68
67930c2
ba46775
9d50d40
76bf589
78c2f51
9cbd57e
46adf76
7417745
3e15ebc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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 | ||
davidcavazos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a bit more context around this. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
davidcavazos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
davidcavazos marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.