github.yml 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. name: VCMI
  2. on:
  3. push:
  4. branches:
  5. - features/*
  6. - beta
  7. - master
  8. pull_request:
  9. schedule:
  10. - cron: '0 2 * * *'
  11. workflow_dispatch:
  12. env:
  13. # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  14. BUILD_TYPE: Release
  15. jobs:
  16. check_last_build:
  17. if: github.event.schedule != ''
  18. runs-on: ubuntu-latest
  19. outputs:
  20. skip_build: ${{ steps.check_if_built.outputs.skip_build }}
  21. defaults:
  22. run:
  23. shell: bash
  24. steps:
  25. - name: Get repo name
  26. id: get_repo_name
  27. run: echo "::set-output name=value::${GITHUB_REPOSITORY#*/}"
  28. - name: Get last successful build for ${{ github.sha }}
  29. uses: octokit/[email protected]
  30. id: get_last_scheduled_run
  31. with:
  32. route: GET /repos/{owner}/{repo}/actions/runs
  33. owner: ${{ github.repository_owner }}
  34. repo: ${{ steps.get_repo_name.outputs.value }}
  35. status: success
  36. per_page: 1
  37. head_sha: ${{ github.sha }}
  38. env:
  39. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  40. - name: Check if successful build of the current commit exists
  41. id: check_if_built
  42. run: |
  43. if [ ${{ fromJson(steps.get_last_scheduled_run.outputs.data).total_count }} -gt 0 ]; then
  44. echo '::set-output name=skip_build::1'
  45. else
  46. echo '::set-output name=skip_build::0'
  47. fi
  48. - name: Cancel current run
  49. if: steps.check_if_built.outputs.skip_build == 1
  50. uses: octokit/[email protected]
  51. with:
  52. route: POST /repos/{owner}/{repo}/actions/runs/{run_id}/cancel
  53. owner: ${{ github.repository_owner }}
  54. repo: ${{ steps.get_repo_name.outputs.value }}
  55. run_id: ${{ github.run_id }}
  56. env:
  57. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  58. - name: Wait for the run to be cancelled
  59. if: steps.check_if_built.outputs.skip_build == 1
  60. run: sleep 60
  61. build:
  62. needs: check_last_build
  63. if: always() && needs.check_last_build.skip_build != 1
  64. strategy:
  65. matrix:
  66. include:
  67. - platform: linux
  68. os: ubuntu-20.04
  69. test: 0
  70. preset: linux-clang-release
  71. - platform: linux
  72. os: ubuntu-20.04
  73. test: 0
  74. preset: linux-gcc-release
  75. - platform: mac-intel
  76. os: macos-12
  77. test: 0
  78. pack: 1
  79. extension: dmg
  80. preset: macos-conan-ninja-release
  81. conan_profile: macos-intel
  82. artifact_platform: intel
  83. - platform: mac-arm
  84. os: macos-12
  85. test: 0
  86. pack: 1
  87. extension: dmg
  88. preset: macos-arm-conan-ninja-release
  89. conan_profile: macos-arm
  90. artifact_platform: arm
  91. - platform: ios
  92. os: macos-12
  93. test: 0
  94. pack: 1
  95. extension: ipa
  96. preset: ios-release-conan
  97. conan_profile: ios-arm64
  98. - platform: msvc
  99. os: windows-latest
  100. test: 0
  101. pack: 1
  102. extension: exe
  103. preset: windows-msvc-release
  104. runs-on: ${{ matrix.os }}
  105. defaults:
  106. run:
  107. shell: bash
  108. steps:
  109. - uses: actions/checkout@v3
  110. with:
  111. submodules: recursive
  112. - name: Dependencies
  113. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  114. env:
  115. MXE_TARGET: ${{ matrix.mxe }}
  116. VCMI_BUILD_PLATFORM: x64
  117. - uses: actions/setup-python@v4
  118. if: "${{ matrix.conan_profile != '' }}"
  119. with:
  120. python-version: '3.10'
  121. - name: Conan setup
  122. if: "${{ matrix.conan_profile != '' }}"
  123. run: |
  124. pip3 install conan
  125. conan profile new default --detect
  126. conan install . \
  127. --install-folder=conan-generated \
  128. --no-imports \
  129. --build=never \
  130. --profile:build=default \
  131. --profile:host=CI/conan/${{ matrix.conan_profile }} \
  132. --options with_apple_system_libs=True
  133. env:
  134. GENERATE_ONLY_BUILT_CONFIG: 1
  135. - name: Git branch name
  136. id: git-branch-name
  137. uses: EthanSK/git-branch-name-action@v1
  138. - name: Build Number
  139. run: |
  140. source '${{github.workspace}}/CI/get_package_name.sh'
  141. if [ '${{ matrix.artifact_platform }}' ]; then
  142. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  143. fi
  144. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  145. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  146. echo VCMI_PACKAGE_GITVERSION="$VCMI_PACKAGE_GITVERSION" >> $GITHUB_ENV
  147. env:
  148. PULL_REQUEST: ${{ github.event.pull_request.number }}
  149. - name: Configure CMake
  150. if: "${{ matrix.preset == '' }}"
  151. run: |
  152. mkdir -p '${{github.workspace}}/out/build/${{matrix.preset}}'
  153. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  154. cmake \
  155. ../.. -GNinja \
  156. ${{matrix.cmake_args}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
  157. -DENABLE_TEST=${{matrix.test}} \
  158. -DENABLE_STRICT_COMPILATION=ON \
  159. -DPACKAGE_NAME_SUFFIX:STRING="$VCMI_PACKAGE_NAME_SUFFIX" \
  160. -DPACKAGE_FILE_NAME:STRING="$VCMI_PACKAGE_FILE_NAME" \
  161. -DENABLE_GITVERSION="$VCMI_PACKAGE_GITVERSION"
  162. env:
  163. CC: ${{ matrix.cc }}
  164. CXX: ${{ matrix.cxx }}
  165. - name: CMake Preset
  166. if: "${{ matrix.preset != '' }}"
  167. run: |
  168. cmake --preset ${{ matrix.preset }}
  169. - name: Build
  170. if: "${{ matrix.preset == '' }}"
  171. run: |
  172. cmake --build '${{github.workspace}}/out/build/${{matrix.preset}}'
  173. - name: Build Preset
  174. if: "${{ matrix.preset != '' }}"
  175. run: |
  176. cmake --build --preset ${{matrix.preset}}
  177. - name: Test
  178. if: ${{ matrix.test == 1 && matrix.preset != ''}}
  179. run: |
  180. ctest --preset ${{matrix.preset}}
  181. - name: Pack
  182. id: cpack
  183. if: ${{ matrix.pack == 1 }}
  184. run: |
  185. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  186. CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
  187. "$CPACK_PATH" -C ${{env.BUILD_TYPE}} ${{ matrix.cpack_args }}
  188. test -f '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' \
  189. && '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' '${{github.workspace}}' "$(ls '${{ env.VCMI_PACKAGE_FILE_NAME }}'.*)"
  190. rm -rf _CPack_Packages
  191. - name: Additional logs
  192. if: ${{ failure() && steps.cpack.outcome == 'failure' && matrix.platform == 'mxe' }}
  193. run: |
  194. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/project.nsi'
  195. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/NSISOutput.log'
  196. - name: Artifacts
  197. if: ${{ matrix.pack == 1 }}
  198. uses: actions/upload-artifact@v3
  199. with:
  200. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  201. path: |
  202. ${{github.workspace}}/**/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
  203. - name: Upload build
  204. if: ${{ matrix.pack == 1 && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/features/')) && matrix.platform != 'msvc' }}
  205. run: |
  206. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  207. source '${{github.workspace}}/CI/upload_package.sh'
  208. env:
  209. DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
  210. PACKAGE_EXTENSION: ${{ matrix.extension }}
  211. - uses: act10ns/slack@v1
  212. with:
  213. status: ${{ job.status }}
  214. channel: '#notifications'
  215. env:
  216. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  217. if: always()
  218. - name: Trigger Android
  219. uses: peter-evans/repository-dispatch@v1
  220. if: ${{ (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/master') && matrix.platform == 'mxe' }}
  221. with:
  222. token: ${{ secrets.VCMI_ANDROID_ACCESS_TOKEN }}
  223. repository: vcmi/vcmi-android
  224. event-type: vcmi