e2e-managed.yml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # Run secret-dependent e2e tests only after /ok-to-test-managed approval
  2. on:
  3. pull_request:
  4. repository_dispatch:
  5. types: [ok-to-test-managed-command]
  6. env:
  7. # Common versions
  8. GO_VERSION: '1.17'
  9. GOLANGCI_VERSION: 'v1.33'
  10. DOCKER_BUILDX_VERSION: 'v0.4.2'
  11. # Common users. We can't run a step 'if secrets.GHCR_USERNAME != ""' but we can run
  12. # a step 'if env.GHCR_USERNAME' != ""', so we copy these to succinctly test whether
  13. # credentials have been provided before trying to run steps that need them.
  14. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  15. GCP_SM_SA_JSON: ${{ secrets.GCP_SM_SA_JSON}}
  16. GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
  17. TF_VAR_GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
  18. GCP_SM_SA_GKE_JSON: ${{ secrets.GCP_SM_SA_GKE_JSON}}
  19. GCP_GKE_CLUSTER: test-cluster
  20. GCP_GKE_ZONE: ${{ secrets.GCP_GKE_ZONE}}
  21. GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account
  22. GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account
  23. TF_VAR_GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account for tf
  24. TF_VAR_GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account for tf
  25. AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  26. AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  27. AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  28. AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  29. AWS_REGION: "eu-west-1"
  30. AWS_CLUSTER_NAME: "eso-e2e-managed"
  31. TF_VAR_AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  32. TF_VAR_AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  33. TF_VAR_AWS_REGION: "eu-west-1"
  34. TF_VAR_AWS_CLUSTER_NAME: "eso-e2e-managed"
  35. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID}}
  36. AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET}}
  37. TENANT_ID: ${{ secrets.TENANT_ID}}
  38. VAULT_URL: ${{ secrets.VAULT_URL}}
  39. name: e2e tests
  40. jobs:
  41. integration-managed:
  42. runs-on: ubuntu-latest
  43. if: github.event_name == 'repository_dispatch'
  44. steps:
  45. # set status=in_progress
  46. - uses: actions/github-script@v1
  47. env:
  48. number: ${{ github.event.client_payload.pull_request.number }}
  49. job: ${{ github.job }}
  50. conclusion: ${{ job.status }}
  51. with:
  52. github-token: ${{ secrets.GITHUB_TOKEN }}
  53. script: |
  54. const { data: pull } = await github.pulls.get({
  55. ...context.repo,
  56. pull_number: process.env.number
  57. });
  58. const ref = pull.head.sha;
  59. console.log("\n\nPR sha: " + ref)
  60. const { data: checks } = await github.checks.listForRef({
  61. ...context.repo,
  62. ref
  63. });
  64. console.log("\n\nPR CHECKS: " + checks)
  65. const check = checks.check_runs.filter(c => c.name === process.env.job);
  66. console.log("\n\nPR Filtered CHECK: " + check)
  67. console.log(check)
  68. const { data: result } = await github.checks.update({
  69. ...context.repo,
  70. check_run_id: check[0].id,
  71. status: 'in_progress',
  72. });
  73. return result;
  74. # Check out merge commit
  75. - name: Fork based /ok-to-test-managed checkout
  76. uses: actions/checkout@v2
  77. with:
  78. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  79. - name: Fetch History
  80. run: git fetch --prune --unshallow
  81. - name: Setup Go
  82. uses: actions/setup-go@v2
  83. with:
  84. go-version: ${{ env.GO_VERSION }}
  85. - name: Find the Go Cache
  86. id: go
  87. run: |
  88. echo "::set-output name=build-cache::$(go env GOCACHE)"
  89. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  90. - name: Cache the Go Build Cache
  91. uses: actions/cache@v2.1.7
  92. with:
  93. path: ${{ steps.go.outputs.build-cache }}
  94. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  95. restore-keys: ${{ runner.os }}-build-unit-tests-
  96. - name: Cache Go Dependencies
  97. uses: actions/cache@v2.1.7
  98. with:
  99. path: ${{ steps.go.outputs.mod-cache }}
  100. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  101. restore-keys: ${{ runner.os }}-pkg-
  102. - name: Setup TFLint
  103. uses: terraform-linters/setup-tflint@v1
  104. with:
  105. tflint_version: v0.28.0 # Must be specified. See: https://github.com/terraform-linters/tflint/releases for latest versions
  106. - name: Run TFLint
  107. run: find ${{ github.workspace }} | grep tf$ | xargs -n1 dirname | xargs -IXXX -n1 /bin/sh -c 'set -o errexit; cd XXX; pwd; tflint --loglevel=info .; cd - >/dev/null'
  108. - name: Setup TF Gcloud Provider
  109. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  110. run: |-
  111. mkdir -p terraform/gcp/secrets
  112. echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
  113. - name: Show TF
  114. run: |-
  115. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  116. make tf.show.${PROVIDER}
  117. - name: Setup Infracost
  118. uses: infracost/actions/setup@v1
  119. with:
  120. api-key: ${{ secrets.INFRACOST_API_KEY }}
  121. - name: Generate Infracost JSON for provider
  122. run: infracost breakdown --path terraform/${{github.event.client_payload.slash_command.args.named.provider}}/plan.json --format json --out-file /tmp/infracost.json
  123. - name: Post Infracost comment
  124. uses: infracost/actions/comment@v1
  125. with:
  126. path: /tmp/infracost.json
  127. behavior: update
  128. - name: Apply TF
  129. run: |-
  130. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  131. make tf.apply.${PROVIDER}
  132. - name: Setup gcloud CLI
  133. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  134. uses: google-github-actions/setup-gcloud@master
  135. with:
  136. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  137. project_id: ${{ env.GCP_PROJECT_ID }}
  138. - name: Get the GKE credentials
  139. if: github.event.client_payload.slash_command.args.named.provider == 'gke'
  140. run: |-
  141. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  142. - name: Get the AWS credentials
  143. if: github.event.client_payload.slash_command.args.named.provider == 'aws'
  144. run: |-
  145. aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
  146. - name: Login to Docker
  147. uses: docker/login-action@v1
  148. if: env.GHCR_USERNAME != ''
  149. with:
  150. registry: ghcr.io
  151. username: ${{ secrets.GHCR_USERNAME }}
  152. password: ${{ secrets.GHCR_TOKEN }}
  153. - name: Run managed e2e Tests
  154. run: |
  155. export PATH=$PATH:$(go env GOPATH)/bin
  156. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  157. go get github.com/onsi/ginkgo/v2/ginkgo
  158. make test.e2e.managed GINKGO_LABELS="${PROVIDER}"
  159. - name: Destroy TF
  160. if: always()
  161. run: |-
  162. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  163. make tf.destroy.${PROVIDER}
  164. # set status=completed
  165. - uses: actions/github-script@v1
  166. if: ${{ always() }}
  167. env:
  168. number: ${{ github.event.client_payload.pull_request.number }}
  169. job: ${{ github.job }}
  170. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  171. conclusion: ${{ job.status }}
  172. with:
  173. github-token: ${{ secrets.GITHUB_TOKEN }}
  174. script: |
  175. const { data: pull } = await github.pulls.get({
  176. ...context.repo,
  177. pull_number: process.env.number
  178. });
  179. const ref = pull.head.sha;
  180. console.log("\n\nPR sha: " + ref)
  181. const { data: checks } = await github.checks.listForRef({
  182. ...context.repo,
  183. ref
  184. });
  185. console.log("\n\nPR CHECKS: " + checks)
  186. const check = checks.check_runs.filter(c => c.name === process.env.job);
  187. console.log("\n\nPR Filtered CHECK: " + check)
  188. console.log(check)
  189. const { data: result } = await github.checks.update({
  190. ...context.repo,
  191. check_run_id: check[0].id,
  192. status: 'completed',
  193. conclusion: process.env.conclusion
  194. });
  195. return result;