github.yml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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-test
  71. - platform: linux
  72. os: ubuntu-22.04
  73. test: 1
  74. preset: linux-gcc-test
  75. - platform: linux
  76. os: ubuntu-20.04
  77. test: 0
  78. preset: linux-gcc-debug
  79. - platform: mac-intel
  80. os: macos-12
  81. test: 0
  82. pack: 1
  83. pack_type: Release
  84. extension: dmg
  85. preset: macos-conan-ninja-release
  86. conan_profile: macos-intel
  87. conan_options: --options with_apple_system_libs=True
  88. artifact_platform: intel
  89. - platform: mac-arm
  90. os: macos-12
  91. test: 0
  92. pack: 1
  93. pack_type: Release
  94. extension: dmg
  95. preset: macos-arm-conan-ninja-release
  96. conan_profile: macos-arm
  97. conan_options: --options with_apple_system_libs=True
  98. artifact_platform: arm
  99. - platform: ios
  100. os: macos-12
  101. test: 0
  102. pack: 1
  103. pack_type: Release
  104. extension: ipa
  105. preset: ios-release-conan-ccache
  106. conan_profile: ios-arm64
  107. conan_options: --options with_apple_system_libs=True
  108. - platform: msvc
  109. os: windows-latest
  110. test: 0
  111. pack: 1
  112. pack_type: RelWithDebInfo
  113. extension: exe
  114. preset: windows-msvc-release-ccache
  115. - platform: mingw
  116. os: ubuntu-22.04
  117. test: 0
  118. pack: 1
  119. pack_type: Release
  120. extension: exe
  121. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  122. cmake_args: -G Ninja
  123. preset: windows-mingw-conan-linux
  124. conan_profile: mingw64-linux.jinja
  125. - platform: mingw-32
  126. os: ubuntu-22.04
  127. test: 0
  128. pack: 1
  129. pack_type: Release
  130. extension: exe
  131. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  132. cmake_args: -G Ninja
  133. preset: windows-mingw-conan-linux
  134. conan_profile: mingw32-linux.jinja
  135. - platform: android-32
  136. os: ubuntu-22.04
  137. extension: apk
  138. preset: android-conan-ninja-release
  139. conan_profile: android-32
  140. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  141. artifact_platform: armeabi-v7a
  142. - platform: android-64
  143. os: ubuntu-22.04
  144. extension: apk
  145. preset: android-conan-ninja-release
  146. conan_profile: android-64
  147. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  148. artifact_platform: arm64-v8a
  149. runs-on: ${{ matrix.os }}
  150. defaults:
  151. run:
  152. shell: bash
  153. steps:
  154. - uses: actions/checkout@v4
  155. with:
  156. submodules: recursive
  157. - name: Ensure LF line endings
  158. if: ${{ startsWith(matrix.preset, 'linux-clang-test') }}
  159. run: |
  160. find . -path ./.git -prune -o -path ./AI/FuzzyLite -prune -o -path ./test/googletest \
  161. -o -path ./osx -prune -o -type f \
  162. -not -name '*.png' -and -not -name '*.vcxproj*' -and -not -name '*.props' -and -not -name '*.wav' -and -not -name '*.webm' -and -not -name '*.ico' -and -not -name '*.bat' -print0 | \
  163. { ! xargs -0 grep -l -z -P '\r\n'; }
  164. - name: Validate JSON
  165. # the Python yaml module doesn't seem to work on mac-arm
  166. # also, running it on multiple presets is redundant and slightly increases already long CI built times
  167. if: ${{ startsWith(matrix.preset, 'linux-clang-test') }}
  168. run: |
  169. pip3 install json5 jstyleson
  170. python3 CI/linux-qt6/validate_json.py
  171. - name: Dependencies
  172. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  173. env:
  174. VCMI_BUILD_PLATFORM: x64
  175. # ensure the ccache for each PR is separate so they don't interfere with each other
  176. # fall back to ccache of the vcmi/vcmi repo if no PR-specific ccache is found
  177. - name: Ccache for PRs
  178. uses: hendrikmuhs/[email protected]
  179. if: ${{ github.event.number != '' }}
  180. with:
  181. key: ${{ matrix.preset }}-PR-${{ github.event.number }}
  182. restore-keys: |
  183. ${{ matrix.preset }}-PR-${{ github.event.number }}
  184. ${{ matrix.preset }}-no-PR
  185. # actual cache takes up less space, at most ~1 GB
  186. max-size: "5G"
  187. verbose: 2
  188. - name: Ccache for everything but PRs
  189. uses: hendrikmuhs/[email protected]
  190. if: ${{ github.event.number == '' }}
  191. with:
  192. key: ${{ matrix.preset }}-no-PR
  193. restore-keys: |
  194. ${{ matrix.preset }}-no-PR
  195. # actual cache takes up less space, at most ~1 GB
  196. max-size: "5G"
  197. verbose: 2
  198. - name: Prepare Heroes 3 data
  199. env:
  200. HEROES_3_DATA_PASSWORD: ${{ secrets.HEROES_3_DATA_PASSWORD }}
  201. if: ${{ env.HEROES_3_DATA_PASSWORD != '' && matrix.test == 1 }}
  202. run: |
  203. wget --progress=dot:giga https://github.com/vcmi-mods/vcmi-test-data/releases/download/v1.0/h3_assets.zip
  204. 7za x h3_assets.zip -p$HEROES_3_DATA_PASSWORD
  205. mkdir -p ~/.local/share/vcmi/
  206. mv h3_assets/* ~/.local/share/vcmi/
  207. - uses: actions/setup-python@v5
  208. if: "${{ matrix.conan_profile != '' }}"
  209. with:
  210. python-version: '3.10'
  211. - name: Conan setup
  212. if: "${{ matrix.conan_profile != '' }}"
  213. run: |
  214. pip3 install 'conan<2.0'
  215. conan profile new default --detect
  216. conan install . \
  217. --install-folder=conan-generated \
  218. --no-imports \
  219. --build=never \
  220. --profile:build=default \
  221. --profile:host=CI/conan/${{ matrix.conan_profile }} \
  222. ${{ matrix.conan_options }}
  223. env:
  224. GENERATE_ONLY_BUILT_CONFIG: 1
  225. - name: Build Number
  226. run: |
  227. source '${{github.workspace}}/CI/get_package_name.sh'
  228. if [ '${{ matrix.artifact_platform }}' ]; then
  229. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  230. fi
  231. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  232. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  233. echo VCMI_PACKAGE_GITVERSION="$VCMI_PACKAGE_GITVERSION" >> $GITHUB_ENV
  234. env:
  235. PULL_REQUEST: ${{ github.event.pull_request.number }}
  236. - name: Configure
  237. run: |
  238. if [[ ${{matrix.preset}} == linux-gcc-test ]]; then GCC13=1; fi
  239. cmake -DENABLE_CCACHE:BOOL=ON --preset ${{ matrix.preset }} ${GCC13:+-DCMAKE_C_COMPILER=gcc-13 -DCMAKE_CXX_COMPILER=g++-13}
  240. - name: Build
  241. run: |
  242. cmake --build --preset ${{matrix.preset}}
  243. - name: Test
  244. env:
  245. HEROES_3_DATA_PASSWORD: ${{ secrets.HEROES_3_DATA_PASSWORD }}
  246. if: ${{ env.HEROES_3_DATA_PASSWORD != '' && matrix.test == 1 }}
  247. run: |
  248. ctest --preset ${{matrix.preset}}
  249. - name: Pack
  250. id: cpack
  251. if: ${{ matrix.pack == 1 }}
  252. run: |
  253. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  254. CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
  255. "$CPACK_PATH" -C ${{matrix.pack_type}} ${{ matrix.cpack_args }}
  256. test -f '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' \
  257. && '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' '${{github.workspace}}' "$(ls '${{ env.VCMI_PACKAGE_FILE_NAME }}'.*)"
  258. rm -rf _CPack_Packages
  259. - name: Create android package
  260. if: ${{ startsWith(matrix.platform, 'android') }}
  261. run: |
  262. cd android
  263. ./gradlew assembleDaily --info
  264. echo ANDROID_APK_PATH="$(ls ${{ github.workspace }}/android/vcmi-app/build/outputs/apk/daily/*.${{ matrix.extension }})" >> $GITHUB_ENV
  265. - name: Additional logs
  266. if: ${{ failure() && steps.cpack.outcome == 'failure' && matrix.platform == 'msvc' }}
  267. run: |
  268. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/project.nsi'
  269. cat '${{github.workspace}}/out/build/${{matrix.preset}}/_CPack_Packages/win32/NSIS/NSISOutput.log'
  270. - name: Artifacts
  271. if: ${{ matrix.pack == 1 }}
  272. uses: actions/upload-artifact@v4
  273. with:
  274. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  275. path: |
  276. ${{github.workspace}}/out/build/${{matrix.preset}}/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
  277. - name: Android artifacts
  278. if: ${{ startsWith(matrix.platform, 'android') }}
  279. uses: actions/upload-artifact@v4
  280. with:
  281. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  282. path: |
  283. ${{ env.ANDROID_APK_PATH }}
  284. - name: Symbols
  285. if: ${{ matrix.platform == 'msvc' }}
  286. uses: actions/upload-artifact@v4
  287. with:
  288. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }} - symbols
  289. path: |
  290. ${{github.workspace}}/**/*.pdb
  291. - name: Android JNI ${{matrix.platform}}
  292. if: ${{ startsWith(matrix.platform, 'android') && github.ref == 'refs/heads/master' }}
  293. uses: actions/upload-artifact@v4
  294. with:
  295. name: Android JNI ${{matrix.platform}}
  296. path: |
  297. ${{ github.workspace }}/android/vcmi-app/src/main/jniLibs
  298. - name: Upload build
  299. 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' }}
  300. continue-on-error: true
  301. run: |
  302. if cd '${{github.workspace}}/android/vcmi-app/build/outputs/apk/daily' ; then
  303. mv '${{ env.ANDROID_APK_PATH }}' "$VCMI_PACKAGE_FILE_NAME.${{ matrix.extension }}"
  304. else
  305. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  306. fi
  307. source '${{github.workspace}}/CI/upload_package.sh'
  308. env:
  309. DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
  310. PACKAGE_EXTENSION: ${{ matrix.extension }}
  311. # copy-pasted mostly
  312. bundle_release:
  313. needs: build
  314. if: always() && github.ref == 'refs/heads/master'
  315. strategy:
  316. matrix:
  317. include:
  318. - platform: android-32
  319. os: ubuntu-22.04
  320. extension: aab
  321. preset: android-conan-ninja-release
  322. conan_profile: android-32
  323. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  324. artifact_platform: aab
  325. runs-on: ${{ matrix.os }}
  326. defaults:
  327. run:
  328. shell: bash
  329. steps:
  330. - uses: actions/checkout@v4
  331. with:
  332. submodules: recursive
  333. - name: Dependencies
  334. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  335. env:
  336. VCMI_BUILD_PLATFORM: x64
  337. - uses: actions/setup-python@v5
  338. if: "${{ matrix.conan_profile != '' }}"
  339. with:
  340. python-version: '3.10'
  341. - name: Conan setup
  342. if: "${{ matrix.conan_profile != '' }}"
  343. run: |
  344. pip3 install 'conan<2.0'
  345. conan profile new default --detect
  346. conan install . \
  347. --install-folder=conan-generated \
  348. --no-imports \
  349. --build=never \
  350. --profile:build=default \
  351. --profile:host=CI/conan/${{ matrix.conan_profile }} \
  352. ${{ matrix.conan_options }}
  353. env:
  354. GENERATE_ONLY_BUILT_CONFIG: 1
  355. - name: Build Number
  356. run: |
  357. source '${{github.workspace}}/CI/get_package_name.sh'
  358. if [ '${{ matrix.artifact_platform }}' ]; then
  359. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  360. fi
  361. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  362. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  363. echo VCMI_PACKAGE_GITVERSION="$VCMI_PACKAGE_GITVERSION" >> $GITHUB_ENV
  364. env:
  365. PULL_REQUEST: ${{ github.event.pull_request.number }}
  366. - name: CMake Preset
  367. run: |
  368. cmake --preset ${{ matrix.preset }}
  369. - name: Build Preset
  370. run: |
  371. cmake --build --preset ${{matrix.preset}}
  372. - name: Download libs x64
  373. uses: actions/download-artifact@v4
  374. with:
  375. name: Android JNI android-64
  376. path: ${{ github.workspace }}/android/vcmi-app/src/main/jniLibs/
  377. - name: Create android package
  378. run: |
  379. cd android
  380. ./gradlew bundleRelease --info
  381. echo ANDROID_APK_PATH="$(ls ${{ github.workspace }}/android/vcmi-app/build/outputs/bundle/release/*.aab)" >> $GITHUB_ENV
  382. env:
  383. ANDROID_STORE_PASSWORD: ${{ secrets.ANDROID_STORE_PASSWORD }}
  384. ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
  385. - name: Android artifacts
  386. uses: actions/upload-artifact@v4
  387. with:
  388. name: ${{ env.VCMI_PACKAGE_FILE_NAME }}
  389. path: |
  390. ${{ env.ANDROID_APK_PATH }}