ci.yml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  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. license-check:
  36. permissions:
  37. contents: read
  38. runs-on: ubuntu-latest
  39. needs: detect-noop
  40. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  41. steps:
  42. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  43. with:
  44. egress-policy: audit
  45. - name: Checkout
  46. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  47. - name: Check License Headers
  48. uses: apache/skywalking-eyes/header@61275cc80d0798a405cb070f7d3a8aaf7cf2c2c1 # v0.8.0
  49. check-diff:
  50. runs-on: ubuntu-latest
  51. needs: detect-noop
  52. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  53. permissions:
  54. contents: read
  55. steps:
  56. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  57. with:
  58. egress-policy: audit
  59. - name: Checkout
  60. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  61. - uses: hashicorp/setup-terraform@5e8dbf3c6d9deaf4193ca7a8fb23f2ac83bb6c85 # v3
  62. - name: Setup Go
  63. uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
  64. id: setup-go
  65. with:
  66. go-version-file: "go.mod"
  67. - name: Download Go modules
  68. run: go mod download
  69. - name: Configure Git
  70. run: |
  71. git config user.name "$GITHUB_ACTOR"
  72. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  73. - name: Check Diff
  74. env:
  75. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  76. run: |
  77. # make check-diff will also execute linting so there is no need for a separate lint action
  78. make check-diff LINT_JOBS=2
  79. unit-tests:
  80. runs-on: ubuntu-latest
  81. needs: detect-noop
  82. if: needs.detect-noop.outputs.noop != 'true'
  83. permissions:
  84. contents: read
  85. steps:
  86. - uses: step-security/harden-runner@a90bcbc6539c36a85cdfeb73f7e2f433735f215b # v2.15.0
  87. with:
  88. egress-policy: audit
  89. - name: Checkout
  90. uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
  91. - name: Fetch History
  92. run: git fetch --prune --unshallow
  93. - name: Setup Go
  94. uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
  95. id: setup-go
  96. with:
  97. go-version-file: "go.mod"
  98. - name: Download Go modules
  99. run: go mod download
  100. - name: Cache envtest binaries
  101. uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
  102. with:
  103. path: bin/k8s
  104. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  105. - name: Run Unit Tests
  106. run: |
  107. make test
  108. - name: Publish Unit Test Coverage
  109. uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de # v5.5.2
  110. env:
  111. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  112. with:
  113. flags: unittests
  114. file: ./cover.out
  115. publish-artifacts:
  116. needs: detect-noop
  117. if: needs.detect-noop.outputs.noop != 'true'
  118. uses: ./.github/workflows/publish.yml
  119. permissions:
  120. contents: read #actions/checkout
  121. packages: write #for publishing artifacts
  122. id-token: write #for keyless sign
  123. strategy:
  124. matrix:
  125. include:
  126. - dockerfile: "Dockerfile"
  127. build-args: "CGO_ENABLED=0"
  128. build-arch: "amd64 arm64 s390x ppc64le"
  129. build-platform: "linux/amd64,linux/arm64,linux/s390x,linux/ppc64le"
  130. tag-suffix: "" # distroless
  131. - dockerfile: "Dockerfile.ubi"
  132. build-args: "CGO_ENABLED=0"
  133. build-arch: "amd64 arm64 ppc64le"
  134. build-platform: "linux/amd64,linux/arm64,linux/ppc64le"
  135. tag-suffix: "-ubi"
  136. - dockerfile: "Dockerfile.ubi"
  137. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  138. build-arch: "amd64 arm64 ppc64le"
  139. build-platform: "linux/amd64,linux/arm64,linux/ppc64le"
  140. tag-suffix: "-ubi-boringssl"
  141. with:
  142. dockerfile: ${{ matrix.dockerfile }}
  143. tag-suffix: ${{ matrix.tag-suffix }}
  144. image-name: ghcr.io/${{ github.repository }}
  145. build-platform: ${{ matrix.build-platform }}
  146. build-args: ${{ matrix.build-args }}
  147. build-arch: ${{ matrix.build-arch }}
  148. ref: ${{ github.ref }}
  149. secrets:
  150. IS_FORK: ${{ secrets.GHCR_USERNAME }} # this is just a secret to verify it is a fork or not, no other utility