ci.yml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. name: CI
  2. on:
  3. push:
  4. branches: [main]
  5. tags:
  6. - "*"
  7. pull_request:
  8. schedule:
  9. - cron: "0 0 * * *"
  10. workflow_dispatch:
  11. env:
  12. IMAGE_NAME: ${{ github.repository }}
  13. jobs:
  14. vendor:
  15. runs-on: ubuntu-latest
  16. steps:
  17. - uses: actions/checkout@v6
  18. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  19. - uses: DeterminateSystems/magic-nix-cache-action@v13
  20. - run: |
  21. go mod tidy
  22. go mod vendor
  23. git diff --exit-code
  24. build:
  25. runs-on: ubuntu-latest
  26. steps:
  27. - uses: actions/checkout@v6
  28. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  29. - uses: DeterminateSystems/magic-nix-cache-action@v13
  30. - run: nix build
  31. docs:
  32. runs-on: ubuntu-latest
  33. steps:
  34. - uses: actions/checkout@v6
  35. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  36. - uses: DeterminateSystems/magic-nix-cache-action@v13
  37. - name: Build docs
  38. run: |
  39. nix develop . --command make gen-docs
  40. git diff --exit-code
  41. linux:
  42. runs-on: ubuntu-latest
  43. steps:
  44. - uses: actions/checkout@v6
  45. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  46. - uses: DeterminateSystems/magic-nix-cache-action@v13
  47. - run: nix build .#kilo-cross-linux-amd64 .#kilo-cross-linux-arm64 .#kilo-cross-linux-arm
  48. darwin:
  49. runs-on: ubuntu-latest
  50. steps:
  51. - uses: actions/checkout@v6
  52. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  53. - uses: DeterminateSystems/magic-nix-cache-action@v13
  54. - run: nix build .#kgctl-cross-darwin-amd64 .#kgctl-cross-darwin-arm64
  55. windows:
  56. runs-on: ubuntu-latest
  57. steps:
  58. - uses: actions/checkout@v6
  59. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  60. - uses: DeterminateSystems/magic-nix-cache-action@v13
  61. - run: nix build .#kgctl-cross-windows-amd64
  62. unit:
  63. runs-on: ubuntu-latest
  64. steps:
  65. - uses: actions/checkout@v6
  66. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  67. - uses: DeterminateSystems/magic-nix-cache-action@v13
  68. - run: nix develop . --command go test -mod=vendor --race ./...
  69. e2e:
  70. runs-on: ubuntu-latest
  71. steps:
  72. - uses: actions/checkout@v6
  73. - name: Set up Docker Buildx
  74. uses: docker/setup-buildx-action@v3
  75. - name: Build
  76. uses: docker/build-push-action@v6
  77. with:
  78. context: .
  79. platforms: linux/amd64
  80. tags: squat/kilo:test
  81. cache-from: type=gha
  82. cache-to: type=gha,mode=max
  83. load: "true"
  84. build-args: |
  85. VERSION=${{ github.sha }}
  86. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  87. - uses: DeterminateSystems/magic-nix-cache-action@v13
  88. - env:
  89. E2E_SKIP_TEARDOWN_ON_FAILURE: "true"
  90. run: nix develop . --command make e2e
  91. - name: Breakpoint if tests failed
  92. if: failure()
  93. uses: namespacelabs/breakpoint-action@v0
  94. with:
  95. duration: 15m
  96. authorized-users: squat, leonnicolas
  97. lint:
  98. runs-on: ubuntu-latest
  99. steps:
  100. - uses: actions/checkout@v6
  101. - uses: DeterminateSystems/determinate-nix-action@v3.15.1
  102. - uses: DeterminateSystems/magic-nix-cache-action@v13
  103. - run: nix flake check -L --show-trace
  104. container:
  105. runs-on: ubuntu-latest
  106. steps:
  107. - uses: actions/checkout@v6
  108. - name: Set up Docker Buildx
  109. uses: docker/setup-buildx-action@v3
  110. - name: Extract Docker metadata
  111. id: meta
  112. uses: docker/metadata-action@v5
  113. with:
  114. images: ghcr.io/${{ env.IMAGE_NAME }},docker.io/${{ env.IMAGE_NAME }}
  115. tags: type=sha,prefix=
  116. flavor: latest=true
  117. - name: Build
  118. uses: docker/build-push-action@v6
  119. with:
  120. context: .
  121. platforms: linux/amd64, linux/arm64, linux/arm
  122. tags: ${{ steps.meta.outputs.tags }}
  123. labels: ${{ steps.meta.outputs.labels }}
  124. cache-from: type=gha
  125. cache-to: type=gha,mode=max
  126. build-args: |
  127. VERSION=${{ github.sha }}
  128. push:
  129. if: github.event_name != 'pull_request'
  130. needs:
  131. - vendor
  132. - build
  133. - linux
  134. - darwin
  135. - windows
  136. - unit
  137. - lint
  138. - container
  139. runs-on: ubuntu-latest
  140. steps:
  141. - uses: actions/checkout@v6
  142. - name: Set up Docker Buildx
  143. uses: docker/setup-buildx-action@v3
  144. - name: Login to GitHub Container Registry
  145. uses: docker/login-action@v3
  146. with:
  147. registry: ghcr.io
  148. username: ${{ github.repository_owner }}
  149. password: ${{ secrets.GITHUB_TOKEN }}
  150. - name: Login to Docker Hub
  151. uses: docker/login-action@v3
  152. with:
  153. username: ${{ secrets.DOCKER_USERNAME }}
  154. password: ${{ secrets.DOCKER_PASSWORD }}
  155. - name: Extract Docker metadata
  156. id: meta
  157. uses: docker/metadata-action@v5
  158. with:
  159. images: ghcr.io/${{ env.IMAGE_NAME }},docker.io/${{ env.IMAGE_NAME }}
  160. tags: type=sha,prefix=
  161. flavor: latest=true
  162. - name: Build and push
  163. id: push
  164. uses: docker/build-push-action@v6
  165. with:
  166. context: .
  167. push: ${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
  168. platforms: linux/amd64, linux/arm64, linux/arm
  169. tags: ${{ steps.meta.outputs.tags }}
  170. labels: ${{ steps.meta.outputs.labels }}
  171. cache-from: type=gha
  172. cache-to: type=gha,mode=max
  173. build-args: |
  174. VERSION=${{ github.sha }}
  175. - name: Determine digest
  176. run: echo ${{ steps.push.outputs.digest }}