ci.yml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. publish-artifacts:
  97. needs: detect-noop
  98. if: needs.detect-noop.outputs.noop != 'true'
  99. uses: ./.github/workflows/publish.yml
  100. permissions:
  101. id-token: write
  102. contents: read
  103. strategy:
  104. matrix:
  105. include:
  106. - dockerfile: "Dockerfile"
  107. build-args: "CGO_ENABLED=0"
  108. build-arch: "amd64 arm64 s390x"
  109. build-platform: "linux/amd64,linux/arm64,linux/s390x"
  110. tag-suffix: "" # distroless
  111. - dockerfile: "Dockerfile.ubi"
  112. build-args: "CGO_ENABLED=0"
  113. build-arch: "amd64 arm64"
  114. build-platform: "linux/amd64,linux/arm64"
  115. tag-suffix: "-ubi"
  116. - dockerfile: "Dockerfile.ubi"
  117. build-args: "CGO_ENABLED=0 GOEXPERIMENT=boringcrypto"
  118. build-arch: "amd64"
  119. build-platform: "linux/amd64"
  120. tag-suffix: "-ubi-boringssl"
  121. with:
  122. dockerfile: ${{ matrix.dockerfile }}
  123. tag-suffix: ${{ matrix.tag-suffix }}
  124. image-name: ghcr.io/${{ github.repository }}
  125. build-platform: ${{ matrix.build-platform }}
  126. build-args: ${{ matrix.build-args }}
  127. build-arch: ${{ matrix.build-arch }}
  128. ref: ${{ github.ref }}
  129. secrets:
  130. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  131. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}