e2e.yml 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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.15'
  9. GOLANGCI_VERSION: 'v1.33'
  10. KUBEBUILDER_VERSION: '2.3.1'
  11. DOCKER_BUILDX_VERSION: 'v0.4.2'
  12. # Common users. We can't run a step 'if secrets.GHCR_USERNAME != ""' but we can run
  13. # a step 'if env.GHCR_USERNAME' != ""', so we copy these to succinctly test whether
  14. # credentials have been provided before trying to run steps that need them.
  15. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  16. name: e2e tests
  17. jobs:
  18. # Branch-based pull request
  19. integration-trusted:
  20. runs-on: ubuntu-latest
  21. if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
  22. steps:
  23. - name: Branch based PR checkout
  24. uses: actions/checkout@v2
  25. # <insert integration tests needing secrets>
  26. - name: Fetch History
  27. run: git fetch --prune --unshallow
  28. - name: Setup Go
  29. uses: actions/setup-go@v2
  30. with:
  31. go-version: ${{ env.GO_VERSION }}
  32. - name: Find the Go Cache
  33. id: go
  34. run: |
  35. echo "::set-output name=build-cache::$(go env GOCACHE)"
  36. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  37. - name: Cache the Go Build Cache
  38. uses: actions/cache@v2.1.6
  39. with:
  40. path: ${{ steps.go.outputs.build-cache }}
  41. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  42. restore-keys: ${{ runner.os }}-build-unit-tests-
  43. - name: Cache Go Dependencies
  44. uses: actions/cache@v2.1.6
  45. with:
  46. path: ${{ steps.go.outputs.mod-cache }}
  47. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  48. restore-keys: ${{ runner.os }}-pkg-
  49. - name: Add kubebuilder
  50. run: |
  51. curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${{env.KUBEBUILDER_VERSION}}/kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz > kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  52. tar -xvf kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  53. sudo mv kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64 /usr/local/kubebuilder
  54. - name: Cache kubebuilder
  55. uses: actions/cache@v2.1.6
  56. with:
  57. path: /usr/local/kubebuilder
  58. key: ${{ runner.os }}-kubebuilder-${{env.KUBEBUILDER_VERSION}}
  59. restore-keys: ${{ runner.os }}-kubebuilder-
  60. - name: Setup kind
  61. uses: engineerd/setup-kind@v0.5.0
  62. with:
  63. version: "v0.10.0"
  64. node_image: kindest/node:v1.20.2
  65. name: external-secrets
  66. - name: Run e2e Tests
  67. run: |
  68. export PATH=$PATH:$(go env GOPATH)/bin
  69. go get github.com/onsi/ginkgo/ginkgo
  70. make test.e2e
  71. # Repo owner has commented /ok-to-test on a (fork-based) pull request
  72. integration-fork:
  73. runs-on: ubuntu-latest
  74. if:
  75. github.event_name == 'repository_dispatch' &&
  76. github.event.client_payload.slash_command.sha != '' &&
  77. contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha)
  78. steps:
  79. # Check out merge commit
  80. - name: Fork based /ok-to-test checkout
  81. uses: actions/checkout@v2
  82. with:
  83. ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge'
  84. - name: Fetch History
  85. run: git fetch --prune --unshallow
  86. - name: Setup Go
  87. uses: actions/setup-go@v2
  88. with:
  89. go-version: ${{ env.GO_VERSION }}
  90. - name: Find the Go Cache
  91. id: go
  92. run: |
  93. echo "::set-output name=build-cache::$(go env GOCACHE)"
  94. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  95. - name: Cache the Go Build Cache
  96. uses: actions/cache@v2.1.6
  97. with:
  98. path: ${{ steps.go.outputs.build-cache }}
  99. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  100. restore-keys: ${{ runner.os }}-build-unit-tests-
  101. - name: Cache Go Dependencies
  102. uses: actions/cache@v2.1.6
  103. with:
  104. path: ${{ steps.go.outputs.mod-cache }}
  105. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  106. restore-keys: ${{ runner.os }}-pkg-
  107. - name: Add kubebuilder
  108. run: |
  109. curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${{env.KUBEBUILDER_VERSION}}/kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz > kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  110. tar -xvf kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64.tar.gz
  111. sudo mv kubebuilder_${{env.KUBEBUILDER_VERSION}}_linux_amd64 /usr/local/kubebuilder
  112. - name: Cache kubebuilder
  113. uses: actions/cache@v2.1.6
  114. with:
  115. path: /usr/local/kubebuilder
  116. key: ${{ runner.os }}-kubebuilder-${{env.KUBEBUILDER_VERSION}}
  117. restore-keys: ${{ runner.os }}-kubebuilder-
  118. - name: Setup kind
  119. uses: engineerd/setup-kind@v0.5.0
  120. with:
  121. version: "v0.10.0"
  122. node_image: kindest/node:v1.20.2
  123. name: external-secrets
  124. - name: Run e2e Tests
  125. run: |
  126. export PATH=$PATH:$(go env GOPATH)/bin
  127. go get github.com/onsi/ginkgo/ginkgo
  128. make test.e2e
  129. # Update check run called "integration-fork"
  130. - uses: actions/github-script@v1
  131. id: update-check-run
  132. if: ${{ always() }}
  133. env:
  134. number: ${{ github.event.client_payload.pull_request.number }}
  135. job: ${{ github.job }}
  136. # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run
  137. conclusion: ${{ job.status }}
  138. with:
  139. github-token: ${{ secrets.GITHUB_TOKEN }}
  140. script: |
  141. const { data: pull } = await github.pulls.get({
  142. ...context.repo,
  143. pull_number: process.env.number
  144. });
  145. const ref = pull.head.sha;
  146. const { data: checks } = await github.checks.listForRef({
  147. ...context.repo,
  148. ref
  149. });
  150. const check = checks.check_runs.filter(c => c.name === process.env.job);
  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;