github.yml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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
  95. - platform: mxe
  96. os: ubuntu-20.04
  97. mxe: i686-w64-mingw32.shared
  98. test: 0
  99. pack: 1
  100. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  101. extension: exe
  102. cmake_args: -G Ninja
  103. - platform: msvc
  104. os: windows-latest
  105. test: 0
  106. pack: 1
  107. extension: exe
  108. preset: windows-msvc-release
  109. runs-on: ${{ matrix.os }}
  110. defaults:
  111. run:
  112. shell: bash
  113. steps:
  114. - uses: actions/checkout@v3
  115. with:
  116. submodules: recursive
  117. - name: Dependencies
  118. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  119. env:
  120. MXE_TARGET: ${{ matrix.mxe }}
  121. VCMI_BUILD_PLATFORM: x64
  122. - name: Conan setup
  123. if: "${{ matrix.conan_profile != '' }}"
  124. run: |
  125. pip3 install conan
  126. conan profile new default --detect
  127. conan install . \
  128. --install-folder=conan-generated \
  129. --no-imports \
  130. --build=never \
  131. --profile:build=default \
  132. --profile:host=CI/conan/${{ matrix.conan_profile }}
  133. - name: Git branch name
  134. id: git-branch-name
  135. uses: EthanSK/git-branch-name-action@v1
  136. - name: Build Number
  137. run: |
  138. source '${{github.workspace}}/CI/get_package_name.sh'
  139. if [ '${{ matrix.artifact_platform }}' ]; then
  140. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  141. fi
  142. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  143. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  144. env:
  145. PULL_REQUEST: ${{ github.event.pull_request.number }}
  146. - name: Configure CMake
  147. if: "${{ matrix.preset == '' }}"
  148. run: |
  149. mkdir -p '${{github.workspace}}/out/build/${{matrix.preset}}'
  150. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  151. cmake \
  152. ../.. -GNinja \
  153. ${{matrix.cmake_args}} -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
  154. -DENABLE_TEST=${{matrix.test}} \
  155. -DPACKAGE_NAME_SUFFIX:STRING="$VCMI_PACKAGE_NAME_SUFFIX" \
  156. -DPACKAGE_FILE_NAME:STRING="$VCMI_PACKAGE_FILE_NAME"
  157. env:
  158. CC: ${{ matrix.cc }}
  159. CXX: ${{ matrix.cxx }}
  160. - name: CMake Preset
  161. if: "${{ matrix.preset != '' }}"
  162. run: |
  163. cmake --preset ${{ matrix.preset }}
  164. - name: Build
  165. if: "${{ matrix.preset == '' }}"
  166. run: |
  167. cmake --build '${{github.workspace}}/out/build/${{matrix.preset}}'
  168. - name: Build Preset
  169. if: "${{ matrix.preset != '' }}"
  170. run: |
  171. cmake --build --preset ${{matrix.preset}}
  172. - name: Test
  173. if: ${{ matrix.test == 1 && matrix.preset != ''}}
  174. run: |
  175. ctest --preset ${{matrix.preset}}
  176. - name: Pack
  177. id: cpack
  178. if: ${{ matrix.pack == 1 }}
  179. run: |
  180. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  181. CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
  182. "$CPACK_PATH" -C ${{env.BUILD_TYPE}} ${{ matrix.cpack_args }}
  183. test -f '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' \
  184. && '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' '${{github.workspace}}' "$(ls '${{ env.VCMI_PACKAGE_FILE_NAME }}'.*)"
  185. rm -rf _CPack_Packages
  186. - name: Additional logs
  187. if: ${{ failure() && steps.cpack.outcome == 'failure' && matrix.platform == 'mxe' }}
  188. run: |
  189. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/project.nsi'
  190. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/NSISOutput.log'
  191. - name: Artifacts
  192. if: ${{ matrix.pack == 1 }}
  193. uses: actions/upload-artifact@v3
  194. with:
  195. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  196. path: |
  197. ${{github.workspace}}/**/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
  198. - name: Upload build
  199. if: ${{ matrix.pack == 1 && (github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/heads/features/')) && matrix.platform != 'msvc' }}
  200. run: |
  201. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  202. source '${{github.workspace}}/CI/upload_package.sh'
  203. env:
  204. DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
  205. PACKAGE_EXTENSION: ${{ matrix.extension }}
  206. - uses: act10ns/slack@v1
  207. with:
  208. status: ${{ job.status }}
  209. channel: '#notifications'
  210. env:
  211. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  212. if: always()
  213. - name: Trigger Android
  214. uses: peter-evans/repository-dispatch@v1
  215. if: ${{ github.ref == 'refs/heads/develop' && matrix.platform == 'mxe' }}
  216. with:
  217. token: ${{ secrets.VCMI_ANDROID_ACCESS_TOKEN }}
  218. repository: vcmi/vcmi-android
  219. event-type: vcmi