main.yml 19 KB

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