|
1 | 1 | name: tests |
2 | 2 |
|
| 3 | +concurrency: |
| 4 | + # Run only for most recent commit in PRs but for all tags and commits on main |
| 5 | + # Ref: https://docs.github.com/en/actions/using-jobs/using-concurrency |
| 6 | + group: ${{ github.workflow }}-${{ github.head_ref || github.sha }} |
| 7 | + cancel-in-progress: true |
| 8 | + |
3 | 9 | on: |
4 | 10 | pull_request: |
5 | 11 | branches: |
6 | | - - 'main' |
7 | | - - 'release/*' |
| 12 | + - 'main' |
| 13 | + - 'release/*' |
8 | 14 | push: |
9 | 15 | branches: |
10 | | - - 'main' |
| 16 | + - 'main' |
11 | 17 | workflow_dispatch: {} |
12 | 18 |
|
13 | 19 | jobs: |
14 | | - tests-and-coverage: |
15 | | - environment: "integration-tests" |
| 20 | + installer-tests: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + |
| 24 | + - name: checkout repository |
| 25 | + uses: actions/checkout@v3 |
| 26 | + |
| 27 | + - name: run installer script |
| 28 | + env: |
| 29 | + GITHUB_TOKEN: ${{ github.token }} |
| 30 | + run: ./docs/install.sh |
| 31 | + |
| 32 | + - name: run ktf to verify if it installed properly to a desired location |
| 33 | + run: ~/.local/bin/ktf |
| 34 | + |
| 35 | + unit-tests: |
16 | 36 | runs-on: ubuntu-latest |
17 | 37 | steps: |
| 38 | + |
| 39 | + - name: checkout repository |
| 40 | + uses: actions/checkout@v3 |
| 41 | + with: |
| 42 | + fetch-depth: 0 |
| 43 | + |
18 | 44 | - name: setup golang |
19 | | - uses: actions/setup-go@v3 |
| 45 | + uses: actions/setup-go@v4 |
20 | 46 | with: |
21 | | - go-version: '^1.18' |
| 47 | + go-version: '^1.19' |
22 | 48 |
|
23 | | - - name: cache go modules |
24 | | - uses: actions/cache@v3 |
| 49 | + - name: run unit tests |
| 50 | + run: make test.unit |
| 51 | + |
| 52 | + # We're using a retry mechanism for codecov to ensure we do get the reports |
| 53 | + # uploaded. The alternative is to use fail_ci_if_error: false, but that |
| 54 | + # somewhat defeats the purpose of uploading those reports. Why bother uploading |
| 55 | + # if we don't care if the upload's successful? |
| 56 | + - name: Upload coverage to Codecov |
| 57 | + if: steps.detect_if_should_run.outputs.result == 'true' |
| 58 | + uses: Wandalen/wretry.action@v1.3.0 |
25 | 59 | with: |
26 | | - path: ~/go/pkg/mod |
27 | | - key: ${{ runner.os }}-build-codegen-${{ hashFiles('**/go.sum') }} |
28 | | - restore-keys: | |
29 | | - ${{ runner.os }}-build-codegen- |
| 60 | + action: codecov/codecov-action@v3 |
| 61 | + with: | |
| 62 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 63 | + fail_ci_if_error: true |
| 64 | + flags: unit-test |
| 65 | + files: unit.coverage.out |
| 66 | + verbose: true |
| 67 | + attempt_limit: 10 |
| 68 | + attempt_delay: 30000 |
| 69 | + |
| 70 | + setup-integration-tests: |
| 71 | + runs-on: ubuntu-latest |
| 72 | + outputs: |
| 73 | + test_names: ${{ steps.set_test_names.outputs.test_names }} |
| 74 | + steps: |
| 75 | + |
| 76 | + - uses: actions/checkout@v3 |
| 77 | + |
| 78 | + - id: set_test_names |
| 79 | + name: Set test names |
| 80 | + working-directory: test/integration/ |
| 81 | + # grep magic described in https://unix.stackexchange.com/a/13472 |
| 82 | + # sed to add the extra $ is because some of our test names overlap. we need it so the -run regex only matches one test |
| 83 | + run: | |
| 84 | + echo "test_names=$(grep -shoP "(?<=^func )(Test[a-zA-z_0-9]+)(?=\(t \*testing.T\) {)" * | sed -e "s/$/\$/"| jq -R . | jq -cs .)" >> $GITHUB_OUTPUT |
| 85 | +
|
| 86 | + - name: Print test names |
| 87 | + run: echo "Test names ${{ steps.set_test_names.outputs.test_names }}" |
| 88 | + |
| 89 | + integration-tests: |
| 90 | + needs: |
| 91 | + - setup-integration-tests |
| 92 | + strategy: |
| 93 | + fail-fast: false |
| 94 | + matrix: |
| 95 | + test: ${{ fromJSON(needs.setup-integration-tests.outputs.test_names) }} |
| 96 | + runs-on: ubuntu-latest |
| 97 | + steps: |
| 98 | + # This step is needed to avoid running the integration tests requiring an enterprise license |
| 99 | + # if the secrets are not available. |
| 100 | + - name: Detect if we should run test cases requring an enterprise license (have required secrets) |
| 101 | + id: detect_if_should_run_enterprise |
| 102 | + run: echo "result=${{ secrets.PULP_PASSWORD != '' }}" >> $GITHUB_OUTPUT |
| 103 | + |
| 104 | + - name: Set environment variable to enable test cases requiring an enterprise license |
| 105 | + if: steps.detect_if_should_run_enterprise.outputs.result == 'true' |
| 106 | + id: set_run_enterprise_env |
| 107 | + run: echo "KTF_TEST_RUN_ENTERPRISE_CASES=true" >> $GITHUB_ENV |
30 | 108 |
|
31 | 109 | - name: checkout repository |
32 | 110 | uses: actions/checkout@v3 |
33 | 111 | with: |
34 | 112 | fetch-depth: 0 |
35 | 113 |
|
36 | | - - name: run unit tests |
37 | | - run: make test.unit |
| 114 | + - uses: Kong/kong-license@master |
| 115 | + if: steps.detect_if_should_run_enterprise.outputs.result == 'true' |
| 116 | + id: license |
| 117 | + with: |
| 118 | + password: ${{ secrets.PULP_PASSWORD }} |
| 119 | + |
| 120 | + - name: setup golang |
| 121 | + uses: actions/setup-go@v4 |
| 122 | + with: |
| 123 | + go-version: '^1.19' |
38 | 124 |
|
39 | | - - name: run integration tests |
| 125 | + - name: run integration test ${{ matrix.test }} |
40 | 126 | run: make test.integration |
41 | 127 | env: |
42 | | - KONG_LICENSE_DATA: ${{ secrets.KONG_LICENSE_DATA }} |
43 | | - NCPU: 2 # it was found that github actions (specifically) did not seem to perform well when spawning |
44 | | - # multiple kind clusters within a single job so this is hardcoded to 2 to ensure a limit of 2 clusters at any one point. |
| 128 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 129 | + KTF_TEST_KONG_PULL_USERNAME: ${{ secrets.GHA_DOCKERHUB_PULL_USER }} |
| 130 | + KTF_TEST_KONG_PULL_PASSWORD: ${{ secrets.GHA_KONG_ORG_DOCKERHUB_PUBLIC_TOKEN }} |
| 131 | + KONG_LICENSE_DATA: ${{ steps.license.outputs.license }} |
| 132 | + TEST_RUN: ${{ matrix.test }} |
| 133 | + NCPU: 1 |
45 | 134 |
|
| 135 | + # We're using a retry mechanism for codecov to ensure we do get the reports |
| 136 | + # uploaded. The alternative is to use fail_ci_if_error: false, but that |
| 137 | + # somewhat defeats the purpose of uploading those reports. Why bother uploading |
| 138 | + # if we don't care if the upload's successful? |
46 | 139 | - name: Upload coverage to Codecov |
47 | | - uses: codecov/codecov-action@v3 |
| 140 | + uses: Wandalen/wretry.action@v1.3.0 |
48 | 141 | with: |
49 | | - token: ${{ secrets.CODECOV_TOKEN }} |
50 | | - fail_ci_if_error: true |
51 | | - files: unit.coverage.out,integration.coverage.out |
52 | | - verbose: true |
| 142 | + action: codecov/codecov-action@v3 |
| 143 | + with: | |
| 144 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 145 | + fail_ci_if_error: true |
| 146 | + flags: integration-test |
| 147 | + files: integration.coverage.out |
| 148 | + verbose: true |
| 149 | + attempt_limit: 10 |
| 150 | + attempt_delay: 30000 |
| 151 | + |
| 152 | + integration-tests-passed: |
| 153 | + needs: integration-tests |
| 154 | + if: always() && !contains(needs.*.result, 'failure') |
| 155 | + runs-on: ubuntu-latest |
| 156 | + steps: |
| 157 | + - name: integrations tests pased |
| 158 | + run: echo all integrations tests passed |
| 159 | + |
| 160 | + setup-e2e-tests: |
| 161 | + runs-on: ubuntu-latest |
| 162 | + outputs: |
| 163 | + test_names: ${{ steps.set_test_names.outputs.test_names }} |
| 164 | + steps: |
| 165 | + |
| 166 | + - uses: actions/checkout@v3 |
| 167 | + |
| 168 | + - id: set_test_names |
| 169 | + name: Set test names |
| 170 | + working-directory: test/e2e/ |
| 171 | + # grep magic described in https://unix.stackexchange.com/a/13472 |
| 172 | + # sed to add the extra $ is because some of our test names overlap. we need it so the -run regex only matches one test |
| 173 | + run: | |
| 174 | + echo "test_names=$(grep -shoP "(?<=^func )(Test[a-zA-z_0-9]+)(?=\(t \*testing.T\) {)" * | sed -e "s/$/\$/"| jq -R . | jq -cs .)" >> $GITHUB_OUTPUT |
| 175 | +
|
| 176 | + - name: Print test names |
| 177 | + run: echo "Test names ${{ steps.set_test_names.outputs.test_names }}" |
| 178 | + |
| 179 | + e2e-tests: |
| 180 | + needs: |
| 181 | + - setup-e2e-tests |
| 182 | + strategy: |
| 183 | + fail-fast: false |
| 184 | + matrix: |
| 185 | + test: ${{ fromJSON(needs.setup-e2e-tests.outputs.test_names) }} |
| 186 | + environment: gcloud |
| 187 | + runs-on: ubuntu-latest |
| 188 | + steps: |
| 189 | + # This step is needed to avoid running the e2e tests if the secrets are not available. |
| 190 | + # TODO: remove this step once we have a way to run integration tests on forks. |
| 191 | + # https://github.com/Kong/kubernetes-testing-framework/issues/596 |
| 192 | + - name: Detect if we should run (have required secrets) |
| 193 | + id: detect_if_should_run |
| 194 | + run: echo "result=${{ secrets.PULP_PASSWORD != '' && secrets.GOOGLE_APPLICATION_CREDENTIALS != '' }}" >> $GITHUB_OUTPUT |
| 195 | + |
| 196 | + - uses: Kong/kong-license@master |
| 197 | + if: steps.detect_if_should_run.outputs.result == 'true' |
| 198 | + id: license |
| 199 | + with: |
| 200 | + password: ${{ secrets.PULP_PASSWORD }} |
| 201 | + |
| 202 | + - name: checkout repository |
| 203 | + if: steps.detect_if_should_run.outputs.result == 'true' |
| 204 | + uses: actions/checkout@v3 |
| 205 | + with: |
| 206 | + fetch-depth: 0 |
| 207 | + |
| 208 | + - name: setup golang |
| 209 | + if: steps.detect_if_should_run.outputs.result == 'true' |
| 210 | + uses: actions/setup-go@v4 |
| 211 | + with: |
| 212 | + go-version: '^1.19' |
| 213 | + |
| 214 | + - name: run e2e tests |
| 215 | + if: steps.detect_if_should_run.outputs.result == 'true' |
| 216 | + run: make test.e2e |
| 217 | + env: |
| 218 | + TEST_RUN: ${{ matrix.test }} |
| 219 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 220 | + GOOGLE_APPLICATION_CREDENTIALS: ${{ secrets.GOOGLE_APPLICATION_CREDENTIALS }} |
| 221 | + GOOGLE_PROJECT: ${{ secrets.GOOGLE_PROJECT }} |
| 222 | + GOOGLE_LOCATION: ${{ secrets.GOOGLE_LOCATION }} |
| 223 | + KONG_LICENSE_DATA: ${{ steps.license.outputs.license }} |
| 224 | + |
| 225 | + e2e-tests-passed: |
| 226 | + needs: e2e-tests |
| 227 | + if: always() && !contains(needs.*.result, 'failure') |
| 228 | + runs-on: ubuntu-latest |
| 229 | + steps: |
| 230 | + - name: e2e tests pased |
| 231 | + run: echo all e2e tests passed |
0 commit comments