ci.yml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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.54.2'
  11. KUBERNETES_VERSION: '1.28.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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  43. - name: Setup Go
  44. uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.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@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4.0.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@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  64. - name: Setup Go
  65. uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.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' && github.ref != 'refs/heads/main'
  83. steps:
  84. - name: Checkout
  85. uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
  86. - name: Fetch History
  87. run: git fetch --prune --unshallow
  88. - name: Setup Go
  89. uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.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@13aacd865c20de90d75de3b17ebe84f7a17d57d2 # v4.0.0
  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@e0b68c6749509c5f83f984dd99a76a1c1a231044 # v4.0.1
  106. with:
  107. flags: unittests
  108. file: ./cover.out
  109. publish-artifacts:
  110. needs: detect-noop
  111. if: needs.detect-noop.outputs.noop != 'true'
  112. uses: ./.github/workflows/publish.yml
  113. permissions:
  114. id-token: write
  115. contents: read
  116. strategy:
  117. matrix:
  118. include:
  119. - dockerfile: "Dockerfile"
  120. build-args: "CGO_ENABLED=0"
  121. build-arch: "amd64 arm64 s390x"
  122. build-platform: "linux/amd64,linux/arm64,linux/s390x"
  123. tag-suffix: "" # distroless
  124. - dockerfile: "Dockerfile.ubi"
  125. build-args: "CGO_ENABLED=0"
  126. build-arch: "amd64 arm64"
  127. build-platform: "linux/amd64,linux/arm64"
  128. tag-suffix: "-ubi"
  129. - dockerfile: "Dockerfile.ubi"
  130. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  131. build-arch: "amd64"
  132. build-platform: "linux/amd64"
  133. tag-suffix: "-ubi-boringssl"
  134. with:
  135. dockerfile: ${{ matrix.dockerfile }}
  136. tag-suffix: ${{ matrix.tag-suffix }}
  137. image-name: ghcr.io/${{ github.repository }}
  138. build-platform: ${{ matrix.build-platform }}
  139. build-args: ${{ matrix.build-args }}
  140. build-arch: ${{ matrix.build-arch }}
  141. ref: ${{ github.ref }}
  142. secrets:
  143. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  144. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}