ci.yml 7.2 KB

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