ci.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - main
  6. - release-*
  7. pull_request: {}
  8. env:
  9. # Common versions
  10. GOLANGCI_VERSION: 'v1.61.0'
  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. - 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. lint:
  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. - name: Checkout
  42. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  43. - name: Setup Go
  44. uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
  45. id: setup-go
  46. with:
  47. go-version-file: "go.mod"
  48. - name: Download Go modules
  49. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  50. run: go mod download
  51. - name: Lint
  52. uses: golangci/golangci-lint-action@2226d7cb06a077cd73e56eedd38eecad18e5d837 # v6.5.0
  53. with:
  54. version: ${{ env.GOLANGCI_VERSION }}
  55. skip-pkg-cache: true
  56. skip-build-cache: true
  57. check-diff:
  58. runs-on: ubuntu-latest
  59. needs: detect-noop
  60. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  61. steps:
  62. - name: Checkout
  63. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  64. - name: Setup Go
  65. uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
  66. id: setup-go
  67. with:
  68. go-version-file: "go.mod"
  69. - name: Download Go modules
  70. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  71. run: go mod download
  72. - name: Configure Git
  73. run: |
  74. git config user.name "$GITHUB_ACTOR"
  75. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  76. - name: Check Diff
  77. run: |
  78. make check-diff
  79. unit-tests:
  80. runs-on: ubuntu-latest
  81. needs: detect-noop
  82. if: needs.detect-noop.outputs.noop != 'true'
  83. steps:
  84. - name: Checkout
  85. uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  86. - name: Fetch History
  87. run: git fetch --prune --unshallow
  88. - name: Setup Go
  89. uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
  90. id: setup-go
  91. with:
  92. go-version-file: "go.mod"
  93. - name: Download Go modules
  94. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  95. run: go mod download
  96. - name: Cache envtest binaries
  97. uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
  98. with:
  99. path: bin/k8s
  100. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  101. - name: Run Unit Tests
  102. run: |
  103. make test
  104. - name: Publish Unit Test Coverage
  105. uses: codecov/codecov-action@0565863a31f2c772f9f0395002a31e3f06189574 # v5.4.0
  106. env:
  107. CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
  108. with:
  109. flags: unittests
  110. file: ./cover.out
  111. publish-artifacts:
  112. needs: detect-noop
  113. if: needs.detect-noop.outputs.noop != 'true'
  114. uses: ./.github/workflows/publish.yml
  115. permissions:
  116. id-token: write
  117. contents: read
  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 arm64 ppc64le"
  129. build-platform: "linux/amd64,linux/arm64,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. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  146. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}