ci.yml 6.0 KB

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