main.yml 16 KB

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