ci.yml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. name: ci
  2. concurrency:
  3. group: ${{ github.workflow }}-${{ github.ref }}
  4. cancel-in-progress: true
  5. on:
  6. push:
  7. branches:
  8. - 'v2'
  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. DESTDIR: "./bin"
  20. DOCKER_CLI_VERSION: "20.10.17"
  21. permissions:
  22. contents: read # to fetch code (actions/checkout)
  23. jobs:
  24. prepare:
  25. runs-on: ubuntu-latest
  26. outputs:
  27. matrix: ${{ steps.platforms.outputs.matrix }}
  28. steps:
  29. -
  30. name: Checkout
  31. uses: actions/checkout@v3
  32. -
  33. name: Create matrix
  34. id: platforms
  35. run: |
  36. echo ::set-output name=matrix::$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms')
  37. -
  38. name: Show matrix
  39. run: |
  40. echo ${{ steps.platforms.outputs.matrix }}
  41. validate:
  42. runs-on: ubuntu-latest
  43. strategy:
  44. fail-fast: false
  45. matrix:
  46. target:
  47. - lint
  48. - validate-go-mod
  49. - validate-headers
  50. - validate-docs
  51. steps:
  52. -
  53. name: Checkout
  54. uses: actions/checkout@v3
  55. -
  56. name: Set up Docker Buildx
  57. uses: docker/setup-buildx-action@v2
  58. -
  59. name: Run
  60. run: |
  61. make ${{ matrix.target }}
  62. binary:
  63. runs-on: ubuntu-latest
  64. needs:
  65. - prepare
  66. strategy:
  67. fail-fast: false
  68. matrix:
  69. platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
  70. steps:
  71. -
  72. name: Prepare
  73. run: |
  74. platform=${{ matrix.platform }}
  75. echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
  76. -
  77. name: Checkout
  78. uses: actions/checkout@v3
  79. -
  80. name: Set up QEMU
  81. uses: docker/setup-qemu-action@v2
  82. -
  83. name: Set up Docker Buildx
  84. uses: docker/setup-buildx-action@v2
  85. -
  86. name: Build
  87. uses: docker/bake-action@v2
  88. with:
  89. targets: release
  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: Upload artifacts
  96. uses: actions/upload-artifact@v3
  97. with:
  98. name: compose
  99. path: ${{ env.DESTDIR }}/*
  100. if-no-files-found: error
  101. test:
  102. runs-on: ubuntu-latest
  103. steps:
  104. -
  105. name: Checkout
  106. uses: actions/checkout@v3
  107. -
  108. name: Set up Docker Buildx
  109. uses: docker/setup-buildx-action@v2
  110. -
  111. name: Test
  112. uses: docker/bake-action@v2
  113. with:
  114. targets: test
  115. set: |
  116. *.cache-from=type=gha,scope=test
  117. *.cache-to=type=gha,scope=test
  118. e2e:
  119. runs-on: ubuntu-latest
  120. env:
  121. DESTDIR: "./bin/build"
  122. strategy:
  123. fail-fast: false
  124. matrix:
  125. mode:
  126. - plugin
  127. - standalone
  128. steps:
  129. -
  130. name: Checkout
  131. uses: actions/checkout@v3
  132. -
  133. name: Set up Docker Buildx
  134. uses: docker/setup-buildx-action@v2
  135. -
  136. name: Set up Go
  137. uses: actions/setup-go@v3
  138. with:
  139. go-version-file: 'go.mod'
  140. check-latest: true
  141. cache: true
  142. -
  143. name: Setup docker CLI
  144. run: |
  145. curl https://download.docker.com/linux/static/stable/x86_64/docker-${DOCKER_CLI_VERSION}.tgz | tar xz
  146. sudo cp ./docker/docker /usr/bin/ && rm -rf docker && docker version
  147. -
  148. name: Build
  149. uses: docker/bake-action@v2
  150. with:
  151. targets: binary
  152. set: |
  153. *.cache-from=type=gha,scope=binary-linux-amd64
  154. *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
  155. *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
  156. env:
  157. BUILD_TAGS: e2e
  158. -
  159. name: Setup tmate session
  160. if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
  161. uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
  162. with:
  163. limit-access-to-actor: true
  164. github-token: ${{ secrets.GITHUB_TOKEN }}
  165. -
  166. name: Test plugin mode
  167. if: ${{ matrix.mode == 'plugin' }}
  168. run: |
  169. make e2e-compose
  170. -
  171. name: Upload coverage to Codecov
  172. uses: codecov/codecov-action@v3
  173. -
  174. name: Test standalone mode
  175. if: ${{ matrix.mode == 'standalone' }}
  176. run: |
  177. rm -f /usr/local/bin/docker-compose
  178. cp bin/build/docker-compose /usr/local/bin
  179. make e2e-compose-standalone
  180. release:
  181. permissions:
  182. contents: write # to create a release (ncipollo/release-action)
  183. runs-on: ubuntu-latest
  184. needs:
  185. - binary
  186. steps:
  187. -
  188. name: Checkout
  189. uses: actions/checkout@v3
  190. -
  191. name: Download artifacts
  192. uses: actions/download-artifact@v3
  193. with:
  194. name: compose
  195. path: ${{ env.DESTDIR }}
  196. -
  197. name: Create checksums
  198. working-directory: ${{ env.DESTDIR }}
  199. run: |
  200. find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
  201. shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
  202. mv $RUNNER_TEMP/checksums.txt .
  203. cat checksums.txt | while read sum file; do echo "$sum $file" > ${file#\*}.sha256; done
  204. -
  205. name: License
  206. run: cp packaging/* ${{ env.DESTDIR }}/
  207. -
  208. name: List artifacts
  209. run: |
  210. tree -nh ${{ env.DESTDIR }}
  211. -
  212. name: Check artifacts
  213. run: |
  214. find ${{ env.DESTDIR }} -type f -exec file -e ascii -- {} +
  215. -
  216. name: GitHub Release
  217. if: startsWith(github.ref, 'refs/tags/v')
  218. uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
  219. with:
  220. artifacts: ${{ env.DESTDIR }}/*
  221. generateReleaseNotes: true
  222. draft: true
  223. token: ${{ secrets.GITHUB_TOKEN }}