ci.yml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. name: ci
  2. concurrency:
  3. group: ${{ github.workflow }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - 'main'
  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. permissions:
  19. contents: read # to fetch code (actions/checkout)
  20. jobs:
  21. prepare:
  22. runs-on: ubuntu-latest
  23. outputs:
  24. matrix: ${{ steps.platforms.outputs.matrix }}
  25. steps:
  26. -
  27. name: Checkout
  28. uses: actions/checkout@v4
  29. -
  30. name: Create matrix
  31. id: platforms
  32. run: |
  33. echo matrix=$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms') >> $GITHUB_OUTPUT
  34. -
  35. name: Show matrix
  36. run: |
  37. echo ${{ steps.platforms.outputs.matrix }}
  38. validate:
  39. runs-on: ubuntu-latest
  40. strategy:
  41. fail-fast: false
  42. matrix:
  43. target:
  44. - lint
  45. - validate-go-mod
  46. - validate-headers
  47. - validate-docs
  48. steps:
  49. -
  50. name: Checkout
  51. uses: actions/checkout@v4
  52. -
  53. name: Set up Docker Buildx
  54. uses: docker/setup-buildx-action@v2
  55. -
  56. name: Run
  57. run: |
  58. make ${{ matrix.target }}
  59. binary:
  60. runs-on: ubuntu-latest
  61. needs:
  62. - prepare
  63. strategy:
  64. fail-fast: false
  65. matrix:
  66. platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
  67. steps:
  68. -
  69. name: Prepare
  70. run: |
  71. platform=${{ matrix.platform }}
  72. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  73. -
  74. name: Checkout
  75. uses: actions/checkout@v4
  76. -
  77. name: Set up QEMU
  78. uses: docker/setup-qemu-action@v2
  79. -
  80. name: Set up Docker Buildx
  81. uses: docker/setup-buildx-action@v2
  82. -
  83. name: Build
  84. uses: docker/bake-action@v2
  85. with:
  86. targets: release
  87. set: |
  88. *.platform=${{ matrix.platform }}
  89. *.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
  90. *.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
  91. -
  92. name: Upload artifacts
  93. uses: actions/upload-artifact@v4
  94. with:
  95. name: compose-${{ env.PLATFORM_PAIR }}
  96. path: ./bin/release
  97. if-no-files-found: error
  98. test:
  99. runs-on: ubuntu-latest
  100. steps:
  101. -
  102. name: Checkout
  103. uses: actions/checkout@v4
  104. -
  105. name: Set up Docker Buildx
  106. uses: docker/setup-buildx-action@v2
  107. -
  108. name: Test
  109. uses: docker/bake-action@v2
  110. with:
  111. targets: test
  112. set: |
  113. *.cache-from=type=gha,scope=test
  114. *.cache-to=type=gha,scope=test
  115. -
  116. name: Gather coverage data
  117. uses: actions/upload-artifact@v4
  118. with:
  119. name: coverage-data-unit
  120. path: bin/coverage/unit/
  121. if-no-files-found: error
  122. -
  123. name: Unit Test Summary
  124. uses: test-summary/action@v2
  125. with:
  126. paths: bin/coverage/unit/report.xml
  127. if: always()
  128. e2e:
  129. runs-on: ubuntu-latest
  130. strategy:
  131. fail-fast: false
  132. matrix:
  133. mode:
  134. - plugin
  135. - standalone
  136. engine:
  137. - 24.0.9
  138. - 25.0.5
  139. - 26.1.4
  140. - 27.2.1
  141. steps:
  142. - name: Prepare
  143. run: |
  144. mode=${{ matrix.mode }}
  145. engine=${{ matrix.engine }}
  146. echo "MODE_ENGINE_PAIR=${mode}-${engine}" >> $GITHUB_ENV
  147. -
  148. name: Checkout
  149. uses: actions/checkout@v4
  150. - name: Install Docker ${{ matrix.engine }}
  151. run: |
  152. sudo systemctl stop docker.service
  153. sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin
  154. sudo apt-get install curl
  155. curl -fsSL https://test.docker.com -o get-docker.sh
  156. sudo sh ./get-docker.sh --version ${{ matrix.engine }}
  157. - name: Check Docker Version
  158. run: docker --version
  159. -
  160. name: Set up Docker Buildx
  161. uses: docker/setup-buildx-action@v2
  162. -
  163. name: Set up Go
  164. uses: actions/setup-go@v5
  165. with:
  166. go-version-file: 'go.mod'
  167. check-latest: true
  168. cache: true
  169. -
  170. name: Build
  171. uses: docker/bake-action@v2
  172. with:
  173. targets: binary-with-coverage
  174. set: |
  175. *.cache-from=type=gha,scope=binary-linux-amd64
  176. *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
  177. *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
  178. env:
  179. BUILD_TAGS: e2e
  180. -
  181. name: Setup tmate session
  182. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  183. uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
  184. with:
  185. limit-access-to-actor: true
  186. github-token: ${{ secrets.GITHUB_TOKEN }}
  187. -
  188. name: Test plugin mode
  189. if: ${{ matrix.mode == 'plugin' }}
  190. run: |
  191. rm -rf ./bin/coverage/e2e
  192. mkdir -p ./bin/coverage/e2e
  193. make e2e-compose GOCOVERDIR=bin/coverage/e2e TEST_FLAGS="-v"
  194. -
  195. name: Gather coverage data
  196. if: ${{ matrix.mode == 'plugin' }}
  197. uses: actions/upload-artifact@v4
  198. with:
  199. name: coverage-data-e2e-${{ env.MODE_ENGINE_PAIR }}
  200. path: bin/coverage/e2e/
  201. if-no-files-found: error
  202. -
  203. name: Test standalone mode
  204. if: ${{ matrix.mode == 'standalone' }}
  205. run: |
  206. rm -f /usr/local/bin/docker-compose
  207. cp bin/build/docker-compose /usr/local/bin
  208. make e2e-compose-standalone
  209. -
  210. name: e2e Test Summary
  211. uses: test-summary/action@v2
  212. with:
  213. paths: /tmp/report/report.xml
  214. if: always()
  215. coverage:
  216. runs-on: ubuntu-latest
  217. needs:
  218. - test
  219. - e2e
  220. steps:
  221. # codecov won't process the report without the source code available
  222. - name: Checkout
  223. uses: actions/checkout@v4
  224. - name: Set up Go
  225. uses: actions/setup-go@v5
  226. with:
  227. go-version-file: 'go.mod'
  228. check-latest: true
  229. - name: Download unit test coverage
  230. uses: actions/download-artifact@v4
  231. with:
  232. name: coverage-data-unit
  233. path: coverage/unit
  234. merge-multiple: true
  235. - name: Download E2E test coverage
  236. uses: actions/download-artifact@v4
  237. with:
  238. pattern: coverage-data-e2e-*
  239. path: coverage/e2e
  240. merge-multiple: true
  241. - name: Merge coverage reports
  242. run: |
  243. go tool covdata textfmt -i=./coverage/unit,./coverage/e2e -o ./coverage.txt
  244. - name: Store coverage report in GitHub Actions
  245. uses: actions/upload-artifact@v4
  246. with:
  247. name: go-covdata-txt
  248. path: ./coverage.txt
  249. if-no-files-found: error
  250. - name: Upload coverage to Codecov
  251. uses: codecov/codecov-action@v3
  252. with:
  253. files: ./coverage.txt
  254. release:
  255. permissions:
  256. contents: write # to create a release (ncipollo/release-action)
  257. runs-on: ubuntu-latest
  258. needs:
  259. - binary
  260. steps:
  261. -
  262. name: Checkout
  263. uses: actions/checkout@v4
  264. -
  265. name: Download artifacts
  266. uses: actions/download-artifact@v4
  267. with:
  268. pattern: compose-*
  269. path: ./bin/release
  270. merge-multiple: true
  271. -
  272. name: Create checksums
  273. working-directory: ./bin/release
  274. run: |
  275. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  276. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  277. mv $RUNNER_TEMP/checksums.txt .
  278. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  279. -
  280. name: License
  281. run: cp packaging/* ./bin/release/
  282. -
  283. name: List artifacts
  284. run: |
  285. tree -nh ./bin/release
  286. -
  287. name: Check artifacts
  288. run: |
  289. find bin/release -type f -exec file -e ascii -- {} +
  290. -
  291. name: GitHub Release
  292. if: startsWith(github.ref, 'refs/tags/v')
  293. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  294. with:
  295. artifacts: ./bin/release/*
  296. generateReleaseNotes: true
  297. draft: true
  298. token: ${{ secrets.GITHUB_TOKEN }}