github.yml 7.8 KB

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