e2e-managed.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID}}
  26. AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET}}
  27. TENANT_ID: ${{ secrets.TENANT_ID}}
  28. VAULT_URL: ${{ secrets.VAULT_URL}}
  29. IMAGE_REGISTRY: ghcr.io/external-secrets/external-secrets
  30. E2E_IMAGE_REGISTRY: ghcr.io/external-secrets/external-secrets-e2e
  31. E2E_VERSION: test
  32. name: e2e tests
  33. jobs:
  34. # Repo owner has commented /ok-to-test-managed on a (fork-based) pull request
  35. integration-fork-managed:
  36. runs-on: ubuntu-latest
  37. if:
  38. github.event_name == 'repository_dispatch'
  39. steps:
  40. # Check out merge commit
  41. - name: Fork based /ok-to-test-managed checkout
  42. uses: actions/checkout@v2
  43. with:
  44. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  45. - name: Fetch History
  46. run: git fetch --prune --unshallow
  47. - name: Setup Go
  48. uses: actions/setup-go@v2
  49. with:
  50. go-version: ${{ env.GO_VERSION }}
  51. - name: Find the Go Cache
  52. id: go
  53. run: |
  54. echo "::set-output name=build-cache::$(go env GOCACHE)"
  55. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  56. - name: Cache the Go Build Cache
  57. uses: actions/cache@v2.1.7
  58. with:
  59. path: ${{ steps.go.outputs.build-cache }}
  60. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  61. restore-keys: ${{ runner.os }}-build-unit-tests-
  62. - name: Cache Go Dependencies
  63. uses: actions/cache@v2.1.7
  64. with:
  65. path: ${{ steps.go.outputs.mod-cache }}
  66. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  67. restore-keys: ${{ runner.os }}-pkg-
  68. - name: Setup gcloud CLI
  69. uses: google-github-actions/setup-gcloud@master
  70. with:
  71. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  72. project_id: ${{ env.GCP_PROJECT_ID }}
  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. run: |-
  81. mkdir -p terraform/gcp/secrets
  82. echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
  83. - name: Show TF GKE
  84. run: |-
  85. make tf.show.gcp
  86. - name: Setup Infracost
  87. uses: infracost/actions/setup@v1
  88. with:
  89. api-key: ${{ secrets.INFRACOST_API_KEY }}
  90. - name: Generate Infracost JSON for GKE
  91. run: infracost breakdown --path terraform/gcp/plan.json --format json --out-file /tmp/infracost.json
  92. - name: Post Infracost comment
  93. uses: infracost/actions/comment@v1
  94. with:
  95. path: /tmp/infracost.json
  96. # Choose the commenting behavior, 'update' is a good default:
  97. behavior: update # Create a single comment and update it. The "quietest" option.
  98. # behavior: delete-and-new # Delete previous comments and create a new one.
  99. # behavior: hide-and-new # Minimize previous comments and create a new one.
  100. # behavior: new # Create a new cost estimate comment on every push.
  101. - name: Apply TF GKE
  102. run: |-
  103. make tf.apply.gcp
  104. - name: Get the GKE credentials
  105. run: |-
  106. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  107. - name: Login to Docker
  108. uses: docker/login-action@v1
  109. if: env.GHCR_USERNAME != ''
  110. with:
  111. registry: ghcr.io
  112. username: ${{ secrets.GHCR_USERNAME }}
  113. password: ${{ secrets.GHCR_TOKEN }}
  114. - name: Run e2e Tests for GCP
  115. run: |
  116. export E2E_VERSION=$GITHUB_SHA
  117. export PR_IMG_TAG=$GITHUB_SHA
  118. export PATH=$PATH:$(go env GOPATH)/bin
  119. go get github.com/onsi/ginkgo/ginkgo
  120. make test.e2e.managed FOCUS="gcpmanaged"
  121. - name: Destroy TF GKE
  122. if: always()
  123. run: |-
  124. make tf.destroy.gcp
  125. # Update check run called "integration-fork"
  126. - uses: actions/github-script@v1
  127. id: update-check-run
  128. if: ${{ always() }}
  129. env:
  130. number: ${{ github.event.client_payload.pull_request.number }}
  131. job: ${{ github.job }}
  132. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  133. conclusion: ${{ job.status }}
  134. with:
  135. github-token: ${{ secrets.GITHUB_TOKEN }}
  136. script: |
  137. const { data: pull } = await github.pulls.get({
  138. ...context.repo,
  139. pull_number: process.env.number
  140. });
  141. const ref = pull.head.sha;
  142. console.log("\n\nPR sha: " + ref)
  143. const { data: checks } = await github.checks.listForRef({
  144. ...context.repo,
  145. ref
  146. });
  147. console.log("\n\nPR CHECKS: " + checks)
  148. const check = checks.check_runs.filter(c => c.name === process.env.job);
  149. console.log("\n\nPR Filtered CHECK: " + check)
  150. console.log(check)
  151. const { data: result } = await github.checks.update({
  152. ...context.repo,
  153. check_run_id: check[0].id,
  154. status: 'completed',
  155. conclusion: process.env.conclusion
  156. });
  157. return result;