ci.yml 9.1 KB

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