tests #3895
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 2021 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: tests | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
schedule: | |
- cron: '0 2 * * *' | |
# Declare default permissions as read only. | |
permissions: read-all | |
jobs: | |
compilation: | |
name: FreeBSD and OpenBSD compilation check | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 | |
- name: Setup Go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | |
with: | |
go-version: "1.23" | |
cache: false | |
- name: Verify FreeBSD and OpenBSD Builds | |
run: | | |
CGO_ENABLED=0 GOOS=freebsd go build | |
CGO_ENABLED=0 GOOS=openbsd go build | |
integration: | |
runs-on: [self-hosted, linux, x64] | |
# run integration tests on all builds except pull requests from forks or | |
# dependabot | |
if: | | |
github.event_name != 'pull_request' || | |
(github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') | |
name: "integration tests (linux)" | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
issues: write | |
pull-requests: write | |
steps: | |
# This helps understand how much disk space the cache and custom runner | |
# is actually using. | |
# Related to https://github.com/actions/runner/issues/2708 | |
- name: Report disk usage | |
run: df -h | |
- name: Setup Go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | |
with: | |
go-version: "1.23" | |
cache: false | |
- name: Checkout code | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- id: 'auth' | |
name: Authenticate to Google Cloud | |
uses: google-github-actions/auth@8254fb75a33b976a221574d287e93919e6a36f70 # v2.1.6 | |
with: | |
workload_identity_provider: ${{ vars.PROVIDER_NAME }} | |
service_account: ${{ vars.SERVICE_ACCOUNT }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@f0990588f1e5b5af6827153b93673613abdc6ec7 # v2.1.1 | |
- name: Get Secrets | |
id: 'secrets' | |
uses: google-github-actions/get-secretmanager-secrets@95a0b09b8348ef3d02c68c6ba5662a037e78d713 # v2.1.4 | |
with: | |
secrets: |- | |
ALLOYDB_INSTANCE_URI:${{ vars.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_INSTANCE_NAME | |
ALLOYDB_CLUSTER_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS | |
IMPERSONATED_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/IMPERSONATED_USER | |
ALLOYDB_IAM_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_PROXY_IAM_USER | |
ALLOYDB_PSC_INSTANCE_URI:${{ vars.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_PSC_INSTANCE_URI | |
- name: Run tests | |
env: | |
ALLOYDB_DB: 'postgres' | |
ALLOYDB_USER: 'postgres' | |
ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}' | |
ALLOYDB_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_INSTANCE_URI }}' | |
IMPERSONATED_USER: '${{ steps.secrets.outputs.IMPERSONATED_USER }}' | |
ALLOYDB_IAM_USER: '${{ steps.secrets.outputs.ALLOYDB_IAM_USER }}' | |
ALLOYDB_PSC_INSTANCE_URI: '${{ steps.secrets.outputs.ALLOYDB_PSC_INSTANCE_URI }}' | |
# specifying bash shell ensures a failure in a piped process isn't lost by using `set -eo pipefail` | |
shell: bash | |
run: | | |
go test -v -race -cover ./tests | tee test_results.txt | |
- name: Convert test output to XML | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && always() }} | |
run: | | |
go install github.com/jstemmer/go-junit-report/v2@latest | |
go-junit-report -in test_results.txt -set-exit-code -out integration_sponge_log.xml | |
- name: FlakyBot | |
# only run flakybot on periodic (schedule) and continuous (push) events | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && always() }} | |
run: | | |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L | |
chmod +x ./flakybot | |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} | |
unit: | |
name: "unit tests" | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
os: [macos-latest, windows-latest, ubuntu-latest] | |
fail-fast: false | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
issues: write | |
pull-requests: write | |
steps: | |
- name: Setup Go | |
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2 | |
with: | |
go-version: "1.23" | |
cache: false | |
- name: Checkout code | |
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
repository: ${{ github.event.pull_request.head.repo.full_name }} | |
- id: 'auth' | |
name: Authenticate to Google Cloud | |
# only needed for Flakybot on periodic (schedule) and continuous (push) events | |
if: ${{ github.event_name == 'schedule' || github.event_name == 'push' }} | |
uses: google-github-actions/auth@8254fb75a33b976a221574d287e93919e6a36f70 # v2.1.6 | |
with: | |
workload_identity_provider: ${{ vars.PROVIDER_NAME }} | |
service_account: ${{ vars.SERVICE_ACCOUNT }} | |
- name: Run tests | |
# specifying bash shell ensures a failure in a piped process isn't lost by using `set -eo pipefail` | |
shell: bash | |
run: | | |
go test -race -v -cover -short ./... | tee test_results.txt | |
- name: Convert test output to XML | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && always() }} | |
run: | | |
go install github.com/jstemmer/go-junit-report/v2@latest | |
go-junit-report -in test_results.txt -set-exit-code -out unit_sponge_log.xml | |
- name: FlakyBot (Linux) | |
# only run flakybot on periodic (schedule) and continuous (push) events | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Linux' && always() }} | |
run: | | |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L | |
chmod +x ./flakybot | |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} | |
- name: FlakyBot (Windows) | |
# only run flakybot on periodic (schedule) and continuous (push) events | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Windows' && always() }} | |
run: | | |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot.exe -o flakybot.exe -s -L | |
./flakybot.exe --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} | |
- name: FlakyBot (macOS) | |
# only run flakybot on periodic (schedule) and continuous (push) events | |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'macOS' && always() }} | |
run: | | |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot-darwin-amd64 -o flakybot -s -L | |
chmod +x ./flakybot | |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |