e2e-managed.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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.19'
  8. GINKGO_VERSION: 'v2.1.6'
  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@v2
  129. with:
  130. api-key: ${{ secrets.INFRACOST_API_KEY }}
  131. - name: Generate Infracost JSON for provider
  132. run: |
  133. infracost breakdown \
  134. --path terraform/${{github.event.client_payload.slash_command.args.named.provider}}/plan.json \
  135. --format json \
  136. --out-file /tmp/infracost.json
  137. - name: Post Infracost comment
  138. run: |
  139. infracost comment github --path=/tmp/infracost.json \
  140. --repo=$GITHUB_REPOSITORY \
  141. --github-token=${{ secrets.GITHUB_TOKEN }} \
  142. --pull-request=${{ github.event.client_payload.pull_request.number }} \
  143. --behavior=update
  144. - name: Apply TF
  145. run: |-
  146. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  147. make tf.apply.${PROVIDER}
  148. - name: Setup gcloud CLI
  149. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  150. uses: google-github-actions/setup-gcloud@v0
  151. with:
  152. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  153. project_id: ${{ env.GCP_PROJECT_ID }}
  154. - name: Get the GKE credentials
  155. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  156. run: |-
  157. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  158. - name: Get the AWS credentials
  159. if: github.event.client_payload.slash_command.args.named.provider == 'aws'
  160. run: |-
  161. aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
  162. - name: Login to Docker
  163. uses: docker/login-action@v2
  164. if: env.GHCR_USERNAME != ''
  165. with:
  166. registry: ghcr.io
  167. username: ${{ secrets.GHCR_USERNAME }}
  168. password: ${{ secrets.GHCR_TOKEN }}
  169. - name: Run managed e2e Tests
  170. run: |
  171. export PATH=$PATH:$(go env GOPATH)/bin
  172. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  173. go install github.com/onsi/ginkgo/v2/ginkgo@${{env.GINKGO_VERSION}}
  174. make test.e2e.managed GINKGO_LABELS="${PROVIDER}" TEST_SUITES="provider"
  175. - name: Destroy TF
  176. if: always()
  177. run: |-
  178. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  179. make tf.destroy.${PROVIDER}
  180. # set status=completed
  181. - uses: actions/github-script@v6
  182. if: ${{ always() }}
  183. env:
  184. number: ${{ github.event.client_payload.pull_request.number }}
  185. provider: ${{ github.event.client_payload.slash_command.args.named.provider }}
  186. job: ${{ github.job }}
  187. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  188. conclusion: ${{ job.status }}
  189. with:
  190. github-token: ${{ secrets.GITHUB_TOKEN }}
  191. script: |
  192. const { data: pull } = await github.rest.pulls.get({
  193. ...context.repo,
  194. pull_number: process.env.number
  195. });
  196. const ref = pull.head.sha;
  197. console.log("\n\nPR sha: " + ref)
  198. const { data: checks } = await github.rest.checks.listForRef({
  199. ...context.repo,
  200. ref
  201. });
  202. const job_name = process.env.job + "-" + process.env.provider
  203. console.log("\n\nPR CHECKS: " + checks)
  204. const check = checks.check_runs.filter(c => c.name === job_name);
  205. console.log("\n\nPR Filtered CHECK: " + check)
  206. console.log(check)
  207. const { data: result } = await github.rest.checks.update({
  208. ...context.repo,
  209. check_run_id: check[0].id,
  210. status: 'completed',
  211. conclusion: process.env.conclusion
  212. });
  213. return result;