2
0

main.yml 19 KB

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