|
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 | 27 | integration: |
24 | | - runs-on: [self-hosted, linux, x64] |
25 | | - name: "integration tests (linux)" |
26 | | - steps: |
27 | | - - name: Setup Go |
28 | | - uses: actions/setup-go@v3 |
29 | | - with: |
30 | | - go-version: "1.18" |
31 | | - - name: Checkout code |
32 | | - uses: actions/checkout@v3 |
33 | | - - name: Get Secrets |
34 | | - id: 'secrets' |
35 | | - uses: 'google-github-actions/get-secretmanager-secrets@v0' |
36 | | - with: |
37 | | - secrets: |- |
38 | | - ALLOYDB_CONN_NAME:alloydb-connector-testing/ALLOYDB_CONN_NAME |
39 | | - ALLOYDB_CLUSTER_PASS:alloydb-connector-testing/ALLOYDB_CLUSTER_PASS |
40 | | - - name: Run tests |
41 | | - env: |
42 | | - ALLOYDB_DB: 'postgres' |
43 | | - ALLOYDB_USER: 'postgres' |
44 | | - ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}' |
45 | | - ALLOYDB_CONNECTION_NAME: '${{ steps.secrets.outputs.ALLOYDB_CONN_NAME }}' |
46 | | - run: | |
47 | | - go test -v -race -cover ./tests |
48 | | - build: |
49 | | - name: "unit tests" |
50 | | - runs-on: ${{ matrix.os }} |
51 | | - strategy: |
52 | | - matrix: |
53 | | - os: [macos-latest, windows-latest, ubuntu-latest] |
54 | | - steps: |
55 | | - - name: Setup Go |
56 | | - uses: actions/setup-go@v3 |
57 | | - with: |
58 | | - go-version: "1.18" |
59 | | - - name: Checkout code |
60 | | - uses: actions/checkout@v3 |
61 | | - - name: Run tests |
62 | | - run: | |
63 | | - go test -v -race -cover -short ./... |
| 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 | + runs-on: [self-hosted, linux, x64] |
| 31 | + name: "integration tests (linux)" |
| 32 | + permissions: |
| 33 | + contents: 'read' |
| 34 | + id-token: 'write' |
| 35 | + steps: |
| 36 | + - name: Remove PR label |
| 37 | + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 38 | + uses: actions/github-script@v6 |
| 39 | + with: |
| 40 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 41 | + script: | |
| 42 | + try { |
| 43 | + await github.rest.issues.removeLabel({ |
| 44 | + name: 'tests: run', |
| 45 | + owner: context.repo.owner, |
| 46 | + repo: context.repo.repo, |
| 47 | + issue_number: context.payload.pull_request.number |
| 48 | + }); |
| 49 | + } catch (e) { |
| 50 | + console.log('Failed to remove label. Another job may have already removed it!'); |
| 51 | + } |
| 52 | +
|
| 53 | + - name: Setup Go |
| 54 | + uses: actions/setup-go@v3 |
| 55 | + with: |
| 56 | + go-version: "1.18" |
| 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 | + |
| 64 | + - id: 'auth' |
| 65 | + name: 'Authenticate to Google Cloud' |
| 66 | + uses: 'google-github-actions/auth@v0.8.0' |
| 67 | + with: |
| 68 | + workload_identity_provider: ${{ secrets.PROVIDER_NAME }} |
| 69 | + service_account: ${{ secrets.SERVICE_ACCOUNT }} |
| 70 | + |
| 71 | + - name: 'Set up Cloud SDK' |
| 72 | + uses: 'google-github-actions/setup-gcloud@v0.6.0' |
| 73 | + |
| 74 | + - name: Get Secrets |
| 75 | + id: 'secrets' |
| 76 | + uses: 'google-github-actions/get-secretmanager-secrets@v0.5.0' |
| 77 | + with: |
| 78 | + secrets: |- |
| 79 | + ALLOYDB_CONN_NAME:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CONN_NAME |
| 80 | + ALLOYDB_CLUSTER_PASS:${{ secrets.GOOGLE_CLOUD_PROJECT }}/ALLOYDB_CLUSTER_PASS |
| 81 | +
|
| 82 | + - name: Run tests |
| 83 | + env: |
| 84 | + ALLOYDB_DB: 'postgres' |
| 85 | + ALLOYDB_USER: 'postgres' |
| 86 | + ALLOYDB_PASS: '${{ steps.secrets.outputs.ALLOYDB_CLUSTER_PASS }}' |
| 87 | + ALLOYDB_CONNECTION_NAME: '${{ steps.secrets.outputs.ALLOYDB_CONN_NAME }}' |
| 88 | + run: | |
| 89 | + go test -v -race -cover ./tests |
| 90 | +
|
| 91 | + unit: |
| 92 | + if: "${{ github.event.action != 'labeled' || github.event.label.name == 'tests: run' }}" |
| 93 | + name: "unit tests" |
| 94 | + runs-on: ${{ matrix.os }} |
| 95 | + strategy: |
| 96 | + matrix: |
| 97 | + os: [macos-latest, windows-latest, ubuntu-latest] |
| 98 | + fail-fast: false |
| 99 | + steps: |
| 100 | + - name: Remove PR label |
| 101 | + if: "${{ github.event.action == 'labeled' && github.event.label.name == 'tests: run' }}" |
| 102 | + uses: actions/github-script@v6 |
| 103 | + with: |
| 104 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + script: | |
| 106 | + try { |
| 107 | + await github.rest.issues.removeLabel({ |
| 108 | + name: 'tests: run', |
| 109 | + owner: context.repo.owner, |
| 110 | + repo: context.repo.repo, |
| 111 | + issue_number: context.payload.pull_request.number |
| 112 | + }); |
| 113 | + } catch (e) { |
| 114 | + console.log('Failed to remove label. Another job may have already removed it!'); |
| 115 | + } |
| 116 | +
|
| 117 | + - name: Setup Go |
| 118 | + uses: actions/setup-go@v3 |
| 119 | + with: |
| 120 | + go-version: "1.18" |
| 121 | + |
| 122 | + - name: Checkout code |
| 123 | + uses: actions/checkout@v3 |
| 124 | + with: |
| 125 | + ref: ${{ github.event.pull_request.head.sha }} |
| 126 | + repository: ${{ github.event.pull_request.head.repo.full_name }} |
| 127 | + |
| 128 | + - name: Run tests |
| 129 | + run: | |
| 130 | + go test -v -race -cover -short ./... |
0 commit comments