ci.yml 6.2 KB

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