main.yml 18 KB

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