ci.yml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request: {}
  7. env:
  8. # Common versions
  9. GOLANGCI_VERSION: 'v2.4.0'
  10. KUBERNETES_VERSION: '1.33.x'
  11. # Sonar
  12. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  13. jobs:
  14. detect-noop:
  15. permissions:
  16. actions: write # for fkirc/skip-duplicate-actions to skip or stop workflow runs
  17. contents: read # for fkirc/skip-duplicate-actions to read and compare commits
  18. runs-on: ubuntu-latest
  19. outputs:
  20. noop: ${{ steps.noop.outputs.should_skip }}
  21. steps:
  22. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  23. with:
  24. egress-policy: audit
  25. - name: Detect No-op Changes
  26. id: noop
  27. uses: fkirc/skip-duplicate-actions@f75f66ce1886f00957d99748a42c724f4330bdcf # v5.3.1
  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. permissions:
  35. contents: read # for actions/checkout to fetch code
  36. pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
  37. runs-on: ubuntu-latest
  38. needs: detect-noop
  39. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  40. steps:
  41. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  42. with:
  43. egress-policy: audit
  44. - name: Checkout
  45. uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
  46. - name: Setup Go
  47. uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
  48. id: setup-go
  49. with:
  50. go-version-file: "go.mod"
  51. - name: Download Go modules
  52. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  53. run: go mod download
  54. - name: Run lint
  55. run: make lint
  56. license-check:
  57. permissions:
  58. contents: read # for actions/checkout to fetch code
  59. pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
  60. runs-on: ubuntu-latest
  61. needs: detect-noop
  62. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  63. steps:
  64. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  65. with:
  66. egress-policy: audit
  67. - name: Checkout
  68. uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
  69. - name: Check License Headers
  70. uses: apache/skywalking-eyes/header@61275cc80d0798a405cb070f7d3a8aaf7cf2c2c1 # v0.8.0
  71. check-diff:
  72. runs-on: ubuntu-latest
  73. needs: detect-noop
  74. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  75. steps:
  76. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  77. with:
  78. egress-policy: audit
  79. - name: Checkout
  80. uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
  81. - uses: hashicorp/setup-terraform@92e4d08fe1d24283952afa28216efa8f4ed5aeab # v3
  82. - name: Setup Go
  83. uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
  84. id: setup-go
  85. with:
  86. go-version-file: "go.mod"
  87. - name: Download Go modules
  88. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  89. run: go mod download
  90. - name: Configure Git
  91. run: |
  92. git config user.name "$GITHUB_ACTOR"
  93. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  94. - name: Check Diff
  95. run: |
  96. make check-diff
  97. unit-tests:
  98. runs-on: ubuntu-latest
  99. needs: detect-noop
  100. if: needs.detect-noop.outputs.noop != 'true'
  101. steps:
  102. - uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0
  103. with:
  104. egress-policy: audit
  105. - name: Checkout
  106. uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
  107. - name: Fetch History
  108. run: git fetch --prune --unshallow
  109. - name: Setup Go
  110. uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
  111. id: setup-go
  112. with:
  113. go-version-file: "go.mod"
  114. - name: Download Go modules
  115. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  116. run: go mod download
  117. - name: Cache envtest binaries
  118. uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
  119. with:
  120. path: bin/k8s
  121. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  122. - name: Run Unit Tests
  123. run: |
  124. make test
  125. - name: Publish Unit Test Coverage
  126. uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
  127. env:
  128. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  129. with:
  130. flags: unittests
  131. file: ./cover.out
  132. publish-artifacts:
  133. needs: detect-noop
  134. if: needs.detect-noop.outputs.noop != 'true'
  135. uses: ./.github/workflows/publish.yml
  136. permissions:
  137. contents: read #actions/checkout
  138. packages: write #for publishing artifacts
  139. id-token: write #for keyless sign
  140. strategy:
  141. matrix:
  142. include:
  143. - dockerfile: "Dockerfile"
  144. build-args: "CGO_ENABLED=0"
  145. build-arch: "amd64 arm64 s390x ppc64le"
  146. build-platform: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le"
  147. tag-suffix: "" # distroless
  148. - dockerfile: "Dockerfile.ubi"
  149. build-args: "CGO_ENABLED=0"
  150. build-arch: "amd64 arm64 ppc64le"
  151. build-platform: "linux/amd64,linux/arm64,linux/ppc64le"
  152. tag-suffix: "-ubi"
  153. - dockerfile: "Dockerfile.ubi"
  154. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  155. build-arch: "amd64 ppc64le"
  156. build-platform: "linux/amd64,linux/ppc64le"
  157. tag-suffix: "-ubi-boringssl"
  158. with:
  159. dockerfile: ${{ matrix.dockerfile }}
  160. tag-suffix: ${{ matrix.tag-suffix }}
  161. image-name: ghcr.io/${{ github.repository }}
  162. build-platform: ${{ matrix.build-platform }}
  163. build-args: ${{ matrix.build-args }}
  164. build-arch: ${{ matrix.build-arch }}
  165. ref: ${{ github.ref }}
  166. secrets:
  167. IS_FORK: ${{ secrets.GHCR_USERNAME }} # this is just a secret to verify it is a fork or not, no other utility