main.yml 16 KB

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