main.yml 19 KB

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