main.yml 18 KB

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