ci.yml 5.7 KB

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