github.yml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. name: VCMI
  2. on:
  3. push:
  4. branches:
  5. - features/*
  6. - beta
  7. - master
  8. - develop
  9. pull_request:
  10. workflow_dispatch:
  11. env:
  12. # Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
  13. BUILD_TYPE: Release
  14. jobs:
  15. build:
  16. strategy:
  17. matrix:
  18. include:
  19. - platform: linux-qt6
  20. os: ubuntu-24.04
  21. test: 0
  22. preset: linux-clang-test
  23. - platform: linux
  24. os: ubuntu-24.04
  25. test: 1
  26. preset: linux-gcc-test
  27. - platform: linux
  28. os: ubuntu-20.04
  29. test: 0
  30. preset: linux-gcc-debug
  31. - platform: mac-intel
  32. os: macos-13
  33. test: 0
  34. pack: 1
  35. pack_type: Release
  36. extension: dmg
  37. preset: macos-conan-ninja-release
  38. conan_profile: macos-intel
  39. conan_options: --options with_apple_system_libs=True
  40. artifact_platform: intel
  41. - platform: mac-arm
  42. os: macos-13
  43. test: 0
  44. pack: 1
  45. pack_type: Release
  46. extension: dmg
  47. preset: macos-arm-conan-ninja-release
  48. conan_profile: macos-arm
  49. conan_options: --options with_apple_system_libs=True
  50. artifact_platform: arm
  51. - platform: ios
  52. os: macos-13
  53. test: 0
  54. pack: 1
  55. pack_type: Release
  56. extension: ipa
  57. preset: ios-release-conan-ccache
  58. conan_profile: ios-arm64
  59. conan_options: --options with_apple_system_libs=True
  60. - platform: msvc
  61. os: windows-latest
  62. test: 0
  63. pack: 1
  64. pack_type: RelWithDebInfo
  65. extension: exe
  66. preset: windows-msvc-release
  67. - platform: mingw
  68. os: ubuntu-22.04
  69. test: 0
  70. pack: 1
  71. pack_type: Release
  72. extension: exe
  73. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  74. cmake_args: -G Ninja
  75. preset: windows-mingw-conan-linux
  76. conan_profile: mingw64-linux.jinja
  77. - platform: mingw-32
  78. os: ubuntu-22.04
  79. test: 0
  80. pack: 1
  81. pack_type: Release
  82. extension: exe
  83. cpack_args: -D CPACK_NSIS_EXECUTABLE=`which makensis`
  84. cmake_args: -G Ninja
  85. preset: windows-mingw-conan-linux
  86. conan_profile: mingw32-linux.jinja
  87. - platform: android-32
  88. os: macos-14
  89. extension: apk
  90. preset: android-conan-ninja-release
  91. conan_profile: android-32
  92. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  93. artifact_platform: armeabi-v7a
  94. - platform: android-64
  95. os: macos-14
  96. extension: apk
  97. preset: android-conan-ninja-release
  98. conan_profile: android-64
  99. conan_options: --conf tools.android:ndk_path=$ANDROID_NDK_ROOT
  100. artifact_platform: arm64-v8a
  101. runs-on: ${{ matrix.os }}
  102. defaults:
  103. run:
  104. shell: bash
  105. steps:
  106. - uses: actions/checkout@v4
  107. with:
  108. submodules: recursive
  109. - name: Dependencies
  110. run: source '${{github.workspace}}/CI/${{matrix.platform}}/before_install.sh'
  111. env:
  112. VCMI_BUILD_PLATFORM: x64
  113. # ensure the ccache for each PR is separate so they don't interfere with each other
  114. # fall back to ccache of the vcmi/vcmi repo if no PR-specific ccache is found
  115. - name: ccache for PRs
  116. uses: hendrikmuhs/[email protected]
  117. if: ${{ github.event.number != '' }}
  118. with:
  119. key: ${{ matrix.preset }}-PR-${{ github.event.number }}
  120. restore-keys: |
  121. ${{ matrix.preset }}-PR-${{ github.event.number }}
  122. ${{ matrix.preset }}-no-PR
  123. # actual cache takes up less space, at most ~1 GB
  124. max-size: "5G"
  125. verbose: 2
  126. - name: ccache for everything but PRs
  127. uses: hendrikmuhs/[email protected]
  128. if: ${{ (github.repository == 'vcmi/vcmi' && github.event.number == '' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/beta' || github.ref == 'refs/heads/master')) || github.repository != 'vcmi/vcmi' }}
  129. with:
  130. key: ${{ matrix.preset }}-no-PR
  131. restore-keys: |
  132. ${{ matrix.preset }}-no-PR
  133. # actual cache takes up less space, at most ~1 GB
  134. max-size: "5G"
  135. verbose: 2
  136. - name: Prepare Heroes 3 data
  137. env:
  138. HEROES_3_DATA_PASSWORD: ${{ secrets.HEROES_3_DATA_PASSWORD }}
  139. if: ${{ env.HEROES_3_DATA_PASSWORD != '' && matrix.test == 1 }}
  140. run: |
  141. if [[ ${{github.repository_owner}} == vcmi ]]
  142. then
  143. data_url="https://github.com/vcmi-mods/vcmi-test-data/releases/download/v1.0/h3_assets.zip"
  144. else
  145. data_url="https://github.com/${{github.repository_owner}}/vcmi-test-data/releases/download/v1.0/h3_assets.zip"
  146. fi
  147. wget --progress=dot:giga "$data_url" -O h3_assets.zip
  148. 7za x h3_assets.zip -p$HEROES_3_DATA_PASSWORD
  149. mkdir -p ~/.local/share/vcmi/
  150. mv h3_assets/* ~/.local/share/vcmi/
  151. - uses: actions/setup-python@v5
  152. if: "${{ matrix.conan_profile != '' }}"
  153. with:
  154. python-version: '3.10'
  155. - name: Conan setup
  156. if: "${{ matrix.conan_profile != '' }}"
  157. run: |
  158. pip3 install 'conan<2.0'
  159. conan profile new default --detect
  160. conan install . \
  161. --install-folder=conan-generated \
  162. --no-imports \
  163. --build=never \
  164. --profile:build=default \
  165. --profile:host=CI/conan/${{ matrix.conan_profile }} \
  166. ${{ matrix.conan_options }}
  167. env:
  168. GENERATE_ONLY_BUILT_CONFIG: 1
  169. - uses: actions/setup-java@v4
  170. if: ${{ startsWith(matrix.platform, 'android') }}
  171. with:
  172. distribution: 'temurin'
  173. java-version: '11'
  174. # a hack to build ID for x64 build in order for Google Play to allow upload of both 32 and 64 bit builds
  175. - name: Bump Android x64 build ID
  176. if: ${{ matrix.platform == 'android-64' }}
  177. run: perl -i -pe 's/versionCode (\d+)/$x=$1+1; "versionCode $x"/e' android/vcmi-app/build.gradle
  178. - name: Build Number
  179. run: |
  180. source '${{github.workspace}}/CI/get_package_name.sh'
  181. if [ '${{ matrix.artifact_platform }}' ]; then
  182. VCMI_PACKAGE_FILE_NAME+="-${{ matrix.artifact_platform }}"
  183. fi
  184. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  185. echo VCMI_PACKAGE_NAME_SUFFIX="$VCMI_PACKAGE_NAME_SUFFIX" >> $GITHUB_ENV
  186. echo VCMI_PACKAGE_GOLDMASTER="$VCMI_PACKAGE_GOLDMASTER" >> $GITHUB_ENV
  187. env:
  188. PULL_REQUEST: ${{ github.event.pull_request.number }}
  189. - name: Configure
  190. run: |
  191. if [[ ${{matrix.preset}} == linux-gcc-test ]]
  192. then
  193. cmake -DENABLE_CCACHE:BOOL=ON -DCMAKE_C_COMPILER=gcc-14 -DCMAKE_CXX_COMPILER=g++-14 --preset ${{ matrix.preset }}
  194. elif [[ (${{matrix.preset}} == android-conan-ninja-release) && (${{github.ref}} != 'refs/heads/master') ]]
  195. then
  196. cmake -DENABLE_CCACHE:BOOL=ON -DANDROID_GRADLE_PROPERTIES="applicationIdSuffix=.daily;signingConfig=dailySigning;applicationLabel=VCMI daily" --preset ${{ matrix.preset }}
  197. elif [[ ${{matrix.platform}} != msvc ]]
  198. then
  199. cmake -DENABLE_CCACHE:BOOL=ON --preset ${{ matrix.preset }}
  200. else
  201. cmake --preset ${{ matrix.preset }}
  202. fi
  203. - name: Build
  204. run: |
  205. cmake --build --preset ${{matrix.preset}}
  206. env:
  207. ANDROID_STORE_PASSWORD: ${{ secrets.ANDROID_STORE_PASSWORD }}
  208. ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
  209. - name: Test
  210. env:
  211. HEROES_3_DATA_PASSWORD: ${{ secrets.HEROES_3_DATA_PASSWORD }}
  212. if: ${{ env.HEROES_3_DATA_PASSWORD != '' && matrix.test == 1 }}
  213. run: |
  214. ctest --preset ${{matrix.preset}}
  215. - name: Kill XProtect to work around CPack issue on macOS
  216. if: ${{ startsWith(matrix.platform, 'mac') }}
  217. run: |
  218. # Cf. https://github.com/actions/runner-images/issues/7522#issuecomment-1556766641
  219. echo Killing...; sudo pkill -9 XProtect >/dev/null || true;
  220. echo "Waiting..."; counter=0; while pgrep XProtect && ((counter < 20)); do sleep 3; ((counter++)); done
  221. pgrep XProtect || true
  222. - name: Pack
  223. id: cpack
  224. if: ${{ matrix.pack == 1 }}
  225. run: |
  226. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  227. CPACK_PATH=`which -a cpack | grep -m1 -v -i chocolatey`
  228. counter=0; until "$CPACK_PATH" -C ${{matrix.pack_type}} ${{ matrix.cpack_args }} || ((counter > 20)); do sleep 3; ((counter++)); done
  229. test -f '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' \
  230. && '${{github.workspace}}/CI/${{matrix.platform}}/post_pack.sh' '${{github.workspace}}' "$(ls '${{ env.VCMI_PACKAGE_FILE_NAME }}'.*)"
  231. rm -rf _CPack_Packages
  232. - name: Artifacts
  233. if: ${{ matrix.pack == 1 }}
  234. uses: actions/upload-artifact@v4
  235. with:
  236. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  237. path: |
  238. ${{github.workspace}}/out/build/${{matrix.preset}}/${{ env.VCMI_PACKAGE_FILE_NAME }}.${{ matrix.extension }}
  239. - name: Find Android package
  240. if: ${{ startsWith(matrix.platform, 'android') }}
  241. run: |
  242. builtApkPath="$(ls ${{ github.workspace }}/out/build/${{ matrix.preset }}/android-build/vcmi-app/build/outputs/apk/release/*.${{ matrix.extension }})"
  243. builtAabPath="$(ls ${{ github.workspace }}/out/build/${{ matrix.preset }}/android-build/vcmi-app/build/outputs/bundle/release/*.aab)"
  244. ANDROID_APK_PATH="${{ github.workspace }}/$VCMI_PACKAGE_FILE_NAME.${{ matrix.extension }}"
  245. ANDROID_AAB_PATH="${{ github.workspace }}/$VCMI_PACKAGE_FILE_NAME.aab"
  246. mv "$builtApkPath" "$ANDROID_APK_PATH"
  247. mv "$builtAabPath" "$ANDROID_AAB_PATH"
  248. echo "ANDROID_APK_PATH=$ANDROID_APK_PATH" >> $GITHUB_ENV
  249. echo "ANDROID_AAB_PATH=$ANDROID_AAB_PATH" >> $GITHUB_ENV
  250. - name: Android apk artifacts
  251. if: ${{ startsWith(matrix.platform, 'android') }}
  252. uses: actions/upload-artifact@v4
  253. with:
  254. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }}
  255. path: |
  256. ${{ env.ANDROID_APK_PATH }}
  257. - name: Android aab artifacts
  258. if: ${{ startsWith(matrix.platform, 'android') }}
  259. uses: actions/upload-artifact@v4
  260. with:
  261. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }} - aab
  262. path: |
  263. ${{ env.ANDROID_AAB_PATH }}
  264. - name: Symbols
  265. if: ${{ matrix.platform == 'msvc' }}
  266. uses: actions/upload-artifact@v4
  267. with:
  268. name: ${{ env.VCMI_PACKAGE_FILE_NAME }} - ${{ matrix.platform }} - symbols
  269. path: |
  270. ${{github.workspace}}/**/*.pdb
  271. - name: Upload build
  272. 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' && matrix.platform != 'mingw-32' }}
  273. continue-on-error: true
  274. run: |
  275. if [ -z '${{ env.ANDROID_APK_PATH }}' ] ; then
  276. cd '${{github.workspace}}/out/build/${{matrix.preset}}'
  277. fi
  278. source '${{github.workspace}}/CI/upload_package.sh'
  279. env:
  280. DEPLOY_RSA: ${{ secrets.DEPLOY_RSA }}
  281. PACKAGE_EXTENSION: ${{ matrix.extension }}
  282. deploy-src:
  283. if: always() && github.ref == 'refs/heads/master'
  284. runs-on: ubuntu-latest
  285. defaults:
  286. run:
  287. shell: bash
  288. steps:
  289. - uses: actions/checkout@v4
  290. with:
  291. submodules: recursive
  292. - name: Build Number
  293. run: |
  294. source '${{github.workspace}}/CI/get_package_name.sh'
  295. echo VCMI_PACKAGE_FILE_NAME="$VCMI_PACKAGE_FILE_NAME" >> $GITHUB_ENV
  296. - name: Create source code archive (including submodules)
  297. run: |
  298. git archive HEAD -o "release.tar" --worktree-attributes -v
  299. git submodule update --init --recursive
  300. git submodule --quiet foreach 'cd "$toplevel"; tar -rvf "release.tar" "$sm_path"'
  301. gzip release.tar
  302. - name: Upload source code archive
  303. uses: actions/upload-artifact@v4
  304. with:
  305. name: ${{ env.VCMI_PACKAGE_FILE_NAME }}
  306. path: |
  307. ./release.tar.gz
  308. validate-code:
  309. if: always()
  310. runs-on: ubuntu-24.04
  311. defaults:
  312. run:
  313. shell: bash
  314. steps:
  315. - uses: actions/checkout@v4
  316. - uses: actions/setup-python@v5
  317. if: "${{ matrix.conan_profile != '' }}"
  318. with:
  319. python-version: '3.10'
  320. - name: Ensure LF line endings
  321. run: |
  322. find . -path ./.git -prune -o -path ./AI/FuzzyLite -prune -o -path ./test/googletest \
  323. -o -path ./osx -prune -o -type f \
  324. -not -name '*.png' -and -not -name '*.ttf' -and -not -name '*.wav' -and -not -name '*.webm' -and -not -name '*.ico' -and -not -name '*.bat' -print0 | \
  325. { ! xargs -0 grep -l -z -P '\r\n'; }
  326. - name: Validate JSON
  327. run: |
  328. sudo apt install python3-jstyleson
  329. python3 CI/linux-qt6/validate_json.py