github.yml 7.6 KB

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