ci.yml 5.5 KB

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