e2e-managed.yml 8.7 KB

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