github.yml 14 KB

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