|
| 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 | + id-token: write |
| 109 | + statuses: write |
| 110 | + strategy: |
| 111 | + fail-fast: false |
| 112 | + matrix: |
| 113 | + path: ${{ fromJson(needs.affected.outputs.paths) }} |
| 114 | + continue-on-error: true |
| 115 | + env: |
| 116 | + GOOGLE_SAMPLES_PROJECT: long-door-651 |
| 117 | + GOOGLE_SERVICE_ACCOUNT: [email protected] |
| 118 | + steps: |
| 119 | + - name: Check queued |
| 120 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 121 | + id: queued |
| 122 | + with: |
| 123 | + sha: ${{ github.event.workflow_run.head_sha || inputs.ref || github.sha }} |
| 124 | + name: (experimental) Custard CI / ${{ github.job }} (${{ matrix.path }}) |
| 125 | + job-name: ${{ github.job }} (${{ matrix.path }}) |
| 126 | + if: ${{ !!github.event.workflow_run }} |
| 127 | + - name: Setup Custard |
| 128 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 129 | + with: |
| 130 | + path: ${{ matrix.path }} |
| 131 | + ci-setup: ${{ toJson(fromJson(needs.affected.outputs.ci-setups)[matrix.path]) }} |
| 132 | + project-id: ${{ env.GOOGLE_SAMPLES_PROJECT }} |
| 133 | + workload-identity-provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider |
| 134 | + service-account: ${{ env.GOOGLE_SERVICE_ACCOUNT }} |
| 135 | + - name: Check in_progress |
| 136 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 137 | + id: in_progress |
| 138 | + with: |
| 139 | + check: ${{ steps.queued.outputs.check }} |
| 140 | + status: in_progress |
| 141 | + - name: Run tests for ${{ matrix.path }} |
| 142 | + run: | |
| 143 | + timeout ${{ fromJson(needs.affected.outputs.ci-setups)[matrix.path].timeout-minutes }}m \ |
| 144 | + make test dir=${{ matrix.path }} |
| 145 | + - name: Check success |
| 146 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 147 | + with: |
| 148 | + check: ${{ steps.in_progress.outputs.check }} |
| 149 | + status: success |
| 150 | + - name: Check failure |
| 151 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 152 | + if: failure() |
| 153 | + with: |
| 154 | + check: ${{ steps.in_progress.outputs.check }} |
| 155 | + status: failure |
| 156 | + |
| 157 | + done: |
| 158 | + needs: [affected, lint, test] |
| 159 | + if: always() |
| 160 | + runs-on: ubuntu-latest |
| 161 | + permissions: |
| 162 | + statuses: write |
| 163 | + steps: |
| 164 | + - name: Check success |
| 165 | + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/[email protected] |
| 166 | + with: |
| 167 | + check: ${{ needs.affected.outputs.check }} |
| 168 | + status: success |
0 commit comments