main.yml 18 KB

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