diff --git a/.github/config/nodejs-prod.jsonc b/.github/config/nodejs.jsonc similarity index 100% rename from .github/config/nodejs-prod.jsonc rename to .github/config/nodejs.jsonc diff --git a/.github/workflows/custard-ci-dev.yaml b/.github/workflows/custard-ci-dev.yaml index 7f4c40641e..e309fa73d9 100644 --- a/.github/workflows/custard-ci-dev.yaml +++ b/.github/workflows/custard-ci-dev.yaml @@ -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: diff --git a/.github/workflows/custard-ci.yaml b/.github/workflows/custard-ci.yaml index 2e85d1218c..27ff2ed57e 100644 --- a/.github/workflows/custard-ci.yaml +++ b/.github/workflows/custard-ci.yaml @@ -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: @@ -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 @@ -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 diff --git a/.github/workflows/custard-run-dev.yaml b/.github/workflows/custard-run-dev.yaml new file mode 100644 index 0000000000..5955ff5372 --- /dev/null +++ b/.github/workflows/custard-run-dev.yaml @@ -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/affected.yaml@v0.2.3 + 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: kokoro-system-test@long-door-651.iam.gserviceaccount.com + steps: + - name: Check queued + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/create-check@v0.2.3 + 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/setup-custard@v0.2.3 + 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/update-check@v0.2.3 + 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/update-check@v0.2.3 + with: + check: ${{ steps.in_progress.outputs.check }} + status: success + - name: Check failure + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/update-check@v0.2.3 + 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/update-check@v0.2.3 + with: + check: ${{ needs.affected.outputs.check }} + status: success diff --git a/.github/workflows/custard-run.yaml b/.github/workflows/custard-run.yaml new file mode 100644 index 0000000000..9e5a89f87c --- /dev/null +++ b/.github/workflows/custard-run.yaml @@ -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 + +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: + # # https://crontab.guru/#0_12_*_*_0 + # - cron: 0 12 * * 0 # At 12:00 on Sunday + +jobs: + affected: + uses: GoogleCloudPlatform/cloud-samples-tools/.github/workflows/affected.yaml@v0.2.3 + 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/create-check@v0.2.3 + 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/map-run@v0.2.3 + with: + command: npx gts lint + paths: ${{ needs.affected.outputs.paths }} + - name: Check success + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/update-check@v0.2.3 + with: + check: ${{ steps.in_progress.outputs.check }} + status: success + - name: Check failure + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/update-check@v0.2.3 + 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: kokoro-system-test@long-door-651.iam.gserviceaccount.com + steps: + - name: Check queued + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/create-check@v0.2.3 + 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/setup-custard@v0.2.3 + 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/update-check@v0.2.3 + 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/update-check@v0.2.3 + with: + check: ${{ steps.in_progress.outputs.check }} + status: success + - name: Check failure + uses: GoogleCloudPlatform/cloud-samples-tools/actions/steps/update-check@v0.2.3 + 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/update-check@v0.2.3 + with: + check: ${{ needs.affected.outputs.check }} + status: success