ci.yml 7.7 KB

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