main.yml 19 KB

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