main.yml 20 KB

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