ci.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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.42.1'
  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. # Check DIff also runs Reviewable which needs golangci-lint installed
  105. - name: Check Diff
  106. run: |
  107. wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.42.1
  108. export PATH=$PATH:./bin
  109. make check-diff
  110. unit-tests:
  111. runs-on: ubuntu-18.04
  112. needs: detect-noop
  113. if: needs.detect-noop.outputs.noop != 'true'
  114. steps:
  115. - name: Checkout
  116. uses: actions/checkout@v2
  117. - name: Fetch History
  118. run: git fetch --prune --unshallow
  119. - name: Setup Go
  120. uses: actions/setup-go@v2
  121. with:
  122. go-version: ${{ env.GO_VERSION }}
  123. - name: Find the Go Cache
  124. id: go
  125. run: |
  126. echo "::set-output name=build-cache::$(go env GOCACHE)"
  127. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  128. - name: Cache the Go Build Cache
  129. uses: actions/cache@v2.1.6
  130. with:
  131. path: ${{ steps.go.outputs.build-cache }}
  132. key: ${{ runner.os }}-build-unit-tests-${{ hashFiles('**/go.sum') }}
  133. restore-keys: ${{ runner.os }}-build-unit-tests-
  134. - name: Cache Go Dependencies
  135. uses: actions/cache@v2.1.6
  136. with:
  137. path: ${{ steps.go.outputs.mod-cache }}
  138. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  139. restore-keys: ${{ runner.os }}-pkg-
  140. - name: Add envtest binaries
  141. run: |
  142. curl -sSLo envtest-bins.tar.gz "https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${{env.KUBEBUILDER_TOOLS_VERSION}}-linux-amd64.tar.gz"
  143. sudo mkdir -p /usr/local/kubebuilder
  144. sudo tar -C /usr/local/kubebuilder --strip-components=1 -zvxf envtest-bins.tar.gz
  145. - name: Cache envtest binaries
  146. uses: actions/cache@v2.1.6
  147. with:
  148. path: /usr/local/kubebuilder
  149. key: ${{ runner.os }}-kubebuilder-${{env.KUBEBUILDER_TOOLS_VERSION}}
  150. restore-keys: ${{ runner.os }}-kubebuilder-
  151. - name: Run Unit Tests
  152. run: |
  153. export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
  154. make test
  155. publish-artifacts:
  156. runs-on: ubuntu-18.04
  157. needs: detect-noop
  158. if: needs.detect-noop.outputs.noop != 'true'
  159. steps:
  160. - name: Setup QEMU
  161. uses: docker/setup-qemu-action@v1
  162. with:
  163. platforms: all
  164. - name: Setup Docker Buildx
  165. uses: docker/setup-buildx-action@v1
  166. with:
  167. version: ${{ env.DOCKER_BUILDX_VERSION }}
  168. install: true
  169. - name: Checkout
  170. uses: actions/checkout@v2
  171. - name: Fetch History
  172. run: git fetch --prune --unshallow
  173. - name: Setup Go
  174. uses: actions/setup-go@v2
  175. with:
  176. go-version: ${{ env.GO_VERSION }}
  177. - name: Find the Go Cache
  178. id: go
  179. run: |
  180. echo "::set-output name=build-cache::$(go env GOCACHE)"
  181. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  182. - name: Cache the Go Build Cache
  183. uses: actions/cache@v2.1.6
  184. with:
  185. path: ${{ steps.go.outputs.build-cache }}
  186. key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }}
  187. restore-keys: ${{ runner.os }}-build-publish-artifacts-
  188. - name: Cache Go Dependencies
  189. uses: actions/cache@v2.1.6
  190. with:
  191. path: ${{ steps.go.outputs.mod-cache }}
  192. key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }}
  193. restore-keys: ${{ runner.os }}-pkg-
  194. - name: Login to Docker
  195. uses: docker/login-action@v1
  196. if: env.GHCR_USERNAME != ''
  197. with:
  198. registry: ghcr.io
  199. username: ${{ secrets.GHCR_USERNAME }}
  200. password: ${{ secrets.GHCR_TOKEN }}
  201. - name: Build & Publish Artifacts
  202. if: env.GHCR_USERNAME != ''
  203. env:
  204. BUILD_ARGS: "--push --platform linux/amd64,linux/arm64"
  205. run: make docker.build
  206. - name: Promote Artifacts to main release channel
  207. if: github.ref == 'refs/heads/main' && env.GHCR_USERNAME != ''
  208. run: make docker.promote
  209. env:
  210. RELEASE_TAG: main