main.yml 16 KB

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