e2e-managed.yml 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. id: update-check-run
  48. env:
  49. number: ${{ github.event.client_payload.slash_command.args.named.pull }}
  50. job: ${{ github.job }}
  51. conclusion: ${{ job.status }}
  52. with:
  53. github-token: ${{ secrets.GITHUB_TOKEN }}
  54. script: |
  55. const { data: pull } = await github.pulls.get({
  56. ...context.repo,
  57. pull_number: process.env.number
  58. });
  59. const ref = pull.head.sha;
  60. console.log("\n\nPR sha: " + ref)
  61. const { data: checks } = await github.checks.listForRef({
  62. ...context.repo,
  63. ref
  64. });
  65. console.log("\n\nPR CHECKS: " + checks)
  66. const check = checks.check_runs.filter(c => c.name === process.env.job);
  67. console.log("\n\nPR Filtered CHECK: " + check)
  68. console.log(check)
  69. const { data: result } = await github.checks.update({
  70. ...context.repo,
  71. check_run_id: check[0].id,
  72. status: 'in_progress',
  73. });
  74. return result;
  75. # Check out merge commit
  76. - name: Fork based /ok-to-test-managed checkout
  77. uses: actions/checkout@v2
  78. with:
  79. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  80. - name: Fetch History
  81. run: git fetch --prune --unshallow
  82. - name: Setup Go
  83. uses: actions/setup-go@v2
  84. with:
  85. go-version: ${{ env.GO_VERSION }}
  86. - name: Find the Go Cache
  87. id: go
  88. run: |
  89. echo "::set-output name=build-cache::$(go env GOCACHE)"
  90. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  91. - name: Cache the Go Build Cache
  92. uses: actions/cache@v2.1.7
  93. with:
  94. path: ${{ steps.go.outputs.build-cache }}
  95. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  96. restore-keys: ${{ runner.os }}-build-unit-tests-
  97. - name: Cache Go Dependencies
  98. uses: actions/cache@v2.1.7
  99. with:
  100. path: ${{ steps.go.outputs.mod-cache }}
  101. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  102. restore-keys: ${{ runner.os }}-pkg-
  103. - name: Setup TFLint
  104. uses: terraform-linters/setup-tflint@v1
  105. with:
  106. tflint_version: v0.28.0 # Must be specified. See: https://github.com/terraform-linters/tflint/releases for latest versions
  107. - name: Run TFLint
  108. 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'
  109. - name: Setup TF Gcloud Provider
  110. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  111. run: |-
  112. mkdir -p terraform/gcp/secrets
  113. echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
  114. - name: Show TF
  115. run: |-
  116. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  117. make tf.show.${PROVIDER}
  118. - name: Setup Infracost
  119. uses: infracost/actions/setup@v1
  120. with:
  121. api-key: ${{ secrets.INFRACOST_API_KEY }}
  122. - name: Generate Infracost JSON for provider
  123. run: infracost breakdown --path terraform/${{github.event.client_payload.slash_command.args.named.provider}}/plan.json --format json --out-file /tmp/infracost.json
  124. - name: Post Infracost comment
  125. uses: infracost/actions/comment@v1
  126. with:
  127. path: /tmp/infracost.json
  128. behavior: update
  129. - name: Apply TF
  130. run: |-
  131. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  132. make tf.apply.${PROVIDER}
  133. - name: Setup gcloud CLI
  134. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  135. uses: google-github-actions/setup-gcloud@master
  136. with:
  137. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  138. project_id: ${{ env.GCP_PROJECT_ID }}
  139. - name: Get the GKE credentials
  140. if: github.event.client_payload.slash_command.args.named.provider == 'gke'
  141. run: |-
  142. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  143. - name: Get the AWS credentials
  144. if: github.event.client_payload.slash_command.args.named.provider == 'aws'
  145. run: |-
  146. aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
  147. - name: Login to Docker
  148. uses: docker/login-action@v1
  149. if: env.GHCR_USERNAME != ''
  150. with:
  151. registry: ghcr.io
  152. username: ${{ secrets.GHCR_USERNAME }}
  153. password: ${{ secrets.GHCR_TOKEN }}
  154. - name: Run managed e2e Tests
  155. run: |
  156. export PATH=$PATH:$(go env GOPATH)/bin
  157. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  158. go get github.com/onsi/ginkgo/v2/ginkgo
  159. make test.e2e.managed GINKGO_LABELS="${PROVIDER}"
  160. - name: Destroy TF
  161. if: always()
  162. run: |-
  163. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  164. make tf.destroy.${PROVIDER}
  165. # set status=completed
  166. - uses: actions/github-script@v1
  167. id: update-check-run
  168. if: ${{ always() }}
  169. env:
  170. number: ${{ github.event.client_payload.slash_command.args.named.pull }}
  171. job: ${{ github.job }}
  172. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  173. conclusion: ${{ job.status }}
  174. with:
  175. github-token: ${{ secrets.GITHUB_TOKEN }}
  176. script: |
  177. const { data: pull } = await github.pulls.get({
  178. ...context.repo,
  179. pull_number: process.env.number
  180. });
  181. const ref = pull.head.sha;
  182. console.log("\n\nPR sha: " + ref)
  183. const { data: checks } = await github.checks.listForRef({
  184. ...context.repo,
  185. ref
  186. });
  187. console.log("\n\nPR CHECKS: " + checks)
  188. const check = checks.check_runs.filter(c => c.name === process.env.job);
  189. console.log("\n\nPR Filtered CHECK: " + check)
  190. console.log(check)
  191. const { data: result } = await github.checks.update({
  192. ...context.repo,
  193. check_run_id: check[0].id,
  194. status: 'completed',
  195. conclusion: process.env.conclusion
  196. });
  197. return result;