ci.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. - name: Check Diff
  91. run: |
  92. make check-diff
  93. unit-tests:
  94. runs-on: ubuntu-latest
  95. needs: detect-noop
  96. if: needs.detect-noop.outputs.noop != 'true'
  97. steps:
  98. - name: Checkout
  99. uses: actions/checkout@v3
  100. - name: Fetch History
  101. run: git fetch --prune --unshallow
  102. - name: Setup Go
  103. uses: actions/setup-go@v4
  104. with:
  105. go-version-file: "go.mod"
  106. - name: Find the Go Cache
  107. id: go
  108. run: |
  109. echo "::set-output name=build-cache::$(go env GOCACHE)"
  110. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  111. - name: Cache the Go Build Cache
  112. uses: actions/cache@v3
  113. with:
  114. path: ${{ steps.go.outputs.build-cache }}
  115. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  116. - name: Cache Go Dependencies
  117. uses: actions/cache@v3
  118. with:
  119. path: ${{ steps.go.outputs.mod-cache }}
  120. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  121. - name: Cache envtest binaries
  122. uses: actions/cache@v3
  123. with:
  124. path: bin/k8s
  125. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  126. - name: Run Unit Tests
  127. run: |
  128. make test
  129. publish-artifacts:
  130. needs: detect-noop
  131. if: needs.detect-noop.outputs.noop != 'true'
  132. uses: ./.github/workflows/publish.yml
  133. permissions:
  134. id-token: write
  135. contents: read
  136. strategy:
  137. matrix:
  138. include:
  139. - dockerfile: "Dockerfile"
  140. build-args: "CGO_ENABLED=0"
  141. build-arch: "amd64 arm64"
  142. build-platform: "linux/amd64,linux/arm64"
  143. tag-suffix: "" # distroless
  144. - dockerfile: "Dockerfile.ubi"
  145. build-args: "CGO_ENABLED=0"
  146. build-arch: "amd64 arm64"
  147. build-platform: "linux/amd64,linux/arm64"
  148. tag-suffix: "-ubi"
  149. - dockerfile: "Dockerfile.ubi"
  150. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  151. build-arch: "amd64"
  152. build-platform: "linux/amd64"
  153. tag-suffix: "-ubi-boringssl"
  154. with:
  155. dockerfile: ${{ matrix.dockerfile }}
  156. tag-suffix: ${{ matrix.tag-suffix }}
  157. image-name: ghcr.io/${{ github.repository }}
  158. build-platform: ${{ matrix.build-platform }}
  159. build-args: ${{ matrix.build-args }}
  160. build-arch: ${{ matrix.build-arch }}
  161. ref: ${{ github.ref }}
  162. secrets:
  163. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  164. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}