main.yml 19 KB

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