main.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. ######################################################################################
  2. # JME CI/CD
  3. ######################################################################################
  4. # Quick overview of what is going on in this script:
  5. # - Build natives for android
  6. # - Build natives for linux arm
  7. # - Build natives for windows,mac,linux x86_64 and x86
  8. # - Merge the natives, build the engine, create the zip release, maven artifacts, javadoc and native snapshot
  9. # - (only when there is a change in the native code) Deploy the native snapshot to bintray
  10. # - (only when building a release) Deploy everything else to github releases, github packet registry and bintray
  11. # - (only when building a release) Update javadoc.jmonkeyengine.org
  12. # Note:
  13. # All the actions/upload-artifact and actions/download-artifact steps are used to pass
  14. # stuff between jobs, github actions has some sort of storage that is local to the
  15. # running workflow, we use it to store the result of each job since the filesystem
  16. # is not maintained between jobs.
  17. ################# CONFIGURATIONS #####################################################
  18. # >> Configure BINTRAY RELEASE & NATIVE SNAPSHOT
  19. # Configure the following secrets/variables (customize the values with your own)
  20. # BINTRAY_GENERIC_REPO=riccardoblsandbox/jmonkeyengine-files
  21. # BINTRAY_MAVEN_REPO=riccardoblsandbox/jmonkeyengine
  22. # BINTRAY_USER=riccardo
  23. # BINTRAY_APIKEY=XXXXXX
  24. # BINTRAY_LICENSE="BSD 3-Clause"
  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. - master
  49. - newbuild
  50. - v3.3.*
  51. - v3.2
  52. - v3.2.*
  53. pull_request:
  54. release:
  55. types: [published]
  56. jobs:
  57. # Builds the natives on linux arm
  58. BuildLinuxArmNatives:
  59. name: Build natives for linux (arm)
  60. runs-on: ubuntu-18.04
  61. container:
  62. image: riccardoblb/buildenv-jme3:linuxArm
  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. # Build
  73. # Note: since this is crossbuild we use the buildForPlatforms filter to tell
  74. # the buildscript wich platforms it should build for.
  75. ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildForPlatforms=LinuxArm,LinuxArmHF,LinuxArm64 -PbuildNativeProjects=true \
  76. :jme3-bullet-native:assemble
  77. - name: Upload natives
  78. uses: actions/upload-artifact@master
  79. with:
  80. name: linuxarm-natives
  81. path: build/native
  82. # Build the natives on android
  83. BuildAndroidNatives:
  84. name: Build natives for android
  85. runs-on: ubuntu-18.04
  86. container:
  87. image: riccardoblb/buildenv-jme3:android
  88. steps:
  89. - name: Clone the repo
  90. uses: actions/checkout@v2
  91. with:
  92. fetch-depth: 1
  93. - name: Validate the Gradle wrapper
  94. uses: gradle/wrapper-validation-action@v1
  95. - name: Build
  96. run: |
  97. ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
  98. :jme3-android-native:assemble \
  99. :jme3-bullet-native-android:assemble
  100. - name: Upload natives
  101. uses: actions/upload-artifact@master
  102. with:
  103. name: android-natives
  104. path: build/native
  105. # Build the natives
  106. BuildNatives:
  107. strategy:
  108. fail-fast: true
  109. matrix:
  110. os: [ubuntu-18.04,windows-2019,macOS-latest]
  111. jdk: [8.x.x]
  112. include:
  113. - os: ubuntu-18.04
  114. osName: linux
  115. - os: windows-2019
  116. osName: windows
  117. - os: macOS-latest
  118. osName: mac
  119. name: Build natives for ${{ matrix.osName }}
  120. runs-on: ${{ matrix.os }}
  121. steps:
  122. - name: Clone the repo
  123. uses: actions/checkout@v2
  124. with:
  125. fetch-depth: 1
  126. - name: Prepare java environment
  127. uses: actions/setup-java@v1
  128. with:
  129. java-version: ${{ matrix.jdk }}
  130. architecture: x64
  131. - name: Validate the Gradle wrapper
  132. uses: gradle/wrapper-validation-action@v1
  133. - name: Build Natives
  134. shell: bash
  135. env:
  136. OS_NAME: ${{ matrix.osName }}
  137. run: |
  138. # Install dependencies
  139. if [ "$OS_NAME" = "mac" ];
  140. then
  141. echo "Prepare mac"
  142. elif [ "$OS_NAME" = "linux" ];
  143. then
  144. echo "Prepare linux"
  145. sudo apt-get update
  146. sudo apt-get install -y gcc-multilib g++-multilib
  147. else
  148. echo "Prepare windows"
  149. fi
  150. # Build
  151. ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true -Dmaven.repo.local="$PWD/dist/maven" \
  152. build \
  153. :jme3-bullet-native:build
  154. # Upload natives to be used later by the BuildJMonkey job
  155. - name: Upload natives
  156. uses: actions/upload-artifact@master
  157. with:
  158. name: ${{ matrix.osName }}-natives
  159. path: build/native
  160. # Build the engine, we only deploy from ubuntu-18.04 jdk8
  161. BuildJMonkey:
  162. needs: [BuildNatives,BuildAndroidNatives]
  163. name: Build on ${{ matrix.osName }} jdk${{ matrix.jdk }}
  164. runs-on: ${{ matrix.os }}
  165. strategy:
  166. fail-fast: true
  167. matrix:
  168. os: [ubuntu-18.04,windows-2019,macOS-latest]
  169. jdk: [8.x.x,11.x.x]
  170. include:
  171. - os: ubuntu-18.04
  172. osName: linux
  173. deploy: true
  174. - os: windows-2019
  175. osName: windows
  176. - os: macOS-latest
  177. osName: mac
  178. - jdk: 11.x.x
  179. deploy: false
  180. steps:
  181. - name: Clone the repo
  182. uses: actions/checkout@v2
  183. with:
  184. fetch-depth: 1
  185. - name: Setup the java environment
  186. uses: actions/setup-java@v1
  187. with:
  188. java-version: ${{ matrix.jdk }}
  189. architecture: x64
  190. - name: Download natives for linux
  191. uses: actions/download-artifact@master
  192. with:
  193. name: linux-natives
  194. path: build/native
  195. - name: Download natives for windows
  196. uses: actions/download-artifact@master
  197. with:
  198. name: windows-natives
  199. path: build/native
  200. - name: Download natives for mac
  201. uses: actions/download-artifact@master
  202. with:
  203. name: mac-natives
  204. path: build/native
  205. - name: Download natives for android
  206. uses: actions/download-artifact@master
  207. with:
  208. name: android-natives
  209. path: build/native
  210. - name: Download natives for linux (arm)
  211. uses: actions/download-artifact@master
  212. with:
  213. name: linuxarm-natives
  214. path: build/native
  215. - name: Validate the Gradle wrapper
  216. uses: gradle/wrapper-validation-action@v1
  217. - name: Build Engine
  218. shell: bash
  219. run: |
  220. # Build
  221. ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true build
  222. if [ "${{ matrix.deploy }}" = "true" ];
  223. then
  224. # We are going to need "zip"
  225. sudo apt-get update
  226. sudo apt-get install -y zip
  227. # Create the zip release and the javadoc
  228. ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true mergedJavadoc createZipDistribution
  229. # We prepare the release for deploy
  230. mkdir -p ./dist/release/
  231. mv build/distributions/*.zip dist/release/
  232. # Create the maven artifacts
  233. mkdir -p ./dist/maven/
  234. ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true install -Dmaven.repo.local="$PWD/dist/maven"
  235. # Zip the natives into a single archive (we are going to use this to deploy native snapshots)
  236. echo "Create native zip"
  237. cdir="$PWD"
  238. cd "build/native"
  239. zip -r "$cdir/dist/jme3-natives.zip" *
  240. cd "$cdir"
  241. echo "Done"
  242. fi
  243. # Used later by DeploySnapshot
  244. - name: Upload merged natives
  245. if: matrix.deploy==true
  246. uses: actions/upload-artifact@master
  247. with:
  248. name: natives
  249. path: dist/jme3-natives.zip
  250. # Upload maven artifacts to be used later by the deploy job
  251. - name: Upload maven artifacts
  252. if: matrix.deploy==true
  253. uses: actions/upload-artifact@master
  254. with:
  255. name: maven
  256. path: dist/maven
  257. - name: Upload javadoc
  258. if: matrix.deploy==true
  259. uses: actions/upload-artifact@master
  260. with:
  261. name: javadoc
  262. path: dist/javadoc
  263. # Upload release archive to be used later by the deploy job
  264. - name: Upload release
  265. if: github.event_name == 'release' && matrix.deploy==true
  266. uses: actions/upload-artifact@master
  267. with:
  268. name: release
  269. path: dist/release
  270. # This job deploys the native snapshot.
  271. # The snapshot is downloaded when people build the engine without setting buildNativeProject
  272. # this is useful for people that want to build only the java part and don't have
  273. # all the stuff needed to compile natives.
  274. DeploySnapshot:
  275. needs: [BuildJMonkey]
  276. name: "Deploy snapshot"
  277. runs-on: ubuntu-18.04
  278. if: github.event_name == 'push'
  279. steps:
  280. # We clone the repo manually, since we are going to push back a reference to the snapshot
  281. - name: Clone the repo
  282. run: |
  283. branch="${GITHUB_REF//refs\/heads\//}"
  284. if [ "$branch" != "" ];
  285. then
  286. git clone --single-branch --branch "$branch" https://github.com/${GITHUB_REPOSITORY}.git .
  287. fi
  288. - name: Download merged natives
  289. uses: actions/download-artifact@master
  290. with:
  291. name: natives
  292. path: dist/
  293. - name: Deploy natives snapshot
  294. run: |
  295. source .github/actions/tools/bintray.sh
  296. NATIVE_CHANGES="yes"
  297. branch="${GITHUB_REF//refs\/heads\//}"
  298. if [ "$branch" != "" ];
  299. then
  300. if [ -f "natives-snapshot.properties" ];
  301. then
  302. nativeSnapshot=`cat "natives-snapshot.properties"`
  303. nativeSnapshot="${nativeSnapshot#*=}"
  304. # We deploy ONLY if GITHUB_SHA (the current commit hash) is newer than $nativeSnapshot
  305. if [ "`git rev-list --count $nativeSnapshot..$GITHUB_SHA`" = "0" ];
  306. then
  307. NATIVE_CHANGES=""
  308. else
  309. # We check if the native code changed.
  310. echo "Detect changes"
  311. NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet-native/)"
  312. if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-android-native/)"; fi
  313. if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet-native-android/)"; fi
  314. if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-bullet/)"; fi
  315. # The bulletUrl (in gradle.properties) might have changed.
  316. if [ "$NATIVE_CHANGES" = "" ];then NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- gradle.properties)"; fi
  317. fi
  318. fi
  319. # We do nothing if there is no change
  320. if [ "$NATIVE_CHANGES" = "" ];
  321. then
  322. echo "No changes, skip."
  323. else
  324. if [ "${{ secrets.BINTRAY_GENERIC_REPO }}" = "" ];
  325. then
  326. echo "Configure the following secrets to enable native snapshot deployment"
  327. echo "BINTRAY_GENERIC_REPO, BINTRAY_USER, BINTRAY_APIKEY"
  328. else
  329. # Deploy snapshot
  330. bintray_uploadFile dist/jme3-natives.zip \
  331. $GITHUB_SHA/$GITHUB_SHA/jme3-natives.zip \
  332. ${{ secrets.BINTRAY_GENERIC_REPO }} "content" "natives" \
  333. ${{ secrets.BINTRAY_USER }} \
  334. ${{ secrets.BINTRAY_APIKEY }} \
  335. "https://github.com/${GITHUB_REPOSITORY}" \
  336. "${{ secrets.BINTRAY_LICENSE }}" "true"
  337. # We reference the snapshot by writing its commit hash in natives-snapshot.properties
  338. echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties
  339. # We commit the updated natives-snapshot.properties
  340. git config --global user.name "Github Actions"
  341. git config --global user.email "[email protected]"
  342. git add natives-snapshot.properties
  343. git commit -m "[skip ci] update natives snapshot"
  344. # Pull rebase from the remote repo, just in case there was a push in the meantime
  345. git pull -q --rebase
  346. # We need to calculate the header for git authentication
  347. header=$(echo -n "ad-m:${{ secrets.GITHUB_TOKEN }}" | base64)
  348. # Push
  349. (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true)
  350. fi
  351. fi
  352. fi
  353. # This job deploys the release
  354. DeployRelease:
  355. needs: [BuildJMonkey]
  356. name: Deploy Release
  357. runs-on: ubuntu-18.04
  358. if: github.event_name == 'release'
  359. steps:
  360. # We need to clone everything again for uploadToMaven.sh ...
  361. - name: Clone the repo
  362. uses: actions/checkout@v2
  363. with:
  364. fetch-depth: 1
  365. # Download all the stuff...
  366. - name: Download maven artifacts
  367. uses: actions/download-artifact@master
  368. with:
  369. name: maven
  370. path: dist/maven
  371. - name: Download release
  372. uses: actions/download-artifact@master
  373. with:
  374. name: release
  375. path: dist/release
  376. - name: Deploy to github releases
  377. run: |
  378. # We need to get the release id (yeah, it's not the same as the tag)
  379. echo "${GITHUB_EVENT_PATH}"
  380. cat ${GITHUB_EVENT_PATH}
  381. releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
  382. # Now that we have the id, we just upload the release zip from before
  383. echo "Upload to release $releaseId"
  384. filename="$(ls dist/release/*.zip)"
  385. url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
  386. echo "Upload to $url"
  387. curl -L \
  388. -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
  389. -H "Content-Type: application/zip" \
  390. --data-binary @"$filename" \
  391. "$url"
  392. - name: Deploy to bintray
  393. run: |
  394. source .github/actions/tools/uploadToMaven.sh
  395. if [ "${{ secrets.BINTRAY_MAVEN_REPO }}" = "" ];
  396. then
  397. echo "Configure the following secrets to enable bintray deployment"
  398. echo "BINTRAY_MAVEN_REPO, BINTRAY_USER, BINTRAY_APIKEY"
  399. else
  400. 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 }}"
  401. fi
  402. # - name: Deploy to github package registry
  403. # run: |
  404. # source .github/actions/tools/uploadToMaven.sh
  405. # registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY"
  406. # echo "Deploy to github package registry $registry"
  407. # uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }}
  408. # Deploy the javadoc
  409. DeployJavaDoc:
  410. needs: [BuildJMonkey]
  411. name: Deploy Javadoc
  412. runs-on: ubuntu-18.04
  413. if: github.event_name == 'release'
  414. steps:
  415. # We are going to need a deploy key for this, since we need
  416. # to push to a different repo
  417. - name: Set ssh key
  418. run: |
  419. mkdir -p ~/.ssh/
  420. echo "${{ secrets.JAVADOC_GHPAGES_DEPLOY_PRIVKEY }}" > $HOME/.ssh/deploy.key
  421. chmod 600 $HOME/.ssh/deploy.key
  422. # We clone the javadoc repo
  423. - name: Clone gh-pages
  424. run: |
  425. branch="gh-pages"
  426. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  427. git clone --single-branch --branch "$branch" [email protected]:${{ secrets.JAVADOC_GHPAGES_REPO }} .
  428. # Download the javadoc in the new directory "newdoc"
  429. - name: Download javadoc
  430. uses: actions/download-artifact@master
  431. with:
  432. name: javadoc
  433. path: newdoc
  434. # The actual deploy
  435. - name: Deploy to github pages
  436. run: |
  437. set -f
  438. IFS=$'\n'
  439. # Get the tag for this release
  440. version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
  441. # If there is no tag, then we do nothing.
  442. if [ "$version" != "" ];
  443. then
  444. echo "Deploy as $version"
  445. # Remove any older version of the javadoc for this tag
  446. if [ -d "$version" ];then rm -Rf "$version"; fi
  447. # Rename newdoc with the version name
  448. mv newdoc "$version"
  449. # if there isn't an index.txt we create one (we need this to list the versions)
  450. if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi
  451. index="`cat index.txt`"
  452. # Check if this version is already in index.txt
  453. addNew=true
  454. for v in $index;
  455. do
  456. if [ "$v" = "$version" ];
  457. then
  458. echo "$v" "$version"
  459. addNew=false
  460. break
  461. fi
  462. done
  463. # If not, we add it to the beginning
  464. if [ "$addNew" = "true" ];
  465. then
  466. echo -e "$version\n$index" > index.txt
  467. index="`cat index.txt`"
  468. fi
  469. # Regenerate the pages
  470. chmod +x make.sh
  471. ./make.sh
  472. # Configure git to use the deploy key
  473. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  474. # Commit the changes
  475. git config --global user.name "Github Actions"
  476. git config --global user.email "[email protected]"
  477. git add . || true
  478. git commit -m "$version" || true
  479. branch="gh-pages"
  480. git push origin "$branch" --force || true
  481. fi