ci.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - main
  6. - release-*
  7. pull_request: {}
  8. workflow_dispatch: {}
  9. env:
  10. # Common versions
  11. GO_VERSION: '1.16'
  12. GOLANGCI_VERSION: 'v1.33'
  13. # list of available versions: https://storage.googleapis.com/kubebuilder-tools
  14. # TODO: 1.21.2 does not shut down properly with controller-runtime 0.9.2
  15. KUBEBUILDER_TOOLS_VERSION: '1.20.2'
  16. DOCKER_BUILDX_VERSION: 'v0.4.2'
  17. # Common users. We can't run a step 'if secrets.GHCR_USERNAME != ""' but we can run
  18. # a step 'if env.GHCR_USERNAME' != ""', so we copy these to succinctly test whether
  19. # credentials have been provided before trying to run steps that need them.
  20. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  21. jobs:
  22. detect-noop:
  23. runs-on: ubuntu-18.04
  24. outputs:
  25. noop: ${{ steps.noop.outputs.should_skip }}
  26. steps:
  27. - name: Detect No-op Changes
  28. id: noop
  29. uses: fkirc/skip-duplicate-actions@v3.4.1
  30. with:
  31. github_token: ${{ secrets.GITHUB_TOKEN }}
  32. paths_ignore: '["**.md", "**.png", "**.jpg"]'
  33. do_not_skip: '["workflow_dispatch", "schedule", "push"]'
  34. concurrent_skipping: false
  35. lint:
  36. runs-on: ubuntu-18.04
  37. needs: detect-noop
  38. if: needs.detect-noop.outputs.noop != 'true'
  39. steps:
  40. - name: Checkout
  41. uses: actions/checkout@v2
  42. - name: Setup Go
  43. uses: actions/setup-go@v2
  44. with:
  45. go-version: ${{ env.GO_VERSION }}
  46. - name: Find the Go Cache
  47. id: go
  48. run: |
  49. echo "::set-output name=build-cache::$(go env GOCACHE)"
  50. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  51. - name: Cache the Go Build Cache
  52. uses: actions/cache@v2.1.6
  53. with:
  54. path: ${{ steps.go.outputs.build-cache }}
  55. key: ${{ runner.os }}-build-lint-${{ hashFiles('**/go.sum') }}
  56. restore-keys: ${{ runner.os }}-build-lint-
  57. - name: Cache Go Dependencies
  58. uses: actions/cache@v2.1.6
  59. with:
  60. path: ${{ steps.go.outputs.mod-cache }}
  61. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  62. restore-keys: ${{ runner.os }}-pkg-
  63. # This action uses its own setup-go, which always seems to use the latest
  64. # stable version of Go. We could run 'make lint' to ensure our desired Go
  65. # version, but we prefer this action because it leaves 'annotations' (i.e.
  66. # it comments on PRs to point out linter violations).
  67. - name: Lint
  68. uses: golangci/golangci-lint-action@v2
  69. with:
  70. version: ${{ env.GOLANGCI_VERSION }}
  71. skip-pkg-cache: true
  72. skip-build-cache: true
  73. skip-go-installation: true
  74. check-diff:
  75. runs-on: ubuntu-18.04
  76. needs: detect-noop
  77. if: needs.detect-noop.outputs.noop != 'true'
  78. steps:
  79. - name: Checkout
  80. uses: actions/checkout@v2
  81. - name: Setup Go
  82. uses: actions/setup-go@v2
  83. with:
  84. go-version: ${{ env.GO_VERSION }}
  85. - name: Find the Go Cache
  86. id: go
  87. run: |
  88. echo "::set-output name=build-cache::$(go env GOCACHE)"
  89. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  90. - name: Cache the Go Build Cache
  91. uses: actions/cache@v2.1.6
  92. with:
  93. path: ${{ steps.go.outputs.build-cache }}
  94. key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }}
  95. restore-keys: ${{ runner.os }}-build-check-diff-
  96. - name: Cache Go Dependencies
  97. uses: actions/cache@v2.1.6
  98. with:
  99. path: ${{ steps.go.outputs.mod-cache }}
  100. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  101. restore-keys: ${{ runner.os }}-pkg-
  102. - name: Check Diff
  103. run: make check-diff
  104. unit-tests:
  105. runs-on: ubuntu-18.04
  106. needs: detect-noop
  107. if: needs.detect-noop.outputs.noop != 'true'
  108. steps:
  109. - name: Checkout
  110. uses: actions/checkout@v2
  111. - name: Fetch History
  112. run: git fetch --prune --unshallow
  113. - name: Setup Go
  114. uses: actions/setup-go@v2
  115. with:
  116. go-version: ${{ env.GO_VERSION }}
  117. - name: Find the Go Cache
  118. id: go
  119. run: |
  120. echo "::set-output name=build-cache::$(go env GOCACHE)"
  121. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  122. - name: Cache the Go Build Cache
  123. uses: actions/cache@v2.1.6
  124. with:
  125. path: ${{ steps.go.outputs.build-cache }}
  126. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  127. restore-keys: ${{ runner.os }}-build-unit-tests-
  128. - name: Cache Go Dependencies
  129. uses: actions/cache@v2.1.6
  130. with:
  131. path: ${{ steps.go.outputs.mod-cache }}
  132. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  133. restore-keys: ${{ runner.os }}-pkg-
  134. - name: Add envtest binaries
  135. run: |
  136. curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${{env.KUBEBUILDER_TOOLS_VERSION}}-linux-amd64.tar.gz"
  137. sudo mkdir -p /usr/local/kubebuilder
  138. sudo tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz
  139. - name: Cache envtest binaries
  140. uses: actions/cache@v2.1.6
  141. with:
  142. path: /usr/local/kubebuilder
  143. key: ${{ runner.os }}-kubebuilder-${{env.KUBEBUILDER_TOOLS_VERSION}}
  144. restore-keys: ${{ runner.os }}-kubebuilder-
  145. - name: Run Unit Tests
  146. run: |
  147. export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
  148. make test
  149. - name: Publish Unit Test Coverage
  150. uses: codecov/codecov-action@v2.0.2
  151. with:
  152. flags: unittests
  153. file: ./cover.out
  154. publish-artifacts:
  155. runs-on: ubuntu-18.04
  156. needs: detect-noop
  157. if: needs.detect-noop.outputs.noop != 'true'
  158. steps:
  159. - name: Setup QEMU
  160. uses: docker/setup-qemu-action@v1
  161. with:
  162. platforms: all
  163. - name: Setup Docker Buildx
  164. uses: docker/setup-buildx-action@v1
  165. with:
  166. version: ${{ env.DOCKER_BUILDX_VERSION }}
  167. install: true
  168. - name: Checkout
  169. uses: actions/checkout@v2
  170. - name: Fetch History
  171. run: git fetch --prune --unshallow
  172. - name: Setup Go
  173. uses: actions/setup-go@v2
  174. with:
  175. go-version: ${{ env.GO_VERSION }}
  176. - name: Find the Go Cache
  177. id: go
  178. run: |
  179. echo "::set-output name=build-cache::$(go env GOCACHE)"
  180. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  181. - name: Cache the Go Build Cache
  182. uses: actions/cache@v2.1.6
  183. with:
  184. path: ${{ steps.go.outputs.build-cache }}
  185. key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
  186. restore-keys: ${{ runner.os }}-build-publish-artifacts-
  187. - name: Cache Go Dependencies
  188. uses: actions/cache@v2.1.6
  189. with:
  190. path: ${{ steps.go.outputs.mod-cache }}
  191. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  192. restore-keys: ${{ runner.os }}-pkg-
  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: Build & Publish Artifacts
  201. if: env.GHCR_USERNAME != ''
  202. env:
  203. BUILD_ARGS: "--push --platform linux/amd64,linux/arm64"
  204. run: make docker.build
  205. - name: Promote Artifacts to main release channel
  206. if: github.ref == 'refs/heads/main' && env.GHCR_USERNAME != ''
  207. run: make docker.promote
  208. env:
  209. RELEASE_TAG: main