main.yml 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. ######################################################################################
  2. # JME CI/CD
  3. ######################################################################################
  4. # Quick overview of what is going on in this script:
  5. # - Build natives for android
  6. # - Merge the natives, build the engine, create the zip release, maven artifacts, javadoc and native snapshot
  7. # - (only when native code changes) Deploy the natives snapshot to the MinIO instance
  8. # - (only when building a release) Deploy everything else to github releases and Sonatype
  9. # - (only when building a release) Update javadoc.jmonkeyengine.org
  10. # Note:
  11. # All the actions/upload-artifact and actions/download-artifact steps are used to pass
  12. # stuff between jobs, github actions has some sort of storage that is local to the
  13. # running workflow, we use it to store the result of each job since the filesystem
  14. # is not maintained between jobs.
  15. ################# CONFIGURATIONS #####################################################
  16. # >> Configure MINIO NATIVES SNAPSHOT
  17. # OBJECTS_KEY=XXXXXX
  18. # >> Configure SONATYPE RELEASE
  19. # CENTRAL_PASSWORD=XXXXXX
  20. # CENTRAL_USERNAME=XXXXXX
  21. # >> Configure SIGNING
  22. # SIGNING_KEY=XXXXXX
  23. # SIGNING_PASSWORD=XXXXXX
  24. # >> Configure PACKAGE REGISTRY RELEASE
  25. # Nothing to do here, everything is autoconfigured to work with the account/org that
  26. # is running the build.
  27. # >> Configure JAVADOC
  28. # JAVADOC_GHPAGES_REPO="riccardoblsandbox/javadoc.jmonkeyengine.org.git"
  29. # Generate a deploy key
  30. # ssh-keygen -t rsa -b 4096 -C "[email protected]" -f javadoc_deploy
  31. # Set
  32. # JAVADOC_GHPAGES_DEPLOY_PRIVKEY="......."
  33. # In github repo -> Settings, use javadoc_deploy.pub as Deploy key with write access
  34. ######################################################################################
  35. # Resources:
  36. # - Github actions docs: https://help.github.com/en/articles/about-github-actions
  37. # - Package registry docs: https://help.github.com/en/articles/about-github-package-registry
  38. # - Official actions: https://github.com/actions
  39. # - Community actions: https://github.com/sdras/awesome-actions
  40. ######################################################################################
  41. # - Riccardo Balbo
  42. ######################################################################################
  43. name: Build jMonkeyEngine
  44. on:
  45. push:
  46. branches:
  47. - master
  48. - v3.7
  49. - v3.6
  50. - v3.5
  51. - v3.4
  52. - v3.3
  53. - ios-2024_2
  54. pull_request:
  55. release:
  56. types: [published]
  57. jobs:
  58. ScreenshotTests:
  59. name: Run Screenshot Tests
  60. runs-on: ubuntu-latest
  61. container:
  62. image: ghcr.io/onemillionworlds/opengl-docker-image:v1
  63. permissions:
  64. contents: read
  65. steps:
  66. - uses: actions/checkout@v4
  67. - name: Start xvfb
  68. run: |
  69. Xvfb :99 -ac -screen 0 1024x768x16 &
  70. export DISPLAY=:99
  71. echo "DISPLAY=:99" >> $GITHUB_ENV
  72. - name: Report GL/Vulkan
  73. run: |
  74. set -x
  75. echo "DISPLAY=$DISPLAY"
  76. glxinfo | grep -E "OpenGL version|OpenGL renderer|OpenGL vendor" || true
  77. vulkaninfo --summary || true
  78. echo "VK_ICD_FILENAMES=$VK_ICD_FILENAMES"
  79. echo "MESA_LOADER_DRIVER_OVERRIDE=$MESA_LOADER_DRIVER_OVERRIDE"
  80. echo "GALLIUM_DRIVER=$GALLIUM_DRIVER"
  81. - name: Validate the Gradle wrapper
  82. uses: gradle/actions/wrapper-validation@v3
  83. - name: Test with Gradle Wrapper
  84. run: |
  85. ./gradlew :jme3-screenshot-test:screenshotTest
  86. - name: Upload Test Reports
  87. uses: actions/upload-artifact@master
  88. if: always()
  89. with:
  90. name: screenshot-test-report
  91. retention-days: 30
  92. path: |
  93. **/build/reports/**
  94. **/build/changed-images/**
  95. **/build/test-results/**
  96. # Build iOS natives
  97. BuildIosNatives:
  98. name: Build natives for iOS
  99. runs-on: macOS-14
  100. steps:
  101. - name: Check default JAVAs
  102. run: echo $JAVA_HOME --- $JAVA_HOME_8_X64 --- $JAVA_HOME_11_X64 --- $JAVA_HOME_17_X64 --- $JAVA_HOME_21_X64 ---
  103. - name: Setup the java environment
  104. uses: actions/setup-java@v4
  105. with:
  106. distribution: 'temurin'
  107. java-version: '11.0.26+4'
  108. - name: Setup the XCode version to 15.1.0
  109. uses: maxim-lobanov/setup-xcode@v1
  110. with:
  111. xcode-version: '15.1.0'
  112. - name: Clone the repo
  113. uses: actions/checkout@v4
  114. with:
  115. fetch-depth: 1
  116. - name: Validate the Gradle wrapper
  117. uses: gradle/actions/wrapper-validation@v3
  118. - name: Build
  119. run: |
  120. ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
  121. :jme3-ios-native:build
  122. - name: Upload natives
  123. uses: actions/upload-artifact@master
  124. with:
  125. name: ios-natives
  126. path: jme3-ios-native/template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework
  127. # Build the natives on android
  128. BuildAndroidNatives:
  129. name: Build natives for android
  130. runs-on: ubuntu-latest
  131. container:
  132. image: jmonkeyengine/buildenv-jme3:android
  133. steps:
  134. - name: Clone the repo
  135. uses: actions/checkout@v4
  136. with:
  137. fetch-depth: 1
  138. - name: Validate the Gradle wrapper
  139. uses: gradle/actions/wrapper-validation@v3
  140. - name: Build
  141. run: |
  142. ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
  143. :jme3-android-native:assemble
  144. - name: Upload natives
  145. uses: actions/upload-artifact@master
  146. with:
  147. name: android-natives
  148. path: build/native
  149. # Build the engine, we only deploy from ubuntu-latest jdk21
  150. BuildJMonkey:
  151. needs: [BuildAndroidNatives, BuildIosNatives]
  152. name: Build on ${{ matrix.osName }} jdk${{ matrix.jdk }}
  153. runs-on: ${{ matrix.os }}
  154. strategy:
  155. fail-fast: false
  156. matrix:
  157. os: [ubuntu-latest,windows-latest,macOS-latest]
  158. jdk: [11, 17, 21]
  159. include:
  160. - os: ubuntu-latest
  161. osName: linux
  162. deploy: true
  163. - os: windows-latest
  164. osName: windows
  165. deploy: false
  166. - os: macOS-latest
  167. osName: mac
  168. deploy: false
  169. - jdk: 11
  170. deploy: false
  171. - jdk: 17
  172. deploy: false
  173. steps:
  174. - name: Clone the repo
  175. uses: actions/checkout@v4
  176. with:
  177. fetch-depth: 1
  178. - name: Setup the java environment
  179. uses: actions/setup-java@v4
  180. with:
  181. distribution: 'temurin'
  182. java-version: ${{ matrix.jdk }}
  183. - name: Download natives for android
  184. uses: actions/download-artifact@master
  185. with:
  186. name: android-natives
  187. path: build/native
  188. - name: Download natives for iOS
  189. uses: actions/download-artifact@master
  190. with:
  191. name: ios-natives
  192. path: jme3-ios-native/template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework
  193. - name: Validate the Gradle wrapper
  194. uses: gradle/actions/wrapper-validation@v3
  195. - name: Build Engine
  196. shell: bash
  197. run: |
  198. # Normal build plus ZIP distribution and merged javadoc
  199. ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true \
  200. build createZipDistribution mergedJavadoc
  201. if [ "${{ matrix.deploy }}" = "true" ];
  202. then
  203. # We are going to need "zip"
  204. sudo apt-get update
  205. sudo apt-get install -y zip
  206. # We prepare the release for deploy
  207. mkdir -p ./dist/release/
  208. mv build/distributions/*.zip dist/release/
  209. # Install maven artifacts to ./dist/maven and sign them if possible
  210. if [ "${{ secrets.SIGNING_PASSWORD }}" = "" ];
  211. then
  212. echo "Configure the following secrets to enable signing:"
  213. echo "SIGNING_KEY, SIGNING_PASSWORD"
  214. ./gradlew publishMavenPublicationToDistRepository \
  215. -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
  216. --console=plain --stacktrace
  217. else
  218. ./gradlew publishMavenPublicationToDistRepository \
  219. -PsigningKey='${{ secrets.SIGNING_KEY }}' \
  220. -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
  221. -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
  222. --console=plain --stacktrace
  223. fi
  224. # Zip the natives into a single archive (we are going to use this to deploy native snapshots)
  225. echo "Create native zip"
  226. cdir="$PWD"
  227. cd "build/native"
  228. zip -r "$cdir/dist/jme3-natives.zip" *
  229. cd "$cdir"
  230. echo "Done"
  231. fi
  232. # Used later by DeploySnapshot
  233. - name: Upload merged natives
  234. if: matrix.deploy==true
  235. uses: actions/upload-artifact@master
  236. with:
  237. name: natives
  238. path: dist/jme3-natives.zip
  239. # Upload maven artifacts to be used later by the deploy job
  240. - name: Upload maven artifacts
  241. if: matrix.deploy==true
  242. uses: actions/upload-artifact@master
  243. with:
  244. name: maven
  245. path: dist/maven
  246. - name: Upload javadoc
  247. if: matrix.deploy==true
  248. uses: actions/upload-artifact@master
  249. with:
  250. name: javadoc
  251. path: dist/javadoc
  252. # Upload release archive to be used later by the deploy job
  253. - name: Upload release
  254. if: github.event_name == 'release' && matrix.deploy==true
  255. uses: actions/upload-artifact@master
  256. with:
  257. name: release
  258. path: dist/release
  259. # This job deploys the native snapshot.
  260. # The snapshot is downloaded when people build the engine without setting buildNativeProject
  261. # this is useful for people that want to build only the java part and don't have
  262. # all the stuff needed to compile natives.
  263. DeployNativeSnapshot:
  264. needs: [BuildJMonkey]
  265. name: "Deploy native snapshot"
  266. runs-on: ubuntu-latest
  267. if: github.event_name == 'push'
  268. steps:
  269. # We clone the repo manually, since we are going to push back a reference to the snapshot
  270. - name: Clone the repo
  271. run: |
  272. branch="${GITHUB_REF//refs\/heads\//}"
  273. if [ "$branch" != "" ];
  274. then
  275. git clone --single-branch --branch "$branch" https://github.com/${GITHUB_REPOSITORY}.git .
  276. fi
  277. - name: Download merged natives
  278. uses: actions/download-artifact@master
  279. with:
  280. name: natives
  281. path: dist/
  282. - name: Deploy natives snapshot
  283. run: |
  284. source .github/actions/tools/minio.sh
  285. NATIVE_CHANGES="yes"
  286. branch="${GITHUB_REF//refs\/heads\//}"
  287. if [ "$branch" != "" ];
  288. then
  289. if [ -f "natives-snapshot.properties" ];
  290. then
  291. nativeSnapshot=`cat "natives-snapshot.properties"`
  292. nativeSnapshot="${nativeSnapshot#*=}"
  293. # We deploy ONLY if GITHUB_SHA (the current commit hash) is newer than $nativeSnapshot
  294. if [ "`git rev-list --count $nativeSnapshot..$GITHUB_SHA`" = "0" ];
  295. then
  296. NATIVE_CHANGES=""
  297. else
  298. # We check if the native code changed.
  299. echo "Detect changes"
  300. NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-android-native/)"
  301. fi
  302. fi
  303. # We do nothing if there is no change
  304. if [ "$NATIVE_CHANGES" = "" ];
  305. then
  306. echo "No changes, skip."
  307. else
  308. if [ "${{ secrets.OBJECTS_KEY }}" = "" ];
  309. then
  310. echo "Configure the OBJECTS_KEY secret to enable natives snapshot deployment to MinIO"
  311. else
  312. # Deploy natives snapshot to a MinIO instance using function in minio.sh
  313. minio_uploadFile dist/jme3-natives.zip \
  314. native-snapshots/$GITHUB_SHA/jme3-natives.zip \
  315. https://objects.jmonkeyengine.org \
  316. jmonkeyengine \
  317. ${{ secrets.OBJECTS_KEY }}
  318. # We reference the snapshot by writing its commit hash in natives-snapshot.properties
  319. echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties
  320. # We commit the updated natives-snapshot.properties
  321. git config --global user.name "Github Actions"
  322. git config --global user.email "[email protected]"
  323. git add natives-snapshot.properties
  324. git commit -m "[skip ci] update natives snapshot"
  325. # Pull rebase from the remote repo, just in case there was a push in the meantime
  326. git pull -q --rebase
  327. # We need to calculate the header for git authentication
  328. header=$(echo -n "ad-m:${{ secrets.GITHUB_TOKEN }}" | base64)
  329. # Push
  330. (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true)
  331. fi
  332. fi
  333. fi
  334. # This job deploys snapshots on the master branch
  335. DeployJavaSnapshot:
  336. needs: [BuildJMonkey]
  337. name: Deploy Java Snapshot
  338. runs-on: ubuntu-latest
  339. if: github.event_name == 'push' && github.ref_name == 'master'
  340. steps:
  341. # We need to clone everything again for uploadToMaven.sh ...
  342. - name: Clone the repo
  343. uses: actions/checkout@v4
  344. with:
  345. fetch-depth: 1
  346. # Setup jdk 21 used for building Maven-style artifacts
  347. - name: Setup the java environment
  348. uses: actions/setup-java@v4
  349. with:
  350. distribution: 'temurin'
  351. java-version: '21'
  352. - name: Download natives for android
  353. uses: actions/download-artifact@master
  354. with:
  355. name: android-natives
  356. path: build/native
  357. - name: Download natives for iOS
  358. uses: actions/download-artifact@master
  359. with:
  360. name: ios-natives
  361. path: jme3-ios-native/template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework
  362. - name: Rebuild the maven artifacts and upload them to Sonatype's maven-snapshots repo
  363. run: |
  364. if [ "${{ secrets.CENTRAL_PASSWORD }}" = "" ];
  365. then
  366. echo "Configure the following secrets to enable uploading to Sonatype:"
  367. echo "CENTRAL_PASSWORD, CENTRAL_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
  368. else
  369. ./gradlew publishMavenPublicationToSNAPSHOTRepository \
  370. -PcentralPassword=${{ secrets.CENTRAL_PASSWORD }} \
  371. -PcentralUsername=${{ secrets.CENTRAL_USERNAME }} \
  372. -PsigningKey='${{ secrets.SIGNING_KEY }}' \
  373. -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
  374. -PuseCommitHashAsVersionName=true \
  375. --console=plain --stacktrace
  376. fi
  377. # This job deploys the release
  378. DeployRelease:
  379. needs: [BuildJMonkey]
  380. name: Deploy Release
  381. runs-on: ubuntu-latest
  382. if: github.event_name == 'release'
  383. steps:
  384. # We need to clone everything again for uploadToCentral.sh ...
  385. - name: Clone the repo
  386. uses: actions/checkout@v4
  387. with:
  388. fetch-depth: 1
  389. # Setup jdk 21 used for building Sonatype artifacts
  390. - name: Setup the java environment
  391. uses: actions/setup-java@v4
  392. with:
  393. distribution: 'temurin'
  394. java-version: '21'
  395. # Download all the stuff...
  396. - name: Download maven artifacts
  397. uses: actions/download-artifact@master
  398. with:
  399. name: maven
  400. path: dist/maven
  401. - name: Download release
  402. uses: actions/download-artifact@master
  403. with:
  404. name: release
  405. path: dist/release
  406. - name: Download natives for android
  407. uses: actions/download-artifact@master
  408. with:
  409. name: android-natives
  410. path: build/native
  411. - name: Download natives for iOS
  412. uses: actions/download-artifact@master
  413. with:
  414. name: ios-natives
  415. path: jme3-ios-native/template/META-INF/robovm/ios/libs/jme3-ios-native.xcframework
  416. - name: Rebuild the maven artifacts and upload them to Sonatype's Central Publisher Portal
  417. run: |
  418. if [ "${{ secrets.CENTRAL_PASSWORD }}" = "" ];
  419. then
  420. echo "Configure the following secrets to enable uploading to Sonatype:"
  421. echo "CENTRAL_PASSWORD, CENTRAL_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
  422. else
  423. ./gradlew publishMavenPublicationToCentralRepository \
  424. -PcentralPassword=${{ secrets.CENTRAL_PASSWORD }} \
  425. -PcentralUsername=${{ secrets.CENTRAL_USERNAME }} \
  426. -PsigningKey='${{ secrets.SIGNING_KEY }}' \
  427. -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
  428. -PuseCommitHashAsVersionName=true \
  429. --console=plain --stacktrace
  430. .github/actions/tools/uploadToCentral.sh \
  431. -p '${{ secrets.CENTRAL_PASSWORD }}' \
  432. -u '${{ secrets.CENTRAL_USERNAME }}'
  433. fi
  434. - name: Deploy to GitHub Releases
  435. run: |
  436. # We need to get the release id (yeah, it's not the same as the tag)
  437. echo "${GITHUB_EVENT_PATH}"
  438. cat ${GITHUB_EVENT_PATH}
  439. releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
  440. # Now that we have the id, we just upload the release zip from before
  441. echo "Upload to release $releaseId"
  442. filename="$(ls dist/release/*.zip)"
  443. url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
  444. echo "Upload to $url"
  445. curl -L \
  446. -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
  447. -H "Content-Type: application/zip" \
  448. --data-binary @"$filename" \
  449. "$url"
  450. - name: Deploy to github package registry
  451. run: |
  452. source .github/actions/tools/uploadToMaven.sh
  453. registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY"
  454. echo "Deploy to github package registry $registry"
  455. uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }}
  456. # Deploy the javadoc
  457. DeployJavaDoc:
  458. needs: [BuildJMonkey]
  459. name: Deploy Javadoc
  460. runs-on: ubuntu-latest
  461. if: github.event_name == 'release'
  462. steps:
  463. # We are going to need a deploy key for this, since we need
  464. # to push to a different repo
  465. - name: Set ssh key
  466. run: |
  467. mkdir -p ~/.ssh/
  468. echo "${{ secrets.JAVADOC_GHPAGES_DEPLOY_PRIVKEY }}" > $HOME/.ssh/deploy.key
  469. chmod 600 $HOME/.ssh/deploy.key
  470. # We clone the javadoc repo
  471. - name: Clone gh-pages
  472. run: |
  473. branch="gh-pages"
  474. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  475. git clone --single-branch --branch "$branch" [email protected]:${{ secrets.JAVADOC_GHPAGES_REPO }} .
  476. # Download the javadoc in the new directory "newdoc"
  477. - name: Download javadoc
  478. uses: actions/download-artifact@master
  479. with:
  480. name: javadoc
  481. path: newdoc
  482. # The actual deploy
  483. - name: Deploy to github pages
  484. run: |
  485. set -f
  486. IFS=$'\n'
  487. # Get the tag for this release
  488. version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
  489. # If there is no tag, then we do nothing.
  490. if [ "$version" != "" ];
  491. then
  492. echo "Deploy as $version"
  493. # Remove any older version of the javadoc for this tag
  494. if [ -d "$version" ];then rm -Rf "$version"; fi
  495. # Rename newdoc with the version name
  496. mv newdoc "$version"
  497. # if there isn't an index.txt we create one (we need this to list the versions)
  498. if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi
  499. index="`cat index.txt`"
  500. # Check if this version is already in index.txt
  501. addNew=true
  502. for v in $index;
  503. do
  504. if [ "$v" = "$version" ];
  505. then
  506. echo "$v" "$version"
  507. addNew=false
  508. break
  509. fi
  510. done
  511. # If not, we add it to the beginning
  512. if [ "$addNew" = "true" ];
  513. then
  514. echo -e "$version\n$index" > index.txt
  515. index="`cat index.txt`"
  516. fi
  517. # Regenerate the pages
  518. chmod +x make.sh
  519. ./make.sh
  520. # Configure git to use the deploy key
  521. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  522. # Commit the changes
  523. git config --global user.name "Github Actions"
  524. git config --global user.email "[email protected]"
  525. git add . || true
  526. git commit -m "$version" || true
  527. branch="gh-pages"
  528. git push origin "$branch" --force || true
  529. fi