diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..599a9a69 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,176 @@ +name: deploy + +# on: +# push: +# tags: +# - "*.*.*" + +on: [push + # , pull_request + ] + +jobs: + uberjar: + runs-on: ubuntu-18.04 + steps: + - name: Git checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + submodules: 'true' + + - name: Parse Ref + id: parse-ref + run: | + export VERSION="$(echo $GITHUB_SHA | head -c 7)" + echo "##[set-output name=version;]${VERSION}" + echo "##[set-output name=name;]babashka-${VERSION}" + + - name: Cache deps + uses: actions/cache@v1 + id: cache-deps + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('project.clj') }} # Other deps files? + restore-keys: | + ${{ runner.os }}-maven- + + - name: Fetch deps + if: steps.cache-deps.outputs.cache-hit != 'true' + run: | + lein deps + + - name: Build into uberjar + run: | + echo ${{ steps.parse-ref.outputs.version }} > resources/BABASHKA_VERSION + lein uberjar + + - uses: actions/upload-artifact@v1 + with: + path: target/${{ steps.parse-ref.outputs.name }}-standalone.jar + name: jar + + - name: reflection.json + run: | + lein with-profiles +reflection run + + - uses: actions/upload-artifact@v1 + with: + name: reflection.json + path: reflection.json + + # Initial task to compile a JAR, store as a pipeline artifact to be used by + # downstream builders. + native-image-linux: + needs: [uberjar] + runs-on: ubuntu-18.04 + steps: + - name: Git checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + submodules: 'true' + + - uses: actions/download-artifact@v1 + with: + name: jar + path: . + + - uses: actions/download-artifact@v1 + with: + name: reflection.json + path: . + + - name: Parse Ref + id: parse-ref + run: | + export VERSION="$(echo $GITHUB_SHA | head -c 7)" + export BASE=babashka-${VERSION} + echo "##[set-output name=base;]${BASE}" + echo "##[set-output name=name;]${BASE}-linux" + + # Look up at releases here https://github.com/graalvm/graalvm-ce-builds/releases + - name: Prepare GraalVM + uses: DeLaGuardo/setup-graalvm@2.0 + with: + graalvm-version: "20.0.0.java8" + # Newer versions don't work yet + # graalvm-version: "19.3.1.java8" + # graalvm-version: "20.0.0.java8" + + - name: Build Linux native image + run: | + echo "native image at $(which gu)" + export GRAALVM_DEBUG=1 # Seems to work (not ideal, can give runtime errors) + export JAR=${{ steps.parse-ref.outputs.base }}-standalone.jar + export BINARY_NAME=${{ steps.parse-ref.outputs.name }} + script/compile + + - name: Test binary + run: | + export BINARY=./${{ steps.parse-ref.outputs.name }} + $BINARY -e '(println "OK")' + + - run: tar -cvzf ${{ steps.parse-ref.outputs.name }}.tgz ./${{ steps.parse-ref.outputs.name }} + + - uses: actions/upload-artifact@v1 + with: + path: ${{ steps.parse-ref.outputs.name }}.tgz + name: binary-linux + + + # Use GraalVM on macOS to convert JAR to a native macOS binary + native-image-mac: + needs: [uberjar, native-image-linux] # Make it wait for a succesful Linux build as that one runs faster (because of a queue somewhere?). Is also more expensive. + runs-on: macOS-latest + steps: + - name: Git checkout + uses: actions/checkout@v1 + with: + fetch-depth: 1 + submodules: 'true' + + - uses: actions/download-artifact@v1 + with: + name: jar + path: . + + - uses: actions/download-artifact@v1 + with: + name: reflection.json + path: . + + - name: Parse Ref + id: parse-ref + run: | + export VERSION="$(echo $GITHUB_SHA | head -c 7)" + export BASE=babashka-${VERSION} + echo "##[set-output name=base;]${BASE}" + echo "##[set-output name=name;]${BASE}-mac" + + # Look up at releases here https://github.com/graalvm/graalvm-ce-builds/releases + - name: Prepare GraalVM + uses: DeLaGuardo/setup-graalvm@2.0 + with: + graalvm-version: "20.0.0.java8" + # graalvm-version: "19.3.1.java8" + + - name: Build Mac native image + run: | + echo "native image at $(which gu)" + export GRAALVM_DEBUG=1 # Seems to work (not ideal, can give runtime errors) + export JAR=${{ steps.parse-ref.outputs.base }}-standalone.jar + export BINARY_NAME=${{ steps.parse-ref.outputs.name }} + script/compile + + - name: Test binary + run: | + export BINARY=./${{ steps.parse-ref.outputs.name }} + $BINARY -e '(println "OK")' + + - run: tar -cvzf ${{ steps.parse-ref.outputs.name }}.tgz ./${{ steps.parse-ref.outputs.name }} + + - uses: actions/upload-artifact@v1 + with: + path: ${{ steps.parse-ref.outputs.name }}.tgz + name: binary-mac diff --git a/script/compile b/script/compile index fb040df0..4a1707f7 100755 --- a/script/compile +++ b/script/compile @@ -2,16 +2,40 @@ set -eo pipefail -if [ -z "$GRAALVM_HOME" ]; then - echo "Please set GRAALVM_HOME" - exit 1 +GU=`which gu` || true + +if [ -z "$GU" ]; then + if [ -z "$GRAALVM_HOME" ]; then + echo "Please set GRAALVM_HOME" + exit 1 + fi + + GU="$GRAALVM_HOME/bin/gu" +else + GRAALVM_HOME=`echo $GU | sed -e "s/\/bin\/gu$//"` fi if [ -z "$BABASHKA_XMX" ]; then export BABASHKA_XMX="-J-Xmx3g" fi -"$GRAALVM_HOME/bin/gu" install native-image || true +NATIVE_IMAGE=`which native-image` || true + +if [ -z "$NATIVE_IMAGE" ]; then + $GU install native-image || true + + NATIVE_IMAGE=`which native-image` || true + + if [ -z "$NATIVE_IMAGE" ]; then + if [ -z "$GRAALVM_HOME" ]; then + echo "Please set GRAALVM_HOME" + exit 1 + fi + NATIVE_IMAGE="$GRAALVM_HOME/bin/native-image" + fi +fi + +## --- THE ACTUAL SCRIPT --- BABASHKA_VERSION=$(cat resources/BABASHKA_VERSION) @@ -19,11 +43,16 @@ export JAVA_HOME=$GRAALVM_HOME $GRAALVM_HOME/bin/javac -cp $GRAALVM_HOME/jre/lib/svm/builder/svm.jar resources/CutOffCoreServicesDependencies.java -lein with-profiles +reflection do run -lein do clean, uberjar +if [ -z "$JAR" ]; then + lein with-profiles +reflection do run + lein do clean, uberjar + JAR=${JAR:-"target/babashka-$BABASHKA_VERSION-standalone.jar"} +fi -args=( -jar target/babashka-$BABASHKA_VERSION-standalone.jar \ - -H:Name=bb \ +BINARY_NAME=${BINARY_NAME:-"bb"} + +args=( -jar $JAR \ + -H:Name=$BINARY_NAME \ -H:+ReportExceptionStackTraces \ -J-Dclojure.spec.skip-macros=true \ -J-Dclojure.compiler.direct-linking=true \ @@ -48,4 +77,10 @@ fi $GRAALVM_HOME/bin/native-image "${args[@]}" -lein clean +LEIN=`which lein` || true + +if [ -z "$LEIN" ]; then + echo "nothing to clean" +else + lein clean +fi \ No newline at end of file