ci.yml 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. name: CI
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request: {}
  7. env:
  8. # Common versions
  9. GOLANGCI_VERSION: 'v1.49.0'
  10. KUBERNETES_VERSION: '1.24.x'
  11. # Sonar
  12. SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
  13. jobs:
  14. detect-noop:
  15. runs-on: ubuntu-latest
  16. outputs:
  17. noop: ${{ steps.noop.outputs.should_skip }}
  18. steps:
  19. - name: Detect No-op Changes
  20. id: noop
  21. uses: fkirc/skip-duplicate-actions@v5.2.0
  22. with:
  23. github_token: ${{ secrets.GITHUB_TOKEN }}
  24. paths_ignore: '["**.md", "**.png", "**.jpg"]'
  25. do_not_skip: '["workflow_dispatch", "schedule", "push"]'
  26. concurrent_skipping: false
  27. lint:
  28. runs-on: ubuntu-latest
  29. needs: detect-noop
  30. if: needs.detect-noop.outputs.noop != 'true'
  31. steps:
  32. - name: Checkout
  33. uses: actions/checkout@v3
  34. - name: Setup Go
  35. uses: actions/setup-go@v3
  36. with:
  37. go-version-file: "go.mod"
  38. - name: Find the Go Cache
  39. id: go
  40. run: |
  41. echo "::set-output name=build-cache::$(go env GOCACHE)"
  42. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  43. - name: Cache the Go Build Cache
  44. uses: actions/cache@v3
  45. with:
  46. path: ${{ steps.go.outputs.build-cache }}
  47. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  48. - name: Cache Go Dependencies
  49. uses: actions/cache@v3
  50. with:
  51. path: ${{ steps.go.outputs.mod-cache }}
  52. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  53. - name: Lint
  54. uses: golangci/golangci-lint-action@v3
  55. with:
  56. version: ${{ env.GOLANGCI_VERSION }}
  57. skip-pkg-cache: true
  58. skip-build-cache: true
  59. check-diff:
  60. runs-on: ubuntu-latest
  61. needs: detect-noop
  62. if: needs.detect-noop.outputs.noop != 'true'
  63. steps:
  64. - name: Checkout
  65. uses: actions/checkout@v3
  66. - name: Setup Go
  67. uses: actions/setup-go@v3
  68. with:
  69. go-version-file: "go.mod"
  70. - name: Find the Go Cache
  71. id: go
  72. run: |
  73. echo "::set-output name=build-cache::$(go env GOCACHE)"
  74. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  75. - name: Cache the Go Build Cache
  76. uses: actions/cache@v3
  77. with:
  78. path: ${{ steps.go.outputs.build-cache }}
  79. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  80. - name: Cache Go Dependencies
  81. uses: actions/cache@v3
  82. with:
  83. path: ${{ steps.go.outputs.mod-cache }}
  84. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  85. # Check DIff also runs Reviewable which needs golangci-lint installed
  86. - name: Check Diff
  87. run: |
  88. wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${{ env.GOLANGCI_VERSION }}
  89. export PATH=$PATH:./bin
  90. make check-diff
  91. unit-tests:
  92. runs-on: ubuntu-latest
  93. needs: detect-noop
  94. if: needs.detect-noop.outputs.noop != 'true'
  95. steps:
  96. - name: Checkout
  97. uses: actions/checkout@v3
  98. - name: Fetch History
  99. run: git fetch --prune --unshallow
  100. - name: Setup Go
  101. uses: actions/setup-go@v3
  102. with:
  103. go-version-file: "go.mod"
  104. - name: Find the Go Cache
  105. id: go
  106. run: |
  107. echo "::set-output name=build-cache::$(go env GOCACHE)"
  108. echo "::set-output name=mod-cache::$(go env GOMODCACHE)"
  109. - name: Cache the Go Build Cache
  110. uses: actions/cache@v3
  111. with:
  112. path: ${{ steps.go.outputs.build-cache }}
  113. key: ${{ runner.os }}-build-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  114. - name: Cache Go Dependencies
  115. uses: actions/cache@v3
  116. with:
  117. path: ${{ steps.go.outputs.mod-cache }}
  118. key: ${{ runner.os }}-mod-${{ github.sha }}-${{ hashFiles('**/go.sum') }}
  119. - name: Add setup-envtest
  120. run: |
  121. go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
  122. setup-envtest use ${{env.KUBERNETES_VERSION}} -p env --os $(go env GOOS) --arch $(go env GOARCH)
  123. - name: Cache envtest binaries
  124. uses: actions/cache@v3
  125. with:
  126. path: /home/runner/.local/share/kubebuilder-envtest/
  127. key: ${{ runner.os }}-kubebuilder-${{env.KUBERNETES_VERSION}}
  128. - name: Run Unit Tests
  129. run: |
  130. export KUBEBUILDER_ATTACH_CONTROL_PLANE_OUTPUT=true
  131. source <(setup-envtest use ${{env.KUBERNETES_VERSION}} -p env --os $(go env GOOS) --arch $(go env GOARCH))
  132. make test
  133. publish-artifacts:
  134. needs: detect-noop
  135. if: needs.detect-noop.outputs.noop != 'true'
  136. uses: ./.github/workflows/publish.yml
  137. permissions:
  138. id-token: write
  139. contents: read
  140. strategy:
  141. matrix:
  142. include:
  143. - dockerfile: "Dockerfile"
  144. tag-suffix: "" # distroless
  145. - dockerfile: "Dockerfile.ubi"
  146. tag-suffix: "-ubi"
  147. with:
  148. dockerfile: ${{ matrix.dockerfile }}
  149. tag-suffix: ${{ matrix.tag-suffix }}
  150. image-name: ghcr.io/${{ github.repository }}
  151. secrets:
  152. GHCR_USERNAME: ${{ secrets.GHCR_USERNAME }}
  153. GHCR_TOKEN: ${{ secrets.GHCR_TOKEN }}