main.yml 16 KB

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