main.yml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 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
  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. # We reference the snapshot by writing its commit hash in natives-snapshot.properties
  232. echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties
  233. # We commit the updated natives-snapshot.properties
  234. git config --global user.name "Github Actions"
  235. git config --global user.email "[email protected]"
  236. git add natives-snapshot.properties
  237. git commit -m "[skip ci] update natives snapshot"
  238. # Pull rebase from the remote repo, just in case there was a push in the meantime
  239. git pull -q --rebase
  240. # We need to calculate the header for git authentication
  241. header=$(echo -n "ad-m:${{ secrets.GITHUB_TOKEN }}" | base64)
  242. # Push
  243. (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true)
  244. fi
  245. fi
  246. fi
  247. # This job deploys the release
  248. DeployRelease:
  249. needs: [BuildJMonkey]
  250. name: Deploy Release
  251. runs-on: ubuntu-18.04
  252. if: github.event_name == 'release'
  253. steps:
  254. # We need to clone everything again for uploadToMaven.sh ...
  255. - name: Clone the repo
  256. uses: actions/checkout@v2
  257. with:
  258. fetch-depth: 1
  259. # Download all the stuff...
  260. - name: Download maven artifacts
  261. uses: actions/download-artifact@master
  262. with:
  263. name: maven
  264. path: dist/maven
  265. - name: Download release
  266. uses: actions/download-artifact@master
  267. with:
  268. name: release
  269. path: dist/release
  270. - name: Deploy to github releases
  271. run: |
  272. # We need to get the release id (yeah, it's not the same as the tag)
  273. echo "${GITHUB_EVENT_PATH}"
  274. cat ${GITHUB_EVENT_PATH}
  275. releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
  276. # Now that we have the id, we just upload the release zip from before
  277. echo "Upload to release $releaseId"
  278. filename="$(ls dist/release/*.zip)"
  279. url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
  280. echo "Upload to $url"
  281. curl -L \
  282. -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
  283. -H "Content-Type: application/zip" \
  284. --data-binary @"$filename" \
  285. "$url"
  286. - name: Deploy to bintray
  287. run: |
  288. source .github/actions/tools/uploadToMaven.sh
  289. if [ "${{ secrets.BINTRAY_MAVEN_REPO }}" = "" ];
  290. then
  291. echo "Configure the following secrets to enable bintray deployment"
  292. echo "BINTRAY_MAVEN_REPO, BINTRAY_USER, BINTRAY_APIKEY"
  293. else
  294. 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 }}"
  295. fi
  296. # - name: Deploy to github package registry
  297. # run: |
  298. # source .github/actions/tools/uploadToMaven.sh
  299. # registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY"
  300. # echo "Deploy to github package registry $registry"
  301. # uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }}
  302. # Deploy the javadoc
  303. DeployJavaDoc:
  304. needs: [BuildJMonkey]
  305. name: Deploy Javadoc
  306. runs-on: ubuntu-18.04
  307. if: github.event_name == 'release'
  308. steps:
  309. # We are going to need a deploy key for this, since we need
  310. # to push to a different repo
  311. - name: Set ssh key
  312. run: |
  313. mkdir -p ~/.ssh/
  314. echo "${{ secrets.JAVADOC_GHPAGES_DEPLOY_PRIVKEY }}" > $HOME/.ssh/deploy.key
  315. chmod 600 $HOME/.ssh/deploy.key
  316. # We clone the javadoc repo
  317. - name: Clone gh-pages
  318. run: |
  319. branch="gh-pages"
  320. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  321. git clone --single-branch --branch "$branch" [email protected]:${{ secrets.JAVADOC_GHPAGES_REPO }} .
  322. # Download the javadoc in the new directory "newdoc"
  323. - name: Download javadoc
  324. uses: actions/download-artifact@master
  325. with:
  326. name: javadoc
  327. path: newdoc
  328. # The actual deploy
  329. - name: Deploy to github pages
  330. run: |
  331. set -f
  332. IFS=$'\n'
  333. # Get the tag for this release
  334. version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
  335. # If there is no tag, then we do nothing.
  336. if [ "$version" != "" ];
  337. then
  338. echo "Deploy as $version"
  339. # Remove any older version of the javadoc for this tag
  340. if [ -d "$version" ];then rm -Rf "$version"; fi
  341. # Rename newdoc with the version name
  342. mv newdoc "$version"
  343. # if there isn't an index.txt we create one (we need this to list the versions)
  344. if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi
  345. index="`cat index.txt`"
  346. # Check if this version is already in index.txt
  347. addNew=true
  348. for v in $index;
  349. do
  350. if [ "$v" = "$version" ];
  351. then
  352. echo "$v" "$version"
  353. addNew=false
  354. break
  355. fi
  356. done
  357. # If not, we add it to the beginning
  358. if [ "$addNew" = "true" ];
  359. then
  360. echo -e "$version\n$index" > index.txt
  361. index="`cat index.txt`"
  362. fi
  363. # Regenerate the pages
  364. chmod +x make.sh
  365. ./make.sh
  366. # Configure git to use the deploy key
  367. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  368. # Commit the changes
  369. git config --global user.name "Github Actions"
  370. git config --global user.email "[email protected]"
  371. git add . || true
  372. git commit -m "$version" || true
  373. branch="gh-pages"
  374. git push origin "$branch" --force || true
  375. fi