ci.yml 5.5 KB

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