github.yml 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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-qt6
  68. os: ubuntu-22.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. conan_options: --options with_apple_system_libs=True
  83. artifact_platform: intel
  84. - platform: mac-arm
  85. os: macos-12
  86. test: 0
  87. pack: 1
  88. extension: dmg
  89. preset: macos-arm-conan-ninja-release
  90. conan_profile: macos-arm
  91. conan_options: --options with_apple_system_libs=True
  92. artifact_platform: arm
  93. - platform: ios
  94. os: macos-12
  95. test: 0
  96. pack: 1
  97. extension: ipa
  98. preset: ios-release-conan
  99. conan_profile: ios-arm64
  100. conan_options: --options with_apple_system_libs=True
  101. - platform: msvc
  102. os: windows-latest
  103. test: 0
  104. pack: 1
  105. extension: exe
  106. preset: windows-msvc-release
  107. - platform: mingw-ubuntu
  108. os: ubuntu-22.04
  109. test: 0
  110. pack: 1
  111. extension: exe
  112. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  113. cmake_args: -G Ninja
  114. preset: windows-mingw-conan-linux
  115. conan_profile: mingw64-linux.jinja
  116. - platform: android-32
  117. os: ubuntu-22.04
  118. extension: apk
  119. preset: android-conan-ninja-release
  120. conan_profile: android-32
  121. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  122. artifact_platform: armeabi-v7a
  123. - platform: android-64
  124. os: ubuntu-22.04
  125. extension: apk
  126. preset: android-conan-ninja-release
  127. conan_profile: android-64
  128. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  129. artifact_platform: aarch64-v8a
  130. runs-on: ${{ matrix.os }}
  131. defaults:
  132. run:
  133. shell: bash
  134. steps:
  135. - uses: actions/checkout@v3
  136. with:
  137. submodules: recursive
  138. - name: Dependencies
  139. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  140. env:
  141. VCMI_BUILD_PLATFORM: x64
  142. - uses: actions/setup-python@v4
  143. if: "${{ matrix.conan_profile != '' }}"
  144. with:
  145. python-version: '3.10'
  146. - name: Conan setup
  147. if: "${{ matrix.conan_profile != '' }}"
  148. run: |
  149. pip3 install 'conan<2.0'
  150. conan profile new default --detect
  151. conan install . \
  152. --install-folder=conan-generated \
  153. --no-imports \
  154. --build=never \
  155. --profile:build=default \
  156. --profile:host=CI/conan/${{ matrix.conan_profile }} \
  157. ${{ matrix.conan_options }}
  158. env:
  159. GENERATE_ONLY_BUILT_CONFIG: 1
  160. - name: Git branch name
  161. id: git-branch-name
  162. uses: EthanSK/git-branch-name-action@v1
  163. - name: Build Number
  164. run: |
  165. source '${{github.workspace}}/CI/get_package_name.sh'
  166. if [ '${{ matrix.artifact_platform }}' ]; then
  167. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  168. fi
  169. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  170. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  171. echo VCMI_PACKAGE_GITVERSION="$VCMI_PACKAGE_GITVERSION" >> $GITHUB_ENV
  172. env:
  173. PULL_REQUEST: ${{ github.event.pull_request.number }}
  174. - name: CMake Preset
  175. run: |
  176. cmake --preset ${{ matrix.preset }}
  177. - name: Build Preset
  178. run: |
  179. cmake --build --preset ${{matrix.preset}}
  180. - name: Test
  181. if: ${{ matrix.test == 1 }}
  182. run: |
  183. ctest --preset ${{matrix.preset}}
  184. - name: Pack
  185. id: cpack
  186. if: ${{ matrix.pack == 1 }}
  187. run: |
  188. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  189. CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
  190. "$CPACK_PATH" -C ${{env.BUILD_TYPE}} ${{ matrix.cpack_args }}
  191. test -f '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' \
  192. && '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' '${{github.workspace}}' "$(ls '${{ env.VCMI_PACKAGE_FILE_NAME }}'.*)"
  193. rm -rf _CPack_Packages
  194. - name: Create android package
  195. if: ${{ startsWith(matrix.platform, 'android') }}
  196. run: |
  197. cd android
  198. ./gradlew assembleDaily --info
  199. echo ANDROID_APK_PATH="$(ls ${{ github.workspace }}/android/vcmi-app/build/outputs/apk/daily/*.${{ matrix.extension }})" >> $GITHUB_ENV
  200. - name: Additional logs
  201. if: ${{ failure() && steps.cpack.outcome == 'failure' && matrix.platform == 'msvc' }}
  202. run: |
  203. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/project.nsi'
  204. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/NSISOutput.log'
  205. - name: Artifacts
  206. if: ${{ matrix.pack == 1 }}
  207. uses: actions/upload-artifact@v3
  208. with:
  209. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  210. path: |
  211. ${{github.workspace}}/out/build/${{matrix.preset}}/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
  212. - name: Android artifacts
  213. if: ${{ startsWith(matrix.platform, 'android') }}
  214. uses: actions/upload-artifact@v3
  215. with:
  216. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  217. path: |
  218. ${{ env.ANDROID_APK_PATH }}
  219. - name: Upload build
  220. if: ${{ (matrix.pack == 1 || startsWith(matrix.platform, 'android')) && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/features/')) && matrix.platform != 'msvc' }}
  221. continue-on-error: true
  222. run: |
  223. if cd '${{github.workspace}}/android/vcmi-app/build/outputs/apk/daily' ; then
  224. mv '${{ env.ANDROID_APK_PATH }}' "$VCMI_PACKAGE_FILE_NAME.${{ matrix.extension }}"
  225. else
  226. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  227. fi
  228. source '${{github.workspace}}/CI/upload_package.sh'
  229. env:
  230. DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
  231. PACKAGE_EXTENSION: ${{ matrix.extension }}
  232. - uses: act10ns/slack@v1
  233. with:
  234. status: ${{ job.status }}
  235. channel: '#notifications'
  236. env:
  237. SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
  238. if: always()