| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455 |
- ######################################################################################
- # JME CI/CD
- ######################################################################################
- # Quick overview of what is going on in this script:
- # - Build natives for android
- # - Merge the natives, build the engine, create the zip release, maven artifacts, javadoc and native snapshot
- # - (only when native code changes) Deploy the natives snapshot to the MinIO instance
- # - (only when building a release) Deploy everything else to github releases and Sonatype
- # - (only when building a release) Update javadoc.jmonkeyengine.org
- # Note:
- # All the actions/upload-artifact and actions/download-artifact steps are used to pass
- # stuff between jobs, github actions has some sort of storage that is local to the
- # running workflow, we use it to store the result of each job since the filesystem
- # is not maintained between jobs.
- ################# CONFIGURATIONS #####################################################
- # >> Configure MINIO NATIVES SNAPSHOT
- # OBJECTS_KEY=XXXXXX
- # >> Configure SONATYPE RELEASE
- # OSSRH_PASSWORD=XXXXXX
- # OSSRH_USERNAME=XXXXXX
- # >> Configure SIGNING
- # SIGNING_KEY=XXXXXX
- # SIGNING_PASSWORD=XXXXXX
- # >> Configure PACKAGE REGISTRY RELEASE
- # Nothing to do here, everything is autoconfigured to work with the account/org that
- # is running the build.
- # >> Configure JAVADOC
- # JAVADOC_GHPAGES_REPO="riccardoblsandbox/javadoc.jmonkeyengine.org.git"
- # Generate a deploy key
- # ssh-keygen -t rsa -b 4096 -C "[email protected]" -f javadoc_deploy
- # Set
- # JAVADOC_GHPAGES_DEPLOY_PRIVKEY="......."
- # In github repo -> Settings, use javadoc_deploy.pub as Deploy key with write access
- ######################################################################################
- # Resources:
- # - Github actions docs: https://help.github.com/en/articles/about-github-actions
- # - Package registry docs: https://help.github.com/en/articles/about-github-package-registry
- # - Official actions: https://github.com/actions
- # - Community actions: https://github.com/sdras/awesome-actions
- ######################################################################################
- # - Riccardo Balbo
- ######################################################################################
- name: Build jMonkeyEngine
- on:
- push:
- branches:
- - master
- - v3.5
- - v3.4
- - v3.3
- pull_request:
- release:
- types: [published]
- jobs:
- # Build the natives on android
- BuildAndroidNatives:
- name: Build natives for android
- runs-on: ubuntu-18.04
- container:
- image: jmonkeyengine/buildenv-jme3:android
- steps:
- - name: Clone the repo
- uses: actions/checkout@v2
- with:
- fetch-depth: 1
- - name: Validate the Gradle wrapper
- uses: gradle/[email protected]
- - name: Build
- run: |
- ./gradlew -PuseCommitHashAsVersionName=true --no-daemon -PbuildNativeProjects=true \
- :jme3-android-native:assemble
- - name: Upload natives
- uses: actions/upload-artifact@master
- with:
- name: android-natives
- path: build/native
- # Build the engine, we only deploy from ubuntu-18.04 jdk8
- BuildJMonkey:
- needs: [BuildAndroidNatives]
- name: Build on ${{ matrix.osName }} jdk${{ matrix.jdk }}
- runs-on: ${{ matrix.os }}
- strategy:
- fail-fast: false
- matrix:
- os: [ubuntu-18.04,ubuntu-20.04,windows-2019,macOS-latest]
- jdk: [8.x.x,11.x.x]
- include:
- - os: ubuntu-20.04
- osName: linux-next
- - os: ubuntu-18.04
- osName: linux
- deploy: true
- - os: windows-2019
- osName: windows
- - os: macOS-latest
- osName: mac
- - jdk: 11.x.x
- deploy: false
- steps:
- - name: Clone the repo
- uses: actions/checkout@v2
- with:
- fetch-depth: 1
- - name: Setup the java environment
- uses: actions/setup-java@v1
- with:
- java-version: ${{ matrix.jdk }}
- architecture: x64
- - name: Download natives for android
- uses: actions/download-artifact@master
- with:
- name: android-natives
- path: build/native
- - name: Validate the Gradle wrapper
- uses: gradle/[email protected]
- - name: Build Engine
- shell: bash
- run: |
- # Build
- ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true build
- if [ "${{ matrix.deploy }}" = "true" ];
- then
- # We are going to need "zip"
- sudo apt-get update
- sudo apt-get install -y zip
- # Create the zip release and the javadoc
- ./gradlew -PuseCommitHashAsVersionName=true -PskipPrebuildLibraries=true mergedJavadoc createZipDistribution
- # We prepare the release for deploy
- mkdir -p ./dist/release/
- mv build/distributions/*.zip dist/release/
- # Install maven artifacts to ./dist/maven and sign them if possible
- if [ "${{ secrets.SIGNING_PASSWORD }}" = "" ];
- then
- echo "Configure the following secrets to enable signing:"
- echo "SIGNING_KEY, SIGNING_PASSWORD"
- ./gradlew publishMavenPublicationToDistRepository \
- -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
- --console=plain --stacktrace
- else
- ./gradlew publishMavenPublicationToDistRepository \
- -PsigningKey='${{ secrets.SIGNING_KEY }}' \
- -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
- -PskipPrebuildLibraries=true -PuseCommitHashAsVersionName=true \
- --console=plain --stacktrace
- fi
- # Zip the natives into a single archive (we are going to use this to deploy native snapshots)
- echo "Create native zip"
- cdir="$PWD"
- cd "build/native"
- zip -r "$cdir/dist/jme3-natives.zip" *
- cd "$cdir"
- echo "Done"
- fi
- # Used later by DeploySnapshot
- - name: Upload merged natives
- if: matrix.deploy==true
- uses: actions/upload-artifact@master
- with:
- name: natives
- path: dist/jme3-natives.zip
- # Upload maven artifacts to be used later by the deploy job
- - name: Upload maven artifacts
- if: matrix.deploy==true
- uses: actions/upload-artifact@master
- with:
- name: maven
- path: dist/maven
- - name: Upload javadoc
- if: matrix.deploy==true
- uses: actions/upload-artifact@master
- with:
- name: javadoc
- path: dist/javadoc
- # Upload release archive to be used later by the deploy job
- - name: Upload release
- if: github.event_name == 'release' && matrix.deploy==true
- uses: actions/upload-artifact@master
- with:
- name: release
- path: dist/release
- # This job deploys the native snapshot.
- # The snapshot is downloaded when people build the engine without setting buildNativeProject
- # this is useful for people that want to build only the java part and don't have
- # all the stuff needed to compile natives.
- DeploySnapshot:
- needs: [BuildJMonkey]
- name: "Deploy snapshot"
- runs-on: ubuntu-18.04
- if: github.event_name == 'push'
- steps:
- # We clone the repo manually, since we are going to push back a reference to the snapshot
- - name: Clone the repo
- run: |
- branch="${GITHUB_REF//refs\/heads\//}"
- if [ "$branch" != "" ];
- then
- git clone --single-branch --branch "$branch" https://github.com/${GITHUB_REPOSITORY}.git .
- fi
- - name: Download merged natives
- uses: actions/download-artifact@master
- with:
- name: natives
- path: dist/
- - name: Deploy natives snapshot
- run: |
- source .github/actions/tools/minio.sh
- NATIVE_CHANGES="yes"
- branch="${GITHUB_REF//refs\/heads\//}"
- if [ "$branch" != "" ];
- then
- if [ -f "natives-snapshot.properties" ];
- then
- nativeSnapshot=`cat "natives-snapshot.properties"`
- nativeSnapshot="${nativeSnapshot#*=}"
- # We deploy ONLY if GITHUB_SHA (the current commit hash) is newer than $nativeSnapshot
- if [ "`git rev-list --count $nativeSnapshot..$GITHUB_SHA`" = "0" ];
- then
- NATIVE_CHANGES=""
- else
- # We check if the native code changed.
- echo "Detect changes"
- NATIVE_CHANGES="$(git diff-tree --name-only "$GITHUB_SHA" "$nativeSnapshot" -- jme3-android-native/)"
- fi
- fi
- # We do nothing if there is no change
- if [ "$NATIVE_CHANGES" = "" ];
- then
- echo "No changes, skip."
- else
- if [ "${{ secrets.OBJECTS_KEY }}" = "" ];
- then
- echo "Configure the OBJECTS_KEY secret to enable natives snapshot deployment to MinIO"
- else
- # Deploy natives snapshot to a MinIO instance using function in minio.sh
- minio_uploadFile dist/jme3-natives.zip \
- native-snapshots/$GITHUB_SHA/jme3-natives.zip \
- https://objects.jmonkeyengine.org \
- jmonkeyengine \
- ${{ secrets.OBJECTS_KEY }}
- # We reference the snapshot by writing its commit hash in natives-snapshot.properties
- echo "natives.snapshot=$GITHUB_SHA" > natives-snapshot.properties
- # We commit the updated natives-snapshot.properties
- git config --global user.name "Github Actions"
- git config --global user.email "[email protected]"
- git add natives-snapshot.properties
- git commit -m "[skip ci] update natives snapshot"
- # Pull rebase from the remote repo, just in case there was a push in the meantime
- git pull -q --rebase
- # We need to calculate the header for git authentication
- header=$(echo -n "ad-m:${{ secrets.GITHUB_TOKEN }}" | base64)
- # Push
- (git -c http.extraheader="AUTHORIZATION: basic $header" push origin "$branch" || true)
- fi
- fi
- fi
- # This job deploys the release
- DeployRelease:
- needs: [BuildJMonkey]
- name: Deploy Release
- runs-on: ubuntu-18.04
- if: github.event_name == 'release'
- steps:
- # We need to clone everything again for uploadToMaven.sh ...
- - name: Clone the repo
- uses: actions/checkout@v2
- with:
- fetch-depth: 1
- # Download all the stuff...
- - name: Download maven artifacts
- uses: actions/download-artifact@master
- with:
- name: maven
- path: dist/maven
- - name: Download release
- uses: actions/download-artifact@master
- with:
- name: release
- path: dist/release
- - name: Download natives for android
- uses: actions/download-artifact@master
- with:
- name: android-natives
- path: build/native
- - name: Rebuild the maven artifacts and deploy them to Sonatype OSSRH
- run: |
- if [ "${{ secrets.OSSRH_PASSWORD }}" = "" ];
- then
- echo "Configure the following secrets to enable deployment to Sonatype:"
- echo "OSSRH_PASSWORD, OSSRH_USERNAME, SIGNING_KEY, SIGNING_PASSWORD"
- else
- ./gradlew publishMavenPublicationToOSSRHRepository \
- -PossrhPassword=${{ secrets.OSSRH_PASSWORD }} \
- -PossrhUsername=${{ secrets.OSSRH_USERNAME }} \
- -PsigningKey='${{ secrets.SIGNING_KEY }}' \
- -PsigningPassword='${{ secrets.SIGNING_PASSWORD }}' \
- -PuseCommitHashAsVersionName=true \
- --console=plain --stacktrace
- fi
- - name: Deploy to GitHub Releases
- run: |
- # We need to get the release id (yeah, it's not the same as the tag)
- echo "${GITHUB_EVENT_PATH}"
- cat ${GITHUB_EVENT_PATH}
- releaseId=$(jq --raw-output '.release.id' ${GITHUB_EVENT_PATH})
- # Now that we have the id, we just upload the release zip from before
- echo "Upload to release $releaseId"
- filename="$(ls dist/release/*.zip)"
- url="https://uploads.github.com/repos/${GITHUB_REPOSITORY}/releases/$releaseId/assets?name=$(basename $filename)"
- echo "Upload to $url"
- curl -L \
- -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
- -H "Content-Type: application/zip" \
- --data-binary @"$filename" \
- "$url"
- - name: Deploy to github package registry
- run: |
- source .github/actions/tools/uploadToMaven.sh
- registry="https://maven.pkg.github.com/$GITHUB_REPOSITORY"
- echo "Deploy to github package registry $registry"
- uploadAllToMaven dist/maven/ $registry "token" ${{ secrets.GITHUB_TOKEN }}
- # Deploy the javadoc
- DeployJavaDoc:
- needs: [BuildJMonkey]
- name: Deploy Javadoc
- runs-on: ubuntu-18.04
- if: github.event_name == 'release'
- steps:
- # We are going to need a deploy key for this, since we need
- # to push to a different repo
- - name: Set ssh key
- run: |
- mkdir -p ~/.ssh/
- echo "${{ secrets.JAVADOC_GHPAGES_DEPLOY_PRIVKEY }}" > $HOME/.ssh/deploy.key
- chmod 600 $HOME/.ssh/deploy.key
- # We clone the javadoc repo
- - name: Clone gh-pages
- run: |
- branch="gh-pages"
- export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
- git clone --single-branch --branch "$branch" [email protected]:${{ secrets.JAVADOC_GHPAGES_REPO }} .
- # Download the javadoc in the new directory "newdoc"
- - name: Download javadoc
- uses: actions/download-artifact@master
- with:
- name: javadoc
- path: newdoc
- # The actual deploy
- - name: Deploy to github pages
- run: |
- set -f
- IFS=$'\n'
- # Get the tag for this release
- version="`if [[ $GITHUB_REF == refs\/tags* ]]; then echo ${GITHUB_REF//refs\/tags\//}; fi`"
- # If there is no tag, then we do nothing.
- if [ "$version" != "" ];
- then
- echo "Deploy as $version"
- # Remove any older version of the javadoc for this tag
- if [ -d "$version" ];then rm -Rf "$version"; fi
- # Rename newdoc with the version name
- mv newdoc "$version"
- # if there isn't an index.txt we create one (we need this to list the versions)
- if [ ! -f "index.txt" ]; then echo "" > index.txt ; fi
- index="`cat index.txt`"
- # Check if this version is already in index.txt
- addNew=true
- for v in $index;
- do
- if [ "$v" = "$version" ];
- then
- echo "$v" "$version"
- addNew=false
- break
- fi
- done
- # If not, we add it to the beginning
- if [ "$addNew" = "true" ];
- then
- echo -e "$version\n$index" > index.txt
- index="`cat index.txt`"
- fi
- # Regenerate the pages
- chmod +x make.sh
- ./make.sh
- # Configure git to use the deploy key
- export GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i $HOME/.ssh/deploy.key"
- # Commit the changes
- git config --global user.name "Github Actions"
- git config --global user.email "[email protected]"
- git add . || true
- git commit -m "$version" || true
- branch="gh-pages"
- git push origin "$branch" --force || true
- fi
|