main.yml 19 KB

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