ci.yml 6.1 KB

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