ci.yml 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 matrix=$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms') >> $GITHUB_OUTPUT
  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. -
  119. name: Upload coverage to Codecov
  120. uses: codecov/codecov-action@v3
  121. e2e:
  122. runs-on: ubuntu-latest
  123. env:
  124. DESTDIR: "./bin/build"
  125. strategy:
  126. fail-fast: false
  127. matrix:
  128. mode:
  129. - plugin
  130. - standalone
  131. - cucumber
  132. steps:
  133. -
  134. name: Checkout
  135. uses: actions/checkout@v3
  136. -
  137. name: Set up Docker Buildx
  138. uses: docker/setup-buildx-action@v2
  139. -
  140. name: Set up Go
  141. uses: actions/setup-go@v3
  142. with:
  143. go-version-file: 'go.mod'
  144. check-latest: true
  145. cache: true
  146. -
  147. name: Setup docker CLI
  148. run: |
  149. curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
  150. sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
  151. -
  152. name: Build
  153. uses: docker/bake-action@v2
  154. with:
  155. targets: binary-with-coverage
  156. set: |
  157. *.cache-from=type=gha,scope=binary-linux-amd64
  158. *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
  159. *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
  160. env:
  161. BUILD_TAGS: e2e
  162. -
  163. name: Setup tmate session
  164. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  165. uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
  166. with:
  167. limit-access-to-actor: true
  168. github-token: ${{ secrets.GITHUB_TOKEN }}
  169. -
  170. name: Test plugin mode
  171. if: ${{ matrix.mode == 'plugin' }}
  172. run: |
  173. rm -rf ./covdatafiles
  174. mkdir ./covdatafiles
  175. make e2e-compose GOCOVERDIR=covdatafiles
  176. go tool covdata textfmt -i=covdatafiles -o=coverage.out
  177. -
  178. name: Test standalone mode
  179. if: ${{ matrix.mode == 'standalone' }}
  180. run: |
  181. rm -f /usr/local/bin/docker-compose
  182. cp bin/build/docker-compose /usr/local/bin
  183. make e2e-compose-standalone
  184. -
  185. name: Run cucumber tests
  186. if: ${{ matrix.mode == 'cucumber'}}
  187. run: |
  188. make test-cucumber
  189. -
  190. name: Upload coverage to Codecov
  191. uses: codecov/codecov-action@v3
  192. release:
  193. permissions:
  194. contents: write # to create a release (ncipollo/release-action)
  195. runs-on: ubuntu-latest
  196. needs:
  197. - binary
  198. steps:
  199. -
  200. name: Checkout
  201. uses: actions/checkout@v3
  202. -
  203. name: Download artifacts
  204. uses: actions/download-artifact@v3
  205. with:
  206. name: compose
  207. path: ${{ env.DESTDIR }}
  208. -
  209. name: Create checksums
  210. working-directory: ${{ env.DESTDIR }}
  211. run: |
  212. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  213. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  214. mv $RUNNER_TEMP/checksums.txt .
  215. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  216. -
  217. name: License
  218. run: cp packaging/* ${{ env.DESTDIR }}/
  219. -
  220. name: List artifacts
  221. run: |
  222. tree -nh ${{ env.DESTDIR }}
  223. -
  224. name: Check artifacts
  225. run: |
  226. find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
  227. -
  228. name: GitHub Release
  229. if: startsWith(github.ref, 'refs/tags/v')
  230. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  231. with:
  232. artifacts: ${{ env.DESTDIR }}/*
  233. generateReleaseNotes: true
  234. draft: true
  235. token: ${{ secrets.GITHUB_TOKEN }}