ci.yml 5.4 KB

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