main.yml 17 KB

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