| 1 |
# Copyright 2020 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: tests |
| 16 |
on: |
| 17 |
push: |
| 18 |
branches: |
| 19 |
- 'v1' |
| 20 |
pull_request: |
| 21 |
pull_request_target: |
| 22 |
types: [labeled] |
| 23 |
|
| 24 |
jobs: |
| 25 |
unit: |
| 26 |
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label) |
| 27 |
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" |
| 28 |
name: unit tests |
| 29 |
runs-on: "ubuntu-latest" |
| 30 |
strategy: |
| 31 |
matrix: |
| 32 |
go-version: ["1.19", "1.21"] |
| 33 |
fail-fast: false |
| 34 |
permissions: |
| 35 |
contents: 'read' |
| 36 |
id-token: 'write' |
| 37 |
steps: |
| 38 |
- name: Remove PR label |
| 39 |
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 40 |
uses: actions/github-script@v6 |
| 41 |
with: |
| 42 |
github-token: ${{ secrets.GITHUB_TOKEN }} |
| 43 |
script: | |
| 44 |
try { |
| 45 |
await github.rest.issues.removeLabel({ |
| 46 |
name: 'tests: run', |
| 47 |
owner: context.repo.owner, |
| 48 |
repo: context.repo.repo, |
| 49 |
issue_number: context.payload.pull_request.number |
| 50 |
}); |
| 51 |
} catch (e) { |
| 52 |
console.log('Failed to remove label. Another job may have already removed it!'); |
| 53 |
} |
| 54 |
|
| 55 |
- name: Checkout code |
| 56 |
uses: 'actions/checkout@v3' |
| 57 |
with: |
| 58 |
ref: ${{ github.event.pull_request.head.sha }} |
| 59 |
repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 60 |
|
| 61 |
- name: Setup Go ${{ matrix.go-version }} |
| 62 |
uses: actions/setup-go@v3 |
| 63 |
with: |
| 64 |
go-version: ${{ matrix.go-version }} |
| 65 |
|
| 66 |
- id: 'auth' |
| 67 |
name: 'Authenticate to Google Cloud' |
| 68 |
uses: 'google-github-actions/[email protected]' |
| 69 |
with: |
| 70 |
workload_identity_provider: ${{ secrets.PROVIDER_NAME }} |
| 71 |
service_account: ${{ secrets.SERVICE_ACCOUNT }} |
| 72 |
access_token_lifetime: 600s |
| 73 |
|
| 74 |
- name: Run tests |
| 75 |
# specifying bash shell ensures a failure in a piped process isn't lost by using `set -eo pipefail` |
| 76 |
shell: bash |
| 77 |
run: | |
| 78 |
go install github.com/jstemmer/go-junit-report/v2@latest |
| 79 |
go test -short -race -v ./... | tee test_results.txt |
| 80 |
go-junit-report -in test_results.txt -set-exit-code -out unit_sponge_log.xml |
| 81 |
|
| 82 |
- name: FlakyBot |
| 83 |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && always() }} |
| 84 |
run: | |
| 85 |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L |
| 86 |
chmod +x ./flakybot |
| 87 |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 88 |
|
| 89 |
integration: |
| 90 |
# run job on proper workflow event triggers (skip job for pull_request event from forks and only run pull_request_target for "tests: run" label) |
| 91 |
if: "${{ (github.event.action != 'labeled' && github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name) || github.event.label.name == 'tests: run' }}" |
| 92 |
name: integration tests |
| 93 |
runs-on: ${{ matrix.os }} |
| 94 |
strategy: |
| 95 |
matrix: |
| 96 |
os: [macos-latest, windows-latest, ubuntu-latest] |
| 97 |
fail-fast: false |
| 98 |
permissions: |
| 99 |
contents: 'read' |
| 100 |
id-token: 'write' |
| 101 |
steps: |
| 102 |
- name: Remove PR label |
| 103 |
if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 104 |
uses: actions/github-script@v6 |
| 105 |
with: |
| 106 |
github-token: ${{ secrets.GITHUB_TOKEN }} |
| 107 |
script: | |
| 108 |
try { |
| 109 |
await github.rest.issues.removeLabel({ |
| 110 |
name: 'tests: run', |
| 111 |
owner: context.repo.owner, |
| 112 |
repo: context.repo.repo, |
| 113 |
issue_number: context.payload.pull_request.number |
| 114 |
}); |
| 115 |
} catch (e) { |
| 116 |
console.log('Failed to remove label. Another job may have already removed it!'); |
| 117 |
} |
| 118 |
|
| 119 |
- name: Checkout code |
| 120 |
uses: 'actions/checkout@v3' |
| 121 |
with: |
| 122 |
ref: ${{ github.event.pull_request.head.sha }} |
| 123 |
repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 124 |
|
| 125 |
- name: Setup Go |
| 126 |
uses: actions/setup-go@v3 |
| 127 |
with: |
| 128 |
go-version: "1.21" |
| 129 |
|
| 130 |
- id: 'auth' |
| 131 |
name: 'Authenticate to Google Cloud' |
| 132 |
uses: 'google-github-actions/[email protected]' |
| 133 |
with: |
| 134 |
workload_identity_provider: ${{ secrets.PROVIDER_NAME }} |
| 135 |
service_account: ${{ secrets.SERVICE_ACCOUNT }} |
| 136 |
access_token_lifetime: 600s |
| 137 |
|
| 138 |
- id: 'secrets' |
| 139 |
name: Get secrets |
| 140 |
uses: 'google-github-actions/[email protected]' |
| 141 |
with: |
| 142 |
secrets: |- |
| 143 |
MYSQL_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_CONNECTION_NAME |
| 144 |
MYSQL_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER |
| 145 |
MYSQL_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS |
| 146 |
MYSQL_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB |
| 147 |
POSTGRES_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME |
| 148 |
POSTGRES_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER |
| 149 |
POSTGRES_USER_IAM:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM |
| 150 |
POSTGRES_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_PASS |
| 151 |
POSTGRES_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_DB |
| 152 |
SQLSERVER_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_CONNECTION_NAME |
| 153 |
SQLSERVER_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_USER |
| 154 |
SQLSERVER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_PASS |
| 155 |
SQLSERVER_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_DB |
| 156 |
|
| 157 |
- name: Enable fuse config (Linux) |
| 158 |
if: runner.os == 'Linux' |
| 159 |
run: | |
| 160 |
sudo sed -i 's/#user_allow_other/user_allow_other/g' /etc/fuse.conf |
| 161 |
|
| 162 |
- name: Run tests |
| 163 |
env: |
| 164 |
GOOGLE_CLOUD_PROJECT: '${{ secrets.GOOGLE_CLOUD_PROJECT }}' |
| 165 |
MYSQL_CONNECTION_NAME: '${{ steps.secrets.outputs.MYSQL_CONNECTION_NAME }}' |
| 166 |
MYSQL_USER: '${{ steps.secrets.outputs.MYSQL_USER }}' |
| 167 |
MYSQL_PASS: '${{ steps.secrets.outputs.MYSQL_PASS }}' |
| 168 |
MYSQL_DB: '${{ steps.secrets.outputs.MYSQL_DB }}' |
| 169 |
POSTGRES_CONNECTION_NAME: '${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}' |
| 170 |
POSTGRES_USER: '${{ steps.secrets.outputs.POSTGRES_USER }}' |
| 171 |
POSTGRES_USER_IAM: '${{ steps.secrets.outputs.POSTGRES_USER_IAM }}' |
| 172 |
POSTGRES_PASS: '${{ steps.secrets.outputs.POSTGRES_PASS }}' |
| 173 |
POSTGRES_DB: '${{ steps.secrets.outputs.POSTGRES_DB }}' |
| 174 |
SQLSERVER_CONNECTION_NAME: '${{ steps.secrets.outputs.SQLSERVER_CONNECTION_NAME }}' |
| 175 |
SQLSERVER_USER: '${{ steps.secrets.outputs.SQLSERVER_USER }}' |
| 176 |
SQLSERVER_PASS: '${{ steps.secrets.outputs.SQLSERVER_PASS }}' |
| 177 |
SQLSERVER_DB: '${{ steps.secrets.outputs.SQLSERVER_DB }}' |
| 178 |
TMPDIR: "/tmp" |
| 179 |
run: | |
| 180 |
go install github.com/jstemmer/go-junit-report/v2@latest |
| 181 |
go test -race -v ./... | tee test_results.txt |
| 182 |
go-junit-report -in test_results.txt -set-exit-code -out integration_sponge_log.xml |
| 183 |
|
| 184 |
- name: FlakyBot (Linux) |
| 185 |
# only run flakybot on periodic (schedule) and continuous (push) events |
| 186 |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Linux' && always() }} |
| 187 |
run: | |
| 188 |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L |
| 189 |
chmod +x ./flakybot |
| 190 |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 191 |
|
| 192 |
- name: FlakyBot (Windows) |
| 193 |
# only run flakybot on periodic (schedule) and continuous (push) events |
| 194 |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'Windows' && always() }} |
| 195 |
run: | |
| 196 |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot.exe -o flakybot.exe -s -L |
| 197 |
./flakybot.exe --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
| 198 |
|
| 199 |
- name: FlakyBot (macOS) |
| 200 |
# only run flakybot on periodic (schedule) and continuous (push) events |
| 201 |
if: ${{ (github.event_name == 'schedule' || github.event_name == 'push') && runner.os == 'macOS' && always() }} |
| 202 |
run: | |
| 203 |
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot-darwin-amd64 -o flakybot -s -L |
| 204 |
chmod +x ./flakybot |
| 205 |
./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |