|
| 1 | +name: GCP Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - 'modules/gcp/**' |
| 8 | + - 'test/gcp/**' |
| 9 | + - 'go.mod' |
| 10 | + - 'go.sum' |
| 11 | + pull_request: |
| 12 | + paths: |
| 13 | + - 'modules/gcp/**' |
| 14 | + - 'test/gcp/**' |
| 15 | + - 'go.mod' |
| 16 | + - 'go.sum' |
| 17 | + workflow_dispatch: |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: read |
| 21 | + |
| 22 | +jobs: |
| 23 | + test: |
| 24 | + name: GCP Tests |
| 25 | + # Skip PRs from forks — repo secrets aren't exposed there, so auth would fail. |
| 26 | + if: >- |
| 27 | + github.event_name != 'pull_request' || |
| 28 | + github.event.pull_request.head.repo.full_name == github.repository |
| 29 | + runs-on: ubuntu-latest |
| 30 | + timeout-minutes: 90 |
| 31 | + |
| 32 | + env: |
| 33 | + # GOOGLE_CLOUD_PROJECT is the env var that the GCP provider helper |
| 34 | + # (gcp.GetGoogleProjectIDFromEnvVar) actually reads. |
| 35 | + GOOGLE_CLOUD_PROJECT: ${{ vars.GOOGLE_CLOUD_PROJECT }} |
| 36 | + # GOOGLE_COMPUTE_ZONE is consumed by the gcloud config step below. |
| 37 | + GOOGLE_COMPUTE_ZONE: ${{ vars.GOOGLE_COMPUTE_ZONE }} |
| 38 | + # GOOGLE_IDENTITY_EMAIL is required by the oslogin and static_token tests. |
| 39 | + GOOGLE_IDENTITY_EMAIL: ${{ vars.GOOGLE_IDENTITY_EMAIL }} |
| 40 | + |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + |
| 44 | + - name: Install mise |
| 45 | + uses: jdx/mise-action@v3 |
| 46 | + with: |
| 47 | + version: 2025.12.10 |
| 48 | + experimental: true |
| 49 | + env: |
| 50 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Go module cache |
| 53 | + uses: actions/cache@v4 |
| 54 | + with: |
| 55 | + path: | |
| 56 | + ~/go/pkg/mod |
| 57 | + ~/.cache/go-build |
| 58 | + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} |
| 59 | + restore-keys: | |
| 60 | + ${{ runner.os }}-go- |
| 61 | +
|
| 62 | + - name: Authenticate to Google Cloud |
| 63 | + uses: google-github-actions/auth@v2 |
| 64 | + with: |
| 65 | + credentials_json: ${{ secrets.GCLOUD_SERVICE_KEY }} |
| 66 | + |
| 67 | + - name: Set up gcloud CLI |
| 68 | + uses: google-github-actions/setup-gcloud@v2 |
| 69 | + with: |
| 70 | + project_id: ${{ vars.GOOGLE_CLOUD_PROJECT }} |
| 71 | + |
| 72 | + - name: Configure gcloud defaults |
| 73 | + run: | |
| 74 | + gcloud --quiet config set project "$GOOGLE_CLOUD_PROJECT" |
| 75 | + gcloud --quiet config set compute/zone "$GOOGLE_COMPUTE_ZONE" |
| 76 | +
|
| 77 | + - name: Download Go modules |
| 78 | + run: go mod download |
| 79 | + |
| 80 | + - name: Build GCP module |
| 81 | + run: go build ./modules/gcp/... |
| 82 | + |
| 83 | + - name: Compile GCP module tests |
| 84 | + run: go test -tags gcp -c -o /dev/null ./modules/gcp/... |
| 85 | + |
| 86 | + - name: Compile GCP integration tests |
| 87 | + run: go test -tags gcp -c -o /dev/null ./test/gcp/... |
| 88 | + |
| 89 | + - name: Run GCP module tests |
| 90 | + run: | |
| 91 | + mkdir -p /tmp/logs |
| 92 | + go test -v -count=1 -timeout 30m -tags gcp ./modules/gcp/... 2>&1 | tee /tmp/logs/gcp-module-tests.log |
| 93 | +
|
| 94 | + - name: Run GCP integration tests |
| 95 | + run: | |
| 96 | + go test -v -count=1 -timeout 45m -tags gcp ./test/gcp/... 2>&1 | tee /tmp/logs/gcp-integration-tests.log |
| 97 | +
|
| 98 | + - name: Upload test logs |
| 99 | + if: always() |
| 100 | + uses: actions/upload-artifact@v4 |
| 101 | + with: |
| 102 | + name: gcp-test-logs |
| 103 | + path: /tmp/logs/ |
0 commit comments