main.yml 20 KB

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