...

Text file src/cloud.google.com/go/cloudsqlconn/.github/workflows/tests.yaml

Documentation: cloud.google.com/go/cloudsqlconn/.github/workflows

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

View as plain text