ci.yml 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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: "24.0.7"
  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. 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 ./bin/coverage/e2e
  174. mkdir -p ./bin/coverage/e2e
  175. make e2e-compose GOCOVERDIR=bin/coverage/e2e TEST_FLAGS="-v"
  176. -
  177. name: Gather coverage data
  178. if: ${{ matrix.mode == 'plugin' }}
  179. uses: actions/upload-artifact@v3
  180. with:
  181. name: coverage-data-e2e
  182. path: bin/coverage/e2e/
  183. if-no-files-found: error
  184. -
  185. name: Test standalone mode
  186. if: ${{ matrix.mode == 'standalone' }}
  187. run: |
  188. rm -f /usr/local/bin/docker-compose
  189. cp bin/build/docker-compose /usr/local/bin
  190. make e2e-compose-standalone
  191. coverage:
  192. runs-on: ubuntu-22.04
  193. needs:
  194. - test
  195. - e2e
  196. steps:
  197. # codecov won't process the report without the source code available
  198. - name: Checkout
  199. uses: actions/checkout@v3
  200. - name: Set up Go
  201. uses: actions/setup-go@v4
  202. with:
  203. go-version-file: 'go.mod'
  204. check-latest: true
  205. - name: Download unit test coverage
  206. uses: actions/download-artifact@v3
  207. with:
  208. name: coverage-data-unit
  209. path: coverage/unit
  210. - name: Download E2E test coverage
  211. uses: actions/download-artifact@v3
  212. with:
  213. name: coverage-data-e2e
  214. path: coverage/e2e
  215. - name: Merge coverage reports
  216. run: |
  217. go tool covdata textfmt -i=./coverage/unit,./coverage/e2e -o ./coverage.txt
  218. - name: Store coverage report in GitHub Actions
  219. uses: actions/upload-artifact@v3
  220. with:
  221. name: go-covdata-txt
  222. path: ./coverage.txt
  223. if-no-files-found: error
  224. - name: Upload coverage to Codecov
  225. uses: codecov/codecov-action@v3
  226. with:
  227. files: ./coverage.txt
  228. release:
  229. permissions:
  230. contents: write # to create a release (ncipollo/release-action)
  231. runs-on: ubuntu-latest
  232. needs:
  233. - binary
  234. steps:
  235. -
  236. name: Checkout
  237. uses: actions/checkout@v3
  238. -
  239. name: Download artifacts
  240. uses: actions/download-artifact@v3
  241. with:
  242. name: compose
  243. path: bin/release
  244. -
  245. name: Create checksums
  246. working-directory: bin/release
  247. run: |
  248. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  249. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  250. mv $RUNNER_TEMP/checksums.txt .
  251. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  252. -
  253. name: License
  254. run: cp packaging/* bin/release/
  255. -
  256. name: List artifacts
  257. run: |
  258. tree -nh bin/release
  259. -
  260. name: Check artifacts
  261. run: |
  262. find bin/release -type f -exec file -e ascii -- {} +
  263. -
  264. name: GitHub Release
  265. if: startsWith(github.ref, 'refs/tags/v')
  266. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  267. with:
  268. artifacts: bin/release/*
  269. generateReleaseNotes: true
  270. draft: true
  271. token: ${{ secrets.GITHUB_TOKEN }}