main.yml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  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. fi
  316. fi
  317. # We do nothing if there is no change
  318. if [ "$NATIVE_CHANGES" = "" ];
  319. then
  320. echo "No changes, skip."
  321. else
  322. if [ "${{ secrets.BINTRAY_GENERIC_REPO }}" = "" ];
  323. then
  324. echo "Configure the following secrets to enable native snapshot deployment"
  325. echo "BINTRAY_GENERIC_REPO, BINTRAY_USER, BINTRAY_APIKEY"
  326. else
  327. # Deploy snapshot
  328. bintray_uploadFile dist/jme3-natives.zip \
  329. $GITHUB_SHA/$GITHUB_SHA/jme3-natives.zip \
  330. ${{ secrets.BINTRAY_GENERIC_REPO }} "content" "natives" \
  331. ${{ secrets.BINTRAY_USER }} \
  332. ${{ secrets.BINTRAY_APIKEY }} \
  333. "https://github.com/${GITHUB_REPOSITORY}" \
  334. "${{ secrets.BINTRAY_LICENSE }}" "true"
  335. # We reference the snapshot by writing its commit hash in natives-snapshot.properties
  336. echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties
  337. # We commit the updated natives-snapshot.properties
  338. git config --global user.name "Github Actions"
  339. git config --global user.email "[email protected]"
  340. git add natives-snapshot.properties
  341. git commit -m "[skip ci] update natives snapshot"
  342. # Pull rebase from the remote repo, just in case there was a push in the meantime
  343. git pull -q --rebase
  344. # We need to calculate the header for git authentication
  345. header=$(echo -n "ad-m:${{ secrets.GITHUB_TOKEN }}" | base64)
  346. # Push
  347. (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true)
  348. fi
  349. fi
  350. fi
  351. # This job deploys the release
  352. DeployRelease:
  353. needs: [BuildJMonkey]
  354. name: Deploy Release
  355. runs-on: ubuntu-18.04
  356. if: github.event_name == 'release'
  357. steps:
  358. # We need to clone everything again for uploadToMaven.sh ...
  359. - name: Clone the repo
  360. uses: actions/checkout@v2
  361. with:
  362. fetch-depth: 1
  363. # Download all the stuff...
  364. - name: Download maven artifacts
  365. uses: actions/download-artifact@master
  366. with:
  367. name: maven
  368. path: dist/maven
  369. - name: Download release
  370. uses: actions/download-artifact@master
  371. with:
  372. name: release
  373. path: dist/release
  374. - name: Deploy to github releases
  375. run: |
  376. # We need to get the release id (yeah, it's not the same as the tag)
  377. echo "${GITHUB_EVENT_PATH}"
  378. cat ${GITHUB_EVENT_PATH}
  379. releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
  380. # Now that we have the id, we just upload the release zip from before
  381. echo "Upload to release $releaseId"
  382. filename="$(ls dist/release/*.zip)"
  383. url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
  384. echo "Upload to $url"
  385. curl -L \
  386. -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
  387. -H "Content-Type: application/zip" \
  388. --data-binary @"$filename" \
  389. "$url"
  390. - name: Deploy to bintray
  391. run: |
  392. source .github/actions/tools/uploadToMaven.sh
  393. if [ "${{ secrets.BINTRAY_MAVEN_REPO }}" = "" ];
  394. then
  395. echo "Configure the following secrets to enable bintray deployment"
  396. echo "BINTRAY_MAVEN_REPO, BINTRAY_USER, BINTRAY_APIKEY"
  397. else
  398. 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 }}"
  399. fi
  400. # - name: Deploy to github package registry
  401. # run: |
  402. # source .github/actions/tools/uploadToMaven.sh
  403. # registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY"
  404. # echo "Deploy to github package registry $registry"
  405. # uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }}
  406. # Deploy the javadoc
  407. DeployJavaDoc:
  408. needs: [BuildJMonkey]
  409. name: Deploy Javadoc
  410. runs-on: ubuntu-18.04
  411. if: github.event_name == 'release'
  412. steps:
  413. # We are going to need a deploy key for this, since we need
  414. # to push to a different repo
  415. - name: Set ssh key
  416. run: |
  417. mkdir -p ~/.ssh/
  418. echo "${{ secrets.JAVADOC_GHPAGES_DEPLOY_PRIVKEY }}" > $HOME/.ssh/deploy.key
  419. chmod 600 $HOME/.ssh/deploy.key
  420. # We clone the javadoc repo
  421. - name: Clone gh-pages
  422. run: |
  423. branch="gh-pages"
  424. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  425. git clone --single-branch --branch "$branch" [email protected]:${{ secrets.JAVADOC_GHPAGES_REPO }} .
  426. # Download the javadoc in the new directory "newdoc"
  427. - name: Download javadoc
  428. uses: actions/download-artifact@master
  429. with:
  430. name: javadoc
  431. path: newdoc
  432. # The actual deploy
  433. - name: Deploy to github pages
  434. run: |
  435. set -f
  436. IFS=$'\n'
  437. # Get the tag for this release
  438. version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
  439. # If there is no tag, then we do nothing.
  440. if [ "$version" != "" ];
  441. then
  442. echo "Deploy as $version"
  443. # Remove any older version of the javadoc for this tag
  444. if [ -d "$version" ];then rm -Rf "$version"; fi
  445. # Rename newdoc with the version name
  446. mv newdoc "$version"
  447. # if there isn't an index.txt we create one (we need this to list the versions)
  448. if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi
  449. index="`cat index.txt`"
  450. # Check if this version is already in index.txt
  451. addNew=true
  452. for v in $index;
  453. do
  454. if [ "$v" = "$version" ];
  455. then
  456. echo "$v" "$version"
  457. addNew=false
  458. break
  459. fi
  460. done
  461. # If not, we add it to the beginning
  462. if [ "$addNew" = "true" ];
  463. then
  464. echo -e "$version\n$index" > index.txt
  465. index="`cat index.txt`"
  466. fi
  467. # Regenerate the pages
  468. chmod +x make.sh
  469. ./make.sh
  470. # Configure git to use the deploy key
  471. export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
  472. # Commit the changes
  473. git config --global user.name "Github Actions"
  474. git config --global user.email "[email protected]"
  475. git add . || true
  476. git commit -m "$version" || true
  477. branch="gh-pages"
  478. git push origin "$branch" --force || true
  479. fi