ci.yml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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. DESTDIR: "./bin"
  20. DOCKER_CLI_VERSION: "20.10.17"
  21. jobs:
  22. prepare:
  23. runs-on: ubuntu-latest
  24. outputs:
  25. matrix: ${{ steps.platforms.outputs.matrix }}
  26. steps:
  27. -
  28. name: Checkout
  29. uses: actions/checkout@v3
  30. -
  31. name: Create matrix
  32. id: platforms
  33. run: |
  34. echo ::set-output name=matrix::$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')
  35. -
  36. name: Show matrix
  37. run: |
  38. echo ${{ steps.platforms.outputs.matrix }}
  39. validate:
  40. runs-on: ubuntu-latest
  41. strategy:
  42. fail-fast: false
  43. matrix:
  44. target:
  45. - lint
  46. - validate-go-mod
  47. - validate-headers
  48. - validate-docs
  49. steps:
  50. -
  51. name: Checkout
  52. uses: actions/checkout@v3
  53. -
  54. name: Set up Docker Buildx
  55. uses: docker/setup-buildx-action@v2
  56. -
  57. name: Run
  58. run: |
  59. make ${{ matrix.target }}
  60. binary:
  61. runs-on: ubuntu-latest
  62. needs:
  63. - prepare
  64. strategy:
  65. fail-fast: false
  66. matrix:
  67. platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
  68. steps:
  69. -
  70. name: Prepare
  71. run: |
  72. platform=${{ matrix.platform }}
  73. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  74. -
  75. name: Checkout
  76. uses: actions/checkout@v3
  77. -
  78. name: Set up QEMU
  79. uses: docker/setup-qemu-action@v2
  80. -
  81. name: Set up Docker Buildx
  82. uses: docker/setup-buildx-action@v2
  83. -
  84. name: Build
  85. uses: docker/bake-action@v2
  86. with:
  87. targets: release
  88. set: |
  89. *.platform=${{ matrix.platform }}
  90. *.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
  91. *.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
  92. -
  93. name: Upload artifacts
  94. uses: actions/upload-artifact@v3
  95. with:
  96. name: compose
  97. path: ${{ env.DESTDIR }}/*
  98. if-no-files-found: error
  99. test:
  100. runs-on: ubuntu-latest
  101. steps:
  102. -
  103. name: Checkout
  104. uses: actions/checkout@v3
  105. -
  106. name: Set up Docker Buildx
  107. uses: docker/setup-buildx-action@v2
  108. -
  109. name: Test
  110. uses: docker/bake-action@v2
  111. with:
  112. targets: test
  113. set: |
  114. *.cache-from=type=gha,scope=test
  115. *.cache-to=type=gha,scope=test
  116. e2e:
  117. runs-on: ubuntu-latest
  118. env:
  119. DESTDIR: "./bin/build"
  120. strategy:
  121. fail-fast: false
  122. matrix:
  123. mode:
  124. - plugin
  125. - standalone
  126. steps:
  127. -
  128. name: Checkout
  129. uses: actions/checkout@v3
  130. -
  131. name: Set up Docker Buildx
  132. uses: docker/setup-buildx-action@v2
  133. -
  134. name: Set up Go
  135. uses: actions/setup-go@v3
  136. with:
  137. go-version-file: 'go.mod'
  138. check-latest: true
  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# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  194. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  195. mv $RUNNER_TEMP/checksums.txt .
  196. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  197. -
  198. name: License
  199. run: cp packaging/* ${{ env.DESTDIR }}/
  200. -
  201. name: List artifacts
  202. run: |
  203. tree -nh ${{ env.DESTDIR }}
  204. -
  205. name: Check artifacts
  206. run: |
  207. find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
  208. -
  209. name: GitHub Release
  210. if: startsWith(github.ref, 'refs/tags/v')
  211. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  212. with:
  213. artifacts: ${{ env.DESTDIR }}/*
  214. generateReleaseNotes: true
  215. draft: true
  216. token: ${{ secrets.GITHUB_TOKEN }}