ci.yml 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. e2e:
  125. runs-on: ubuntu-latest
  126. strategy:
  127. fail-fast: false
  128. matrix:
  129. mode:
  130. - plugin
  131. - standalone
  132. engine:
  133. - 24.0.9
  134. - 25.0.3
  135. steps:
  136. -
  137. name: Checkout
  138. uses: actions/checkout@v3
  139. - name: Install Docker ${{ matrix.engine }}
  140. run: |
  141. sudo apt-get install curl
  142. curl -fsSL https://get.docker.com -o get-docker.sh
  143. sudo sh ./get-docker.sh --version ${{ matrix.engine }}
  144. - name: Check Docker Version
  145. run: docker --version
  146. -
  147. name: Set up Docker Buildx
  148. uses: docker/setup-buildx-action@v2
  149. -
  150. name: Set up Go
  151. uses: actions/setup-go@v3
  152. with:
  153. go-version-file: 'go.mod'
  154. check-latest: true
  155. cache: true
  156. -
  157. name: Setup docker CLI
  158. run: |
  159. curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
  160. sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
  161. -
  162. name: Build
  163. uses: docker/bake-action@v2
  164. with:
  165. targets: binary-with-coverage
  166. set: |
  167. *.cache-from=type=gha,scope=binary-linux-amd64
  168. *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
  169. *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
  170. env:
  171. BUILD_TAGS: e2e
  172. -
  173. name: Setup tmate session
  174. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  175. uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
  176. with:
  177. limit-access-to-actor: true
  178. github-token: ${{ secrets.GITHUB_TOKEN }}
  179. -
  180. name: Test plugin mode
  181. if: ${{ matrix.mode == 'plugin' }}
  182. run: |
  183. rm -rf ./bin/coverage/e2e
  184. mkdir -p ./bin/coverage/e2e
  185. make e2e-compose GOCOVERDIR=bin/coverage/e2e TEST_FLAGS="-v"
  186. -
  187. name: Gather coverage data
  188. if: ${{ matrix.mode == 'plugin' }}
  189. uses: actions/upload-artifact@v3
  190. with:
  191. name: coverage-data-e2e
  192. path: bin/coverage/e2e/
  193. if-no-files-found: error
  194. -
  195. name: Test standalone mode
  196. if: ${{ matrix.mode == 'standalone' }}
  197. run: |
  198. rm -f /usr/local/bin/docker-compose
  199. cp bin/build/docker-compose /usr/local/bin
  200. make e2e-compose-standalone
  201. coverage:
  202. runs-on: ubuntu-22.04
  203. needs:
  204. - test
  205. - e2e
  206. steps:
  207. # codecov won't process the report without the source code available
  208. - name: Checkout
  209. uses: actions/checkout@v3
  210. - name: Set up Go
  211. uses: actions/setup-go@v4
  212. with:
  213. go-version-file: 'go.mod'
  214. check-latest: true
  215. - name: Download unit test coverage
  216. uses: actions/download-artifact@v3
  217. with:
  218. name: coverage-data-unit
  219. path: coverage/unit
  220. - name: Download E2E test coverage
  221. uses: actions/download-artifact@v3
  222. with:
  223. name: coverage-data-e2e
  224. path: coverage/e2e
  225. - name: Merge coverage reports
  226. run: |
  227. go tool covdata textfmt -i=./coverage/unit,./coverage/e2e -o ./coverage.txt
  228. - name: Store coverage report in GitHub Actions
  229. uses: actions/upload-artifact@v3
  230. with:
  231. name: go-covdata-txt
  232. path: ./coverage.txt
  233. if-no-files-found: error
  234. - name: Upload coverage to Codecov
  235. uses: codecov/codecov-action@v3
  236. with:
  237. files: ./coverage.txt
  238. release:
  239. permissions:
  240. contents: write # to create a release (ncipollo/release-action)
  241. runs-on: ubuntu-latest
  242. needs:
  243. - binary
  244. steps:
  245. -
  246. name: Checkout
  247. uses: actions/checkout@v3
  248. -
  249. name: Download artifacts
  250. uses: actions/download-artifact@v3
  251. with:
  252. name: compose
  253. path: bin/release
  254. -
  255. name: Create checksums
  256. working-directory: bin/release
  257. run: |
  258. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  259. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  260. mv $RUNNER_TEMP/checksums.txt .
  261. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  262. -
  263. name: License
  264. run: cp packaging/* bin/release/
  265. -
  266. name: List artifacts
  267. run: |
  268. tree -nh bin/release
  269. -
  270. name: Check artifacts
  271. run: |
  272. find bin/release -type f -exec file -e ascii -- {} +
  273. -
  274. name: GitHub Release
  275. if: startsWith(github.ref, 'refs/tags/v')
  276. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  277. with:
  278. artifacts: bin/release/*
  279. generateReleaseNotes: true
  280. draft: true
  281. token: ${{ secrets.GITHUB_TOKEN }}