e2e-managed.yml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. # Run secret-dependent e2e tests only after /ok-to-test approval
  2. on:
  3. pull_request:
  4. repository_dispatch:
  5. types: [ok-to-test-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. # Branch-based pull request
  35. integration-trusted-managed:
  36. runs-on: ubuntu-latest
  37. if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
  38. steps:
  39. - name: Branch based PR checkout
  40. uses: actions/checkout@v2
  41. # <insert integration tests needing secrets>
  42. - name: Fetch History
  43. run: git fetch --prune --unshallow
  44. - name: Setup Go
  45. uses: actions/setup-go@v2
  46. with:
  47. go-version: ${{ env.GO_VERSION }}
  48. - name: Find the Go Cache
  49. id: go
  50. run: |
  51. echo "::set-output name=build-cache::$(go env GOCACHE)"
  52. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  53. - name: Cache the Go Build Cache
  54. uses: actions/cache@v2.1.7
  55. with:
  56. path: ${{ steps.go.outputs.build-cache }}
  57. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  58. restore-keys: ${{ runner.os }}-build-unit-tests-
  59. - name: Cache Go Dependencies
  60. uses: actions/cache@v2.1.7
  61. with:
  62. path: ${{ steps.go.outputs.mod-cache }}
  63. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  64. restore-keys: ${{ runner.os }}-pkg-
  65. - name: Setup gcloud CLI
  66. uses: google-github-actions/setup-gcloud@master
  67. with:
  68. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  69. project_id: ${{ env.GCP_PROJECT_ID }}
  70. - name: Setup TFLint
  71. uses: terraform-linters/setup-tflint@v1
  72. with:
  73. tflint_version: v0.28.0 # Must be specified. See: https://github.com/terraform-linters/tflint/releases for latest versions
  74. - name: Run TFLint
  75. 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'
  76. - name: Setup TF Gcloud Provider
  77. run: |-
  78. mkdir -p terraform/gcp/secrets
  79. echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
  80. - name: Show TF GKE
  81. run: |-
  82. make tf.show.gcp
  83. - name: Setup Infracost
  84. uses: infracost/actions/setup@v1
  85. with:
  86. api-key: ${{ secrets.INFRACOST_API_KEY }}
  87. - name: Generate Infracost JSON
  88. run: infracost breakdown --path terraform/gcp/plan.json --format json --out-file /tmp/infracost.json
  89. - name: Post Infracost comment
  90. uses: infracost/actions/comment@v1
  91. with:
  92. path: /tmp/infracost.json
  93. # Choose the commenting behavior, 'update' is a good default:
  94. behavior: update # Create a single comment and update it. The "quietest" option.
  95. # behavior: delete-and-new # Delete previous comments and create a new one.
  96. # behavior: hide-and-new # Minimize previous comments and create a new one.
  97. # behavior: new # Create a new cost estimate comment on every push.
  98. - name: Apply TF GKE
  99. run: |-
  100. make tf.apply.gcp
  101. - name: Get the GKE credentials
  102. run: |-
  103. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  104. - name: Login to Docker
  105. uses: docker/login-action@v1
  106. if: env.GHCR_USERNAME != ''
  107. with:
  108. registry: ghcr.io
  109. username: ${{ secrets.GHCR_USERNAME }}
  110. password: ${{ secrets.GHCR_TOKEN }}
  111. - name: Run e2e Tests for GCP
  112. run: |
  113. export E2E_VERSION=$GITHUB_SHA
  114. export PR_IMG_TAG=$GITHUB_SHA
  115. export PATH=$PATH:$(go env GOPATH)/bin
  116. go get github.com/onsi/ginkgo/ginkgo
  117. make test.e2e.managed FOCUS="gcpmanaged"
  118. - name: Destroy TF GKE
  119. if: always()
  120. run: |-
  121. make tf.destroy.gcp
  122. # Repo owner has commented /ok-to-test on a (fork-based) pull request
  123. integration-fork-managed:
  124. runs-on: ubuntu-latest
  125. if:
  126. github.event_name == 'repository_dispatch'
  127. steps:
  128. - name: Branch based PR checkout
  129. uses: actions/checkout@v2
  130. # <insert integration tests needing secrets>
  131. - name: Fetch History
  132. run: git fetch --prune --unshallow
  133. - name: Setup Go
  134. uses: actions/setup-go@v2
  135. with:
  136. go-version: ${{ env.GO_VERSION }}
  137. - name: Find the Go Cache
  138. id: go
  139. run: |
  140. echo "::set-output name=build-cache::$(go env GOCACHE)"
  141. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  142. - name: Cache the Go Build Cache
  143. uses: actions/cache@v2.1.7
  144. with:
  145. path: ${{ steps.go.outputs.build-cache }}
  146. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  147. restore-keys: ${{ runner.os }}-build-unit-tests-
  148. - name: Cache Go Dependencies
  149. uses: actions/cache@v2.1.7
  150. with:
  151. path: ${{ steps.go.outputs.mod-cache }}
  152. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  153. restore-keys: ${{ runner.os }}-pkg-
  154. - name: Setup gcloud CLI
  155. uses: google-github-actions/setup-gcloud@master
  156. with:
  157. service_account_key: ${{ env.GCP_SM_SA_GKE_JSON }}
  158. project_id: ${{ env.GCP_PROJECT_ID }}
  159. - name: Setup TFLint
  160. uses: terraform-linters/setup-tflint@v1
  161. with:
  162. tflint_version: v0.28.0 # Must be specified. See: https://github.com/terraform-linters/tflint/releases for latest versions
  163. - name: Run TFLint
  164. 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'
  165. - name: Setup TF Gcloud Provider
  166. run: |-
  167. mkdir -p terraform/gcp/secrets
  168. echo ${GCP_SM_SA_GKE_JSON} > terraform/gcp/secrets/gcloud-service-account-key.json
  169. - name: Show TF GKE
  170. run: |-
  171. make tf.show.gcp
  172. - name: Setup Infracost
  173. uses: infracost/actions/setup@v1
  174. with:
  175. api-key: ${{ secrets.INFRACOST_API_KEY }}
  176. - name: Generate Infracost JSON for GKE
  177. run: infracost breakdown --path terraform/gcp/plan.json --format json --out-file /tmp/infracost.json
  178. - name: Post Infracost comment
  179. uses: infracost/actions/comment@v1
  180. with:
  181. path: /tmp/infracost.json
  182. # Choose the commenting behavior, 'update' is a good default:
  183. behavior: update # Create a single comment and update it. The "quietest" option.
  184. # behavior: delete-and-new # Delete previous comments and create a new one.
  185. # behavior: hide-and-new # Minimize previous comments and create a new one.
  186. # behavior: new # Create a new cost estimate comment on every push.
  187. - name: Apply TF GKE
  188. run: |-
  189. make tf.apply.gcp
  190. - name: Get the GKE credentials
  191. run: |-
  192. gcloud container clusters get-credentials "$GCP_GKE_CLUSTER" --zone "$GCP_GKE_ZONE" --project "$GCP_PROJECT_ID"
  193. - name: Login to Docker
  194. uses: docker/login-action@v1
  195. if: env.GHCR_USERNAME != ''
  196. with:
  197. registry: ghcr.io
  198. username: ${{ secrets.GHCR_USERNAME }}
  199. password: ${{ secrets.GHCR_TOKEN }}
  200. - name: Run e2e Tests for GCP
  201. run: |
  202. export E2E_VERSION=$GITHUB_SHA
  203. export PR_IMG_TAG=$GITHUB_SHA
  204. export PATH=$PATH:$(go env GOPATH)/bin
  205. go get github.com/onsi/ginkgo/ginkgo
  206. make test.e2e.managed FOCUS="gcpmanaged"
  207. - name: Destroy TF GKE
  208. if: always()
  209. run: |-
  210. make tf.destroy.gcp
  211. # Update check run called "integration-fork"
  212. - uses: actions/github-script@v1
  213. id: update-check-run
  214. if: ${{ always() }}
  215. env:
  216. number: ${{ github.event.client_payload.pull_request.number }}
  217. job: ${{ github.job }}
  218. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  219. conclusion: ${{ job.status }}
  220. with:
  221. github-token: ${{ secrets.GITHUB_TOKEN }}
  222. script: |
  223. const { data: pull } = await github.pulls.get({
  224. ...context.repo,
  225. pull_number: process.env.number
  226. });
  227. const ref = pull.head.sha;
  228. console.log("\n\nPR sha: " + ref)
  229. const { data: checks } = await github.checks.listForRef({
  230. ...context.repo,
  231. ref
  232. });
  233. console.log("\n\nPR CHECKS: " + checks)
  234. const check = checks.check_runs.filter(c => c.name === process.env.job);
  235. console.log("\n\nPR Filtered CHECK: " + check)
  236. console.log(check)
  237. const { data: result } = await github.checks.update({
  238. ...context.repo,
  239. check_run_id: check[0].id,
  240. status: 'completed',
  241. conclusion: process.env.conclusion
  242. });
  243. return result;