ci.yml 6.3 KB

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