e2e-managed.yml 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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. GINKGO_VERSION: 'v2.1.6'
  8. DOCKER_BUILDX_VERSION: 'v0.4.2'
  9. # Common users. We can't run a step 'if secrets.GHCR_USERNAME != ""' but we can run
  10. # a step 'if env.GHCR_USERNAME' != ""', so we copy these to succinctly test whether
  11. # credentials have been provided before trying to run steps that need them.
  12. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  13. GCP_SM_SA_JSON: ${{ secrets.GCP_SM_SA_JSON}}
  14. GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
  15. TF_VAR_GCP_PROJECT_ID: ${{ secrets.GCP_PROJECT_ID}}
  16. GCP_SM_SA_GKE_JSON: ${{ secrets.GCP_SM_SA_GKE_JSON}}
  17. GCP_GKE_CLUSTER: test-cluster
  18. GCP_GKE_ZONE: ${{ secrets.GCP_GKE_ZONE}}
  19. GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account
  20. GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account
  21. TF_VAR_GCP_GSA_NAME: ${{ secrets.GCP_GSA_NAME}} # Goolge Service Account for tf
  22. TF_VAR_GCP_KSA_NAME: ${{ secrets.GCP_KSA_NAME}} # Kubernetes Service Account for tf
  23. AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  24. AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  25. AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  26. AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  27. AWS_REGION: "eu-west-1"
  28. AWS_CLUSTER_NAME: "eso-e2e-managed"
  29. TF_VAR_AWS_SA_NAME: ${{ secrets.AWS_SA_NAME }}
  30. TF_VAR_AWS_SA_NAMESPACE: ${{ secrets.AWS_SA_NAMESPACE }}
  31. TF_VAR_AWS_REGION: "eu-west-1"
  32. TF_VAR_AWS_CLUSTER_NAME: "eso-e2e-managed"
  33. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID}}
  34. AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET}}
  35. TENANT_ID: ${{ secrets.TENANT_ID}}
  36. VAULT_URL: ${{ secrets.VAULT_URL}}
  37. name: e2e tests
  38. jobs:
  39. integration-managed:
  40. runs-on: ubuntu-latest
  41. if: github.event_name == 'repository_dispatch'
  42. steps:
  43. # create new status check for this specific provider
  44. - uses: actions/github-script@v6
  45. if: ${{ always() }}
  46. env:
  47. number: ${{ github.event.client_payload.pull_request.number }}
  48. provider: ${{ github.event.client_payload.slash_command.args.named.provider }}
  49. job: ${{ github.job }}
  50. with:
  51. github-token: ${{ secrets.GITHUB_TOKEN }}
  52. script: |
  53. const { data: pull } = await github.rest.pulls.get({
  54. ...context.repo,
  55. pull_number: process.env.number
  56. });
  57. const ref = pull.head.sha;
  58. console.log("\n\nPR sha: " + ref)
  59. const { data: checks } = await github.rest.checks.listForRef({
  60. ...context.repo,
  61. ref
  62. });
  63. const job_name = process.env.job + "-" + process.env.provider
  64. console.log("\n\nPR CHECKS: " + checks)
  65. const check = checks.check_runs.filter(c => c.name === job_name);
  66. console.log("\n\nPR Filtered CHECK: " + check)
  67. console.log(check)
  68. if(check && check.length > 0){
  69. const { data: result } = await github.rest.checks.update({
  70. ...context.repo,
  71. check_run_id: check[0].id,
  72. status: 'in_progress',
  73. });
  74. return result;
  75. }
  76. const { data: result } = await github.rest.checks.create({
  77. ...context.repo,
  78. name: job_name,
  79. head_sha: pull.head.sha,
  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@v3
  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@v3
  92. with:
  93. go-version-file: "go.mod"
  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@v3
  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@v3
  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@v2
  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@v2
  128. with:
  129. api-key: ${{ secrets.INFRACOST_API_KEY }}
  130. - name: Generate Infracost JSON for provider
  131. run: |
  132. infracost breakdown \
  133. --path terraform/${{github.event.client_payload.slash_command.args.named.provider}}/plan.json \
  134. --format json \
  135. --out-file /tmp/infracost.json
  136. - name: Post Infracost comment
  137. run: |
  138. infracost comment github --path=/tmp/infracost.json \
  139. --repo=$GITHUB_REPOSITORY \
  140. --github-token=${{ secrets.GITHUB_TOKEN }} \
  141. --pull-request=${{ github.event.client_payload.pull_request.number }} \
  142. --behavior=update
  143. - name: Apply TF
  144. run: |-
  145. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  146. make tf.apply.${PROVIDER}
  147. - name: Setup gcloud CLI
  148. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  149. uses: google-github-actions/setup-gcloud@v0
  150. with:
  151. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  152. project_id: ${{ env.GCP_PROJECT_ID }}
  153. - name: Get the GKE credentials
  154. if: github.event.client_payload.slash_command.args.named.provider == 'gcp'
  155. run: |-
  156. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  157. - name: Get the AWS credentials
  158. if: github.event.client_payload.slash_command.args.named.provider == 'aws'
  159. run: |-
  160. aws --region $AWS_REGION eks update-kubeconfig --name $AWS_CLUSTER_NAME
  161. - name: Login to Docker
  162. uses: docker/login-action@v2
  163. if: env.GHCR_USERNAME != ''
  164. with:
  165. registry: ghcr.io
  166. username: ${{ secrets.GHCR_USERNAME }}
  167. password: ${{ secrets.GHCR_TOKEN }}
  168. - name: Run managed e2e Tests
  169. run: |
  170. export PATH=$PATH:$(go env GOPATH)/bin
  171. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  172. go install github.com/onsi/ginkgo/v2/ginkgo@${{env.GINKGO_VERSION}}
  173. make test.e2e.managed GINKGO_LABELS="${PROVIDER}" TEST_SUITES="provider"
  174. - name: Destroy TF
  175. if: always()
  176. run: |-
  177. PROVIDER=${{github.event.client_payload.slash_command.args.named.provider}}
  178. make tf.destroy.${PROVIDER}
  179. # set status=completed
  180. - uses: actions/github-script@v6
  181. if: ${{ always() }}
  182. env:
  183. number: ${{ github.event.client_payload.pull_request.number }}
  184. provider: ${{ github.event.client_payload.slash_command.args.named.provider }}
  185. job: ${{ github.job }}
  186. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  187. conclusion: ${{ job.status }}
  188. with:
  189. github-token: ${{ secrets.GITHUB_TOKEN }}
  190. script: |
  191. const { data: pull } = await github.rest.pulls.get({
  192. ...context.repo,
  193. pull_number: process.env.number
  194. });
  195. const ref = pull.head.sha;
  196. console.log("\n\nPR sha: " + ref)
  197. const { data: checks } = await github.rest.checks.listForRef({
  198. ...context.repo,
  199. ref
  200. });
  201. const job_name = process.env.job + "-" + process.env.provider
  202. console.log("\n\nPR CHECKS: " + checks)
  203. const check = checks.check_runs.filter(c => c.name === job_name);
  204. console.log("\n\nPR Filtered CHECK: " + check)
  205. console.log(check)
  206. const { data: result } = await github.rest.checks.update({
  207. ...context.repo,
  208. check_run_id: check[0].id,
  209. status: 'completed',
  210. conclusion: process.env.conclusion
  211. });
  212. return result;