ci.yml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. jobs:
  15. detect-noop:
  16. runs-on: ubuntu-latest
  17. outputs:
  18. noop: ${{ steps.noop.outputs.should_skip }}
  19. steps:
  20. - name: Detect No-op Changes
  21. id: noop
  22. uses: fkirc/skip-duplicate-actions@v5.3.1
  23. with:
  24. github_token: ${{ secrets.GITHUB_TOKEN }}
  25. paths_ignore: '["**.md", "**.png", "**.jpg"]'
  26. do_not_skip: '["workflow_dispatch", "schedule", "push"]'
  27. concurrent_skipping: false
  28. lint:
  29. runs-on: ubuntu-latest
  30. needs: detect-noop
  31. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  32. steps:
  33. - name: Checkout
  34. uses: actions/checkout@v4
  35. - name: Setup Go
  36. uses: actions/setup-go@v5
  37. id: setup-go
  38. with:
  39. go-version-file: "go.mod"
  40. - name: Download Go modules
  41. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  42. run: go mod download
  43. - name: Lint
  44. uses: golangci/golangci-lint-action@v3
  45. with:
  46. version: ${{ env.GOLANGCI_VERSION }}
  47. skip-pkg-cache: true
  48. skip-build-cache: true
  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. steps:
  54. - name: Checkout
  55. uses: actions/checkout@v4
  56. - name: Setup Go
  57. uses: actions/setup-go@v5
  58. id: setup-go
  59. with:
  60. go-version-file: "go.mod"
  61. - name: Download Go modules
  62. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  63. run: go mod download
  64. - name: Configure Git
  65. run: |
  66. git config user.name "$GITHUB_ACTOR"
  67. git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
  68. - name: Check Diff
  69. run: |
  70. make check-diff
  71. unit-tests:
  72. runs-on: ubuntu-latest
  73. needs: detect-noop
  74. if: needs.detect-noop.outputs.noop != 'true' && github.ref != 'refs/heads/main'
  75. steps:
  76. - name: Checkout
  77. uses: actions/checkout@v4
  78. - name: Fetch History
  79. run: git fetch --prune --unshallow
  80. - name: Setup Go
  81. uses: actions/setup-go@v5
  82. id: setup-go
  83. with:
  84. go-version-file: "go.mod"
  85. - name: Download Go modules
  86. if: ${{ steps.setup-go.outputs.cache-hit != 'true' }}
  87. run: go mod download
  88. - name: Cache envtest binaries
  89. uses: actions/cache@v3
  90. with:
  91. path: bin/k8s
  92. key: ${{ runner.os }}-envtest-${{env.KUBERNETES_VERSION}}
  93. - name: Run Unit Tests
  94. run: |
  95. make test
  96. - name: Publish Unit Test Coverage
  97. uses: codecov/codecov-action@v3
  98. with:
  99. flags: unittests
  100. file: ./cover.out
  101. publish-artifacts:
  102. needs: detect-noop
  103. if: needs.detect-noop.outputs.noop != 'true'
  104. uses: ./.github/workflows/publish.yml
  105. permissions:
  106. id-token: write
  107. contents: read
  108. strategy:
  109. matrix:
  110. include:
  111. - dockerfile: "Dockerfile"
  112. build-args: "CGO_ENABLED=0"
  113. build-arch: "amd64 arm64 s390x"
  114. build-platform: "linux/amd64,linux/arm64,linux/s390x"
  115. tag-suffix: "" # distroless
  116. - dockerfile: "Dockerfile.ubi"
  117. build-args: "CGO_ENABLED=0"
  118. build-arch: "amd64 arm64"
  119. build-platform: "linux/amd64,linux/arm64"
  120. tag-suffix: "-ubi"
  121. - dockerfile: "Dockerfile.ubi"
  122. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  123. build-arch: "amd64"
  124. build-platform: "linux/amd64"
  125. tag-suffix: "-ubi-boringssl"
  126. with:
  127. dockerfile: ${{ matrix.dockerfile }}
  128. tag-suffix: ${{ matrix.tag-suffix }}
  129. image-name: ghcr.io/${{ github.repository }}
  130. build-platform: ${{ matrix.build-platform }}
  131. build-args: ${{ matrix.build-args }}
  132. build-arch: ${{ matrix.build-arch }}
  133. ref: ${{ github.ref }}
  134. secrets:
  135. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  136. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}