e2e-managed.yml 7.0 KB

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