docs: document setup files (#3996) #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: CI (experimental) | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
# schedule: | |
# # https://crontab.guru/#0_12_*_*_0 | |
# - cron: 0 12 * * 0 # At 12:00 on Sunday | |
env: | |
GO_VERSION: ^1.22.0 | |
jobs: | |
affected: | |
name: Finding affected tests | |
runs-on: ubuntu-latest | |
timeout-minutes: 2 | |
outputs: | |
nodejs-paths: ${{ steps.nodejs.outputs.paths }} | |
nodejs-setups: ${{ steps.nodejs.outputs.setups }} | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
fetch-depth: 0 | |
- uses: actions/checkout@v4 | |
with: | |
repository: GoogleCloudPlatform/cloud-samples-tools | |
ref: v0.2.1 | |
path: cloud-samples-tools | |
- name: Create `bin` directory for cloud-samples-tools binaries | |
run: mkdir bin | |
working-directory: cloud-samples-tools | |
- uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Build Custard (from cloud-samples-tools) | |
run: go build -o ../bin -v ./... | |
working-directory: cloud-samples-tools/custard | |
- name: Get diffs | |
run: git --no-pager diff --name-only HEAD origin/main | tee diffs.txt | |
- name: Find Node.js affected packages | |
id: nodejs | |
run: | | |
echo "paths=$(./cloud-samples-tools/bin/custard affected .github/config/nodejs-dev.jsonc diffs.txt paths.txt)" >> $GITHUB_OUTPUT | |
cat paths.txt | |
echo "setups=$(./cloud-samples-tools/bin/custard setup-files .github/config/nodejs-dev.jsonc paths.txt)" >> $GITHUB_OUTPUT | |
nodejs-test: | |
name: Node.js test | |
needs: affected | |
runs-on: ubuntu-latest | |
timeout-minutes: 120 # 2 hours hard limit | |
permissions: | |
id-token: write # needed for google-github-actions/auth | |
strategy: | |
fail-fast: false | |
matrix: | |
path: ${{ fromJson(github.event_name == 'pull_request' && needs.affected.outputs.nodejs-paths || '[]') }} | |
env: | |
GOOGLE_SAMPLES_PROJECT: long-door-651 | |
CI_SETUP: ${{ toJson(fromJson(needs.affected.outputs.nodejs-setups)[matrix.path])}} | |
steps: | |
- name: CI Setup | |
run: echo "${{ env.CI_SETUP }}" | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- uses: actions/setup-node@1d0ff469b7ec7b3cb9d8673fde0c81c44821de2a # v4 | |
with: | |
node-version: ${{ fromJson(env.CI_SETUP).node-version }} | |
- uses: google-github-actions/auth@6fc4af4b145ae7821d527454aa9bd537d1f2dc5f # v2 | |
with: | |
project_id: ${{ env.GOOGLE_SAMPLES_PROJECT }} | |
workload_identity_provider: projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider | |
service_account: [email protected] | |
access_token_lifetime: 600s # 10 minutes | |
- name: Export environment variables | |
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7 | |
id: vars | |
with: | |
script: | | |
const { default: setupVars } = await import('${{ github.workspace }}/.github/scripts/setup-vars.js') | |
const projectId = '${{ env.GOOGLE_SAMPLES_PROJECT }}'; | |
const setup = JSON.parse(process.env.CI_SETUP); | |
return await setupVars({projectId, core, setup}) | |
- uses: google-github-actions/get-secretmanager-secrets@e5bb06c2ca53b244f978d33348d18317a7f263ce # v2 | |
if: ${{ fromJson(steps.vars.outputs.result).secrets }} | |
with: | |
secrets: ${{ fromJson(steps.vars.outputs.result).secrets }} | |
export_to_environment: true | |
- name: 🛠️ Test ${{ matrix.path }} | |
run: | | |
timeout ${{ fromJson(env.CI_SETUP).timeout-minutes }}m \ | |
make test dir=${{ matrix.path }} |