ci.yml 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. # Sonar
  22. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  23. jobs:
  24. detect-noop:
  25. runs-on: ubuntu-18.04
  26. outputs:
  27. noop: ${{ steps.noop.outputs.should_skip }}
  28. steps:
  29. - name: Detect No-op Changes
  30. id: noop
  31. uses: fkirc/skip-duplicate-actions@v3.4.1
  32. with:
  33. github_token: ${{ secrets.GITHUB_TOKEN }}
  34. paths_ignore: '["**.md", "**.png", "**.jpg"]'
  35. do_not_skip: '["workflow_dispatch", "schedule", "push"]'
  36. concurrent_skipping: false
  37. lint:
  38. runs-on: ubuntu-18.04
  39. needs: detect-noop
  40. if: needs.detect-noop.outputs.noop != 'true'
  41. steps:
  42. - name: Checkout
  43. uses: actions/checkout@v2
  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.6
  55. with:
  56. path: ${{ steps.go.outputs.build-cache }}
  57. key: ${{ runner.os }}-build-lint-${{ hashFiles('**/go.sum') }}
  58. restore-keys: ${{ runner.os }}-build-lint-
  59. - name: Cache Go Dependencies
  60. uses: actions/cache@v2.1.6
  61. with:
  62. path: ${{ steps.go.outputs.mod-cache }}
  63. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  64. restore-keys: ${{ runner.os }}-pkg-
  65. # This action uses its own setup-go, which always seems to use the latest
  66. # stable version of Go. We could run 'make lint' to ensure our desired Go
  67. # version, but we prefer this action because it leaves 'annotations' (i.e.
  68. # it comments on PRs to point out linter violations).
  69. - name: Lint
  70. uses: golangci/golangci-lint-action@v2
  71. with:
  72. version: ${{ env.GOLANGCI_VERSION }}
  73. skip-pkg-cache: true
  74. skip-build-cache: true
  75. skip-go-installation: true
  76. check-diff:
  77. runs-on: ubuntu-18.04
  78. needs: detect-noop
  79. if: needs.detect-noop.outputs.noop != 'true'
  80. steps:
  81. - name: Checkout
  82. uses: actions/checkout@v2
  83. - name: Setup Go
  84. uses: actions/setup-go@v2
  85. with:
  86. go-version: ${{ env.GO_VERSION }}
  87. - name: Find the Go Cache
  88. id: go
  89. run: |
  90. echo "::set-output name=build-cache::$(go env GOCACHE)"
  91. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  92. - name: Cache the Go Build Cache
  93. uses: actions/cache@v2.1.6
  94. with:
  95. path: ${{ steps.go.outputs.build-cache }}
  96. key: ${{ runner.os }}-build-check-diff-${{ hashFiles('**/go.sum') }}
  97. restore-keys: ${{ runner.os }}-build-check-diff-
  98. - name: Cache Go Dependencies
  99. uses: actions/cache@v2.1.6
  100. with:
  101. path: ${{ steps.go.outputs.mod-cache }}
  102. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  103. restore-keys: ${{ runner.os }}-pkg-
  104. - name: Check Diff
  105. run: make check-diff
  106. unit-tests:
  107. runs-on: ubuntu-18.04
  108. needs: detect-noop
  109. if: needs.detect-noop.outputs.noop != 'true'
  110. steps:
  111. - name: Checkout
  112. uses: actions/checkout@v2
  113. - name: Fetch History
  114. run: git fetch --prune --unshallow
  115. - name: Setup Go
  116. uses: actions/setup-go@v2
  117. with:
  118. go-version: ${{ env.GO_VERSION }}
  119. - name: Find the Go Cache
  120. id: go
  121. run: |
  122. echo "::set-output name=build-cache::$(go env GOCACHE)"
  123. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  124. - name: Cache the Go Build Cache
  125. uses: actions/cache@v2.1.6
  126. with:
  127. path: ${{ steps.go.outputs.build-cache }}
  128. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  129. restore-keys: ${{ runner.os }}-build-unit-tests-
  130. - name: Cache Go Dependencies
  131. uses: actions/cache@v2.1.6
  132. with:
  133. path: ${{ steps.go.outputs.mod-cache }}
  134. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  135. restore-keys: ${{ runner.os }}-pkg-
  136. - name: Add envtest binaries
  137. run: |
  138. curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${{env.KUBEBUILDER_TOOLS_VERSION}}-linux-amd64.tar.gz"
  139. sudo mkdir -p /usr/local/kubebuilder
  140. sudo tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz
  141. - name: Cache envtest binaries
  142. uses: actions/cache@v2.1.6
  143. with:
  144. path: /usr/local/kubebuilder
  145. key: ${{ runner.os }}-kubebuilder-${{env.KUBEBUILDER_TOOLS_VERSION}}
  146. restore-keys: ${{ runner.os }}-kubebuilder-
  147. - name: Run Unit Tests
  148. run: |
  149. export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
  150. make test
  151. publish-artifacts:
  152. runs-on: ubuntu-18.04
  153. needs: detect-noop
  154. if: needs.detect-noop.outputs.noop != 'true'
  155. steps:
  156. - name: Setup QEMU
  157. uses: docker/setup-qemu-action@v1
  158. with:
  159. platforms: all
  160. - name: Setup Docker Buildx
  161. uses: docker/setup-buildx-action@v1
  162. with:
  163. version: ${{ env.DOCKER_BUILDX_VERSION }}
  164. install: true
  165. - name: Checkout
  166. uses: actions/checkout@v2
  167. - name: Fetch History
  168. run: git fetch --prune --unshallow
  169. - name: Setup Go
  170. uses: actions/setup-go@v2
  171. with:
  172. go-version: ${{ env.GO_VERSION }}
  173. - name: Find the Go Cache
  174. id: go
  175. run: |
  176. echo "::set-output name=build-cache::$(go env GOCACHE)"
  177. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  178. - name: Cache the Go Build Cache
  179. uses: actions/cache@v2.1.6
  180. with:
  181. path: ${{ steps.go.outputs.build-cache }}
  182. key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
  183. restore-keys: ${{ runner.os }}-build-publish-artifacts-
  184. - name: Cache Go Dependencies
  185. uses: actions/cache@v2.1.6
  186. with:
  187. path: ${{ steps.go.outputs.mod-cache }}
  188. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  189. restore-keys: ${{ runner.os }}-pkg-
  190. - name: Login to Docker
  191. uses: docker/login-action@v1
  192. if: env.GHCR_USERNAME != ''
  193. with:
  194. registry: ghcr.io
  195. username: ${{ secrets.GHCR_USERNAME }}
  196. password: ${{ secrets.GHCR_TOKEN }}
  197. - name: Build & Publish Artifacts
  198. if: env.GHCR_USERNAME != ''
  199. env:
  200. BUILD_ARGS: "--push --platform linux/amd64,linux/arm64"
  201. run: make docker.build
  202. - name: Promote Artifacts to main release channel
  203. if: github.ref == 'refs/heads/main' && env.GHCR_USERNAME != ''
  204. run: make docker.promote
  205. env:
  206. RELEASE_TAG: main