ci.yml 8.0 KB

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