2
0

github.yml 14 KB

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