|
18 | 18 | push: |
19 | 19 | branches: |
20 | 20 | - main |
| 21 | + pull_request_target: |
| 22 | + types: [labeled] |
| 23 | + schedule: |
| 24 | + - cron: '0 2 * * *' |
21 | 25 |
|
22 | 26 | jobs: |
23 | | - build: |
24 | | - name: "unit tests" |
| 27 | + integration: |
| 28 | + # 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) |
| 29 | + 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' }}" |
| 30 | + name: integration tests |
25 | 31 | runs-on: ${{ matrix.os }} |
26 | 32 | strategy: |
27 | 33 | matrix: |
28 | 34 | os: [macos-latest, windows-latest, ubuntu-latest] |
29 | 35 | python-version: ["3.7", "3.8", "3.9", "3.10"] |
30 | 36 | fail-fast: false |
| 37 | + permissions: |
| 38 | + contents: 'read' |
| 39 | + id-token: 'write' |
31 | 40 | steps: |
| 41 | + - name: Remove PR label |
| 42 | + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 43 | + uses: actions/github-script@v6 |
| 44 | + with: |
| 45 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 46 | + script: | |
| 47 | + try { |
| 48 | + await github.rest.issues.removeLabel({ |
| 49 | + name: 'tests: run', |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + issue_number: context.payload.pull_request.number |
| 53 | + }); |
| 54 | + } catch (e) { |
| 55 | + console.log('Failed to remove label. Another job may have already removed it!'); |
| 56 | + } |
| 57 | +
|
| 58 | + - name: Checkout code |
| 59 | + uses: 'actions/checkout@v3' |
| 60 | + with: |
| 61 | + ref: ${{ github.event.pull_request.head.sha }} |
| 62 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 63 | + |
32 | 64 | - name: Setup Python ${{ matrix.python-version }} |
33 | 65 | uses: actions/setup-python@v4 |
34 | 66 | with: |
|
37 | 69 | - name: Install nox |
38 | 70 | run: pip install nox |
39 | 71 |
|
| 72 | + - id: 'auth' |
| 73 | + name: 'Authenticate to Google Cloud' |
| 74 | + uses: 'google-github-actions/auth@v0.8.0' |
| 75 | + with: |
| 76 | + workload_identity_provider: ${{ secrets.PROVIDER_NAME }} |
| 77 | + service_account: ${{ secrets.SERVICE_ACCOUNT }} |
| 78 | + access_token_lifetime: 600s |
| 79 | + |
| 80 | + - id: 'secrets' |
| 81 | + name: Get secrets |
| 82 | + uses: 'google-github-actions/get-secretmanager-secrets@v0.5.0' |
| 83 | + with: |
| 84 | + secrets: |- |
| 85 | + MYSQL_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_CONNECTION_NAME |
| 86 | + MYSQL_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER |
| 87 | + MYSQL_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS |
| 88 | + MYSQL_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB |
| 89 | + POSTGRES_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME |
| 90 | + POSTGRES_IAM_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_IAM_CONNECTION_NAME |
| 91 | + POSTGRES_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER |
| 92 | + POSTGRES_IAM_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_PYTHON |
| 93 | + POSTGRES_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_PASS |
| 94 | + POSTGRES_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/POSTGRES_DB |
| 95 | + SQLSERVER_CONNECTION_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_CONNECTION_NAME |
| 96 | + SQLSERVER_USER:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_USER |
| 97 | + SQLSERVER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_PASS |
| 98 | + SQLSERVER_DB:${{ secrets.GOOGLE_CLOUD_PROJECT }}/SQLSERVER_DB |
| 99 | +
|
| 100 | + - name: Run tests |
| 101 | + env: |
| 102 | + MYSQL_CONNECTION_NAME: '${{ steps.secrets.outputs.MYSQL_CONNECTION_NAME }}' |
| 103 | + MYSQL_USER: '${{ steps.secrets.outputs.MYSQL_USER }}' |
| 104 | + MYSQL_PASS: '${{ steps.secrets.outputs.MYSQL_PASS }}' |
| 105 | + MYSQL_DB: '${{ steps.secrets.outputs.MYSQL_DB }}' |
| 106 | + POSTGRES_CONNECTION_NAME: '${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}' |
| 107 | + POSTGRES_IAM_CONNECTION_NAME: '${{ steps.secrets.outputs.POSTGRES_IAM_CONNECTION_NAME }}' |
| 108 | + POSTGRES_USER: '${{ steps.secrets.outputs.POSTGRES_USER }}' |
| 109 | + POSTGRES_IAM_USER: '${{ steps.secrets.outputs.POSTGRES_IAM_USER }}' |
| 110 | + POSTGRES_PASS: '${{ steps.secrets.outputs.POSTGRES_PASS }}' |
| 111 | + POSTGRES_DB: '${{ steps.secrets.outputs.POSTGRES_DB }}' |
| 112 | + SQLSERVER_CONNECTION_NAME: '${{ steps.secrets.outputs.SQLSERVER_CONNECTION_NAME }}' |
| 113 | + SQLSERVER_USER: '${{ steps.secrets.outputs.SQLSERVER_USER }}' |
| 114 | + SQLSERVER_PASS: '${{ steps.secrets.outputs.SQLSERVER_PASS }}' |
| 115 | + SQLSERVER_DB: '${{ steps.secrets.outputs.SQLSERVER_DB }}' |
| 116 | + run: nox -s system-${{ matrix.python-version }} |
| 117 | + |
| 118 | + unit: |
| 119 | + # 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) |
| 120 | + 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' }}" |
| 121 | + name: unit tests |
| 122 | + runs-on: ${{ matrix.os }} |
| 123 | + strategy: |
| 124 | + matrix: |
| 125 | + os: [macos-latest, windows-latest, ubuntu-latest] |
| 126 | + python-version: ["3.7", "3.8", "3.9", "3.10"] |
| 127 | + fail-fast: false |
| 128 | + steps: |
| 129 | + - name: Remove PR label |
| 130 | + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 131 | + uses: actions/github-script@v6 |
| 132 | + with: |
| 133 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 134 | + script: | |
| 135 | + try { |
| 136 | + await github.rest.issues.removeLabel({ |
| 137 | + name: 'tests: run', |
| 138 | + owner: context.repo.owner, |
| 139 | + repo: context.repo.repo, |
| 140 | + issue_number: context.payload.pull_request.number |
| 141 | + }); |
| 142 | + } catch (e) { |
| 143 | + console.log('Failed to remove label. Another job may have already removed it!'); |
| 144 | + } |
| 145 | +
|
40 | 146 | - name: Checkout code |
41 | | - uses: actions/checkout@v3 |
| 147 | + uses: 'actions/checkout@v3' |
| 148 | + with: |
| 149 | + ref: ${{ github.event.pull_request.head.sha }} |
| 150 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 151 | + |
| 152 | + - name: Setup Python ${{ matrix.python-version }} |
| 153 | + uses: actions/setup-python@v4 |
| 154 | + with: |
| 155 | + python-version: ${{ matrix.python-version }} |
| 156 | + |
| 157 | + - name: Install nox |
| 158 | + run: pip install nox |
42 | 159 |
|
43 | 160 | - name: Run tests |
44 | 161 | run: nox -s unit-${{ matrix.python-version }} |
0 commit comments