ci.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
  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@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
  44. with:
  45. egress-policy: audit
  46. - name: Checkout
  47. uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
  48. - name: Setup Go
  49. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.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: Lint
  57. uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0
  58. with:
  59. version: ${{ env.GOLANGCI_VERSION }}
  60. skip-pkg-cache: true
  61. skip-build-cache: true
  62. license-check:
  63. permissions:
  64. contents: read # for actions/checkout to fetch code
  65. pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
  66. runs-on: ubuntu-latest
  67. needs: detect-noop
  68. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  69. steps:
  70. - uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
  71. with:
  72. egress-policy: audit
  73. - name: Checkout
  74. uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
  75. - name: Check License Headers
  76. uses: apache/skywalking-eyes/header@5c5b974209f0de5d905f37deb69369068ebfc15c # v0.7.0
  77. check-diff:
  78. runs-on: ubuntu-latest
  79. needs: detect-noop
  80. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  81. steps:
  82. - uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
  83. with:
  84. egress-policy: audit
  85. - name: Checkout
  86. uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
  87. - uses: hashicorp/setup-terraform@c529327889820530c60b4ce5bbc8d6099e166666 # v3
  88. - name: Setup Go
  89. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
  90. id: setup-go
  91. with:
  92. go-version-file: "go.mod"
  93. - name: Download Go modules
  94. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  95. run: go mod download
  96. - name: Configure Git
  97. run: |
  98. git config user.name "$GITHUB_ACTOR"
  99. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  100. - name: Check Diff
  101. run: |
  102. make check-diff
  103. unit-tests:
  104. runs-on: ubuntu-latest
  105. needs: detect-noop
  106. if: needs.detect-noop.outputs.noop != 'true'
  107. steps:
  108. - uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1
  109. with:
  110. egress-policy: audit
  111. - name: Checkout
  112. uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
  113. - name: Fetch History
  114. run: git fetch --prune --unshallow
  115. - name: Setup Go
  116. uses: actions/setup-go@44694675825211faa026b3c33043df3e48a5fa00 # v6.0.0
  117. id: setup-go
  118. with:
  119. go-version-file: "go.mod"
  120. - name: Download Go modules
  121. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  122. run: go mod download
  123. - name: Cache envtest binaries
  124. uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
  125. with:
  126. path: bin/k8s
  127. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  128. - name: Run Unit Tests
  129. run: |
  130. make test
  131. - name: Publish Unit Test Coverage
  132. uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
  133. env:
  134. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  135. with:
  136. flags: unittests
  137. file: ./cover.out
  138. publish-artifacts:
  139. needs: detect-noop
  140. if: needs.detect-noop.outputs.noop != 'true'
  141. uses: ./.github/workflows/publish.yml
  142. permissions:
  143. contents: read #actions/checkout
  144. packages: write #for publishing artifacts
  145. id-token: write #for keyless sign
  146. strategy:
  147. matrix:
  148. include:
  149. - dockerfile: "Dockerfile"
  150. build-args: "CGO_ENABLED=0"
  151. build-arch: "amd64 arm64 s390x ppc64le"
  152. build-platform: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le"
  153. tag-suffix: "" # distroless
  154. - dockerfile: "Dockerfile.ubi"
  155. build-args: "CGO_ENABLED=0"
  156. build-arch: "amd64 arm64 ppc64le"
  157. build-platform: "linux/amd64,linux/arm64,linux/ppc64le"
  158. tag-suffix: "-ubi"
  159. - dockerfile: "Dockerfile.ubi"
  160. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  161. build-arch: "amd64 ppc64le"
  162. build-platform: "linux/amd64,linux/ppc64le"
  163. tag-suffix: "-ubi-boringssl"
  164. with:
  165. dockerfile: ${{ matrix.dockerfile }}
  166. tag-suffix: ${{ matrix.tag-suffix }}
  167. image-name: ghcr.io/${{ github.repository }}
  168. build-platform: ${{ matrix.build-platform }}
  169. build-args: ${{ matrix.build-args }}
  170. build-arch: ${{ matrix.build-arch }}
  171. ref: ${{ github.ref }}
  172. secrets:
  173. IS_FORK: ${{ secrets.GHCR_USERNAME }} # this is just a secret to verify it is a fork or not, no other utility