main.yml 16 KB

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