e2e-managed.yml 8.6 KB

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