ci.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - main
  6. - release-*
  7. pull_request: {}
  8. env:
  9. # Common versions
  10. GOLANGCI_VERSION: 'v1.52.2'
  11. KUBERNETES_VERSION: '1.24.x'
  12. # Sonar
  13. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  14. jobs:
  15. detect-noop:
  16. runs-on: ubuntu-latest
  17. outputs:
  18. noop: ${{ steps.noop.outputs.should_skip }}
  19. steps:
  20. - name: Detect No-op Changes
  21. id: noop
  22. uses: fkirc/skip-duplicate-actions@v5.3.0
  23. with:
  24. github_token: ${{ secrets.GITHUB_TOKEN }}
  25. paths_ignore: '["**.md", "**.png", "**.jpg"]'
  26. do_not_skip: '["workflow_dispatch", "schedule", "push"]'
  27. concurrent_skipping: false
  28. lint:
  29. runs-on: ubuntu-latest
  30. needs: detect-noop
  31. if: needs.detect-noop.outputs.noop != 'true'
  32. steps:
  33. - name: Checkout
  34. uses: actions/checkout@v3
  35. - name: Setup Go
  36. uses: actions/setup-go@v4
  37. with:
  38. go-version-file: "go.mod"
  39. - name: Find the Go Cache
  40. id: go
  41. run: |
  42. echo "::set-output name=build-cache::$(go env GOCACHE)"
  43. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  44. - name: Cache the Go Build Cache
  45. uses: actions/cache@v3
  46. with:
  47. path: ${{ steps.go.outputs.build-cache }}
  48. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  49. - name: Cache Go Dependencies
  50. uses: actions/cache@v3
  51. with:
  52. path: ${{ steps.go.outputs.mod-cache }}
  53. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  54. - name: Lint
  55. uses: golangci/golangci-lint-action@v3
  56. with:
  57. version: ${{ env.GOLANGCI_VERSION }}
  58. skip-pkg-cache: true
  59. skip-build-cache: true
  60. check-diff:
  61. runs-on: ubuntu-latest
  62. needs: detect-noop
  63. if: needs.detect-noop.outputs.noop != 'true'
  64. steps:
  65. - name: Checkout
  66. uses: actions/checkout@v3
  67. - name: Configure Git
  68. run: |
  69. git config user.name "$GITHUB_ACTOR"
  70. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  71. - name: Setup Go
  72. uses: actions/setup-go@v4
  73. with:
  74. go-version-file: "go.mod"
  75. - name: Find the Go Cache
  76. id: go
  77. run: |
  78. echo "::set-output name=build-cache::$(go env GOCACHE)"
  79. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  80. - name: Cache the Go Build Cache
  81. uses: actions/cache@v3
  82. with:
  83. path: ${{ steps.go.outputs.build-cache }}
  84. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  85. - name: Cache Go Dependencies
  86. uses: actions/cache@v3
  87. with:
  88. path: ${{ steps.go.outputs.mod-cache }}
  89. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  90. # Check DIff also runs Reviewable which needs golangci-lint installed
  91. - name: Check Diff
  92. run: |
  93. wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${{ env.GOLANGCI_VERSION }}
  94. export PATH=$PATH:./bin
  95. make check-diff
  96. unit-tests:
  97. runs-on: ubuntu-latest
  98. needs: detect-noop
  99. if: needs.detect-noop.outputs.noop != 'true'
  100. steps:
  101. - name: Checkout
  102. uses: actions/checkout@v3
  103. - name: Fetch History
  104. run: git fetch --prune --unshallow
  105. - name: Setup Go
  106. uses: actions/setup-go@v4
  107. with:
  108. go-version-file: "go.mod"
  109. - name: Find the Go Cache
  110. id: go
  111. run: |
  112. echo "::set-output name=build-cache::$(go env GOCACHE)"
  113. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  114. - name: Cache the Go Build Cache
  115. uses: actions/cache@v3
  116. with:
  117. path: ${{ steps.go.outputs.build-cache }}
  118. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  119. - name: Cache Go Dependencies
  120. uses: actions/cache@v3
  121. with:
  122. path: ${{ steps.go.outputs.mod-cache }}
  123. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  124. - name: Add setup-envtest
  125. run: |
  126. go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
  127. setup-envtest use ${{env.KUBERNETES_VERSION}} -p env --os $(go env GOOS) --arch $(go env GOARCH)
  128. - name: Cache envtest binaries
  129. uses: actions/cache@v3
  130. with:
  131. path: /home/runner/.local/share/kubebuilder-envtest/
  132. key: ${{ runner.os }}-kubebuilder-${{env.KUBERNETES_VERSION}}
  133. - name: Run Unit Tests
  134. run: |
  135. export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
  136. source <(setup-envtest use ${{env.KUBERNETES_VERSION}} -p env --os $(go env GOOS) --arch $(go env GOARCH))
  137. make test
  138. publish-artifacts:
  139. needs: detect-noop
  140. if: needs.detect-noop.outputs.noop != 'true'
  141. uses: ./.github/workflows/publish.yml
  142. permissions:
  143. id-token: write
  144. contents: read
  145. strategy:
  146. matrix:
  147. include:
  148. - dockerfile: "Dockerfile"
  149. build-args: "CGO_ENABLED=0"
  150. build-arch: "amd64 arm64"
  151. build-platform: "linux/amd64,linux/arm64"
  152. tag-suffix: "" # distroless
  153. - dockerfile: "Dockerfile.ubi"
  154. build-args: "CGO_ENABLED=0"
  155. build-arch: "amd64 arm64"
  156. build-platform: "linux/amd64,linux/arm64"
  157. tag-suffix: "-ubi"
  158. - dockerfile: "Dockerfile.ubi"
  159. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  160. build-arch: "amd64"
  161. build-platform: "linux/amd64"
  162. tag-suffix: "-ubi-boringssl"
  163. with:
  164. dockerfile: ${{ matrix.dockerfile }}
  165. tag-suffix: ${{ matrix.tag-suffix }}
  166. image-name: ghcr.io/${{ github.repository }}
  167. build-platform: ${{ matrix.build-platform }}
  168. build-args: ${{ matrix.build-args }}
  169. build-arch: ${{ matrix.build-arch }}
  170. ref: ${{ github.ref }}
  171. secrets:
  172. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  173. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}