ci.yml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. name: ci
  2. concurrency:
  3. group: ${{ github.workflow }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - 'v2'
  9. tags:
  10. - 'v*'
  11. pull_request:
  12. workflow_dispatch:
  13. inputs:
  14. debug_enabled:
  15. description: 'To run with tmate enter "debug_enabled"'
  16. required: false
  17. default: "false"
  18. env:
  19. GO_VERSION: "1.18.5" # for non sandboxed e2e tests
  20. DESTDIR: "./bin"
  21. DOCKER_CLI_VERSION: "20.10.17"
  22. jobs:
  23. prepare:
  24. runs-on: ubuntu-latest
  25. outputs:
  26. matrix: ${{ steps.platforms.outputs.matrix }}
  27. steps:
  28. -
  29. name: Checkout
  30. uses: actions/checkout@v3
  31. -
  32. name: Create matrix
  33. id: platforms
  34. run: |
  35. echo ::set-output name=matrix::$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')
  36. -
  37. name: Show matrix
  38. run: |
  39. echo ${{ steps.platforms.outputs.matrix }}
  40. validate:
  41. runs-on: ubuntu-latest
  42. strategy:
  43. fail-fast: false
  44. matrix:
  45. target:
  46. - lint
  47. - validate-go-mod
  48. - validate-headers
  49. - validate-docs
  50. steps:
  51. -
  52. name: Checkout
  53. uses: actions/checkout@v3
  54. -
  55. name: Set up Docker Buildx
  56. uses: docker/setup-buildx-action@v2
  57. -
  58. name: Run
  59. run: |
  60. make ${{ matrix.target }}
  61. binary:
  62. runs-on: ubuntu-latest
  63. needs:
  64. - prepare
  65. strategy:
  66. fail-fast: false
  67. matrix:
  68. platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
  69. steps:
  70. -
  71. name: Prepare
  72. run: |
  73. platform=${{ matrix.platform }}
  74. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  75. -
  76. name: Checkout
  77. uses: actions/checkout@v3
  78. -
  79. name: Set up QEMU
  80. uses: docker/setup-qemu-action@v2
  81. -
  82. name: Set up Docker Buildx
  83. uses: docker/setup-buildx-action@v2
  84. -
  85. name: Build
  86. uses: docker/bake-action@v2
  87. with:
  88. targets: release
  89. set: |
  90. *.platform=${{ matrix.platform }}
  91. *.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
  92. *.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
  93. -
  94. name: Upload artifacts
  95. uses: actions/upload-artifact@v3
  96. with:
  97. name: compose
  98. path: ${{ env.DESTDIR }}/*
  99. if-no-files-found: error
  100. test:
  101. runs-on: ubuntu-latest
  102. steps:
  103. -
  104. name: Checkout
  105. uses: actions/checkout@v3
  106. -
  107. name: Set up Docker Buildx
  108. uses: docker/setup-buildx-action@v2
  109. -
  110. name: Test
  111. uses: docker/bake-action@v2
  112. with:
  113. targets: test
  114. set: |
  115. *.cache-from=type=gha,scope=test
  116. *.cache-to=type=gha,scope=test
  117. e2e:
  118. runs-on: ubuntu-latest
  119. env:
  120. DESTDIR: "./bin/build"
  121. strategy:
  122. fail-fast: false
  123. matrix:
  124. mode:
  125. - plugin
  126. - standalone
  127. steps:
  128. -
  129. name: Checkout
  130. uses: actions/checkout@v3
  131. -
  132. name: Set up Docker Buildx
  133. uses: docker/setup-buildx-action@v2
  134. -
  135. name: Set up Go
  136. uses: actions/setup-go@v3
  137. with:
  138. go-version: ${{ env.GO_VERSION }}
  139. cache: true
  140. -
  141. name: Setup docker CLI
  142. run: |
  143. curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
  144. sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
  145. -
  146. name: Build
  147. uses: docker/bake-action@v2
  148. with:
  149. targets: binary
  150. set: |
  151. *.cache-from=type=gha,scope=binary-linux-amd64
  152. *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
  153. *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
  154. env:
  155. BUILD_TAGS: e2e
  156. -
  157. name: Setup tmate session
  158. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  159. uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
  160. with:
  161. limit-access-to-actor: true
  162. github-token: ${{ secrets.GITHUB_TOKEN }}
  163. -
  164. name: Test plugin mode
  165. if: ${{ matrix.mode == 'plugin' }}
  166. run: |
  167. make e2e-compose
  168. -
  169. name: Test standalone mode
  170. if: ${{ matrix.mode == 'standalone' }}
  171. run: |
  172. rm -f /usr/local/bin/docker-compose
  173. cp bin/build/docker-compose /usr/local/bin
  174. make e2e-compose-standalone
  175. release:
  176. runs-on: ubuntu-latest
  177. needs:
  178. - binary
  179. steps:
  180. -
  181. name: Checkout
  182. uses: actions/checkout@v3
  183. -
  184. name: Download artifacts
  185. uses: actions/download-artifact@v3
  186. with:
  187. name: compose
  188. path: ${{ env.DESTDIR }}
  189. -
  190. name: Create checksums
  191. working-directory: ${{ env.DESTDIR }}
  192. run: |
  193. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# .*/# #' > checksums.txt
  194. shasum -a 256 -U -c checksums.txt
  195. -
  196. name: License
  197. run: cp packaging/* ${{ env.DESTDIR }}/
  198. -
  199. name: List artifacts
  200. run: |
  201. tree -nh ${{ env.DESTDIR }}
  202. -
  203. name: Check artifacts
  204. run: |
  205. find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
  206. -
  207. name: GitHub Release
  208. if: startsWith(github.ref, 'refs/tags/v')
  209. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  210. with:
  211. artifacts: ${{ env.DESTDIR }}/*
  212. generateReleaseNotes: true
  213. draft: true
  214. token: ${{ secrets.GITHUB_TOKEN }}