github.yml 7.4 KB

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