diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3a402c6e..dc47011e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,3 +15,14 @@ jobs: - uses: ./ - run: cd test-build && sbt run shell: bash + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - run: yarn install + - run: yarn run build + - uses: ./ + with: + java-version: graal-20.2.0=tgz+https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.2.0/graalvm-ce-java11-linux-aarch64-20.2.0.tar.gz + - run: cd test-build && sbt run + shell: bash diff --git a/README.md b/README.md index dcb87b2a..e394f8f5 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ # Setup Scala GitHub Action -A GitHub Action to install Java via [Jabba](https://github.com/shyiko/jabba) -and sbt. +A GitHub Action to install Java via [Jabba](https://github.com/shyiko/jabba) and +sbt. - Configurable Java version: supports OpenJDK, GraalVM, Zulu and any other Java version that's installable via Jabba. - The `sbt` command is installed using the [paulp/sbt-extras](https://github.com/paulp/sbt-extras/) launcher. - For faster startup, the `csbt` command is installed using the Coursier-based - [coursier/sbt-extras](https://github.com/coursier/sbt-extras/) launcher. This launcher - does not work with all builds, only use `csbt` if you know what you are doing. + [coursier/sbt-extras](https://github.com/coursier/sbt-extras/) launcher. This + launcher does not work with all builds, only use `csbt` if you know what you + are doing. - Cross-platform: works on Linux, macOS, Windows. ## Usage: @@ -58,6 +59,8 @@ More Java version examples: - `graalvm@`: the latest GraalVM - `openjdk@1.14`: the latest OpenJDK 14 version - `zulu@1.11`: the latest Zulu OpenJDK 11 +- `graalvm@20.2.0=tgz+https://github.com/graalvm/graalvm-ce-builds/releases/download/vm-20.2.0/graalvm-ce-java11-linux-aarch64-20.2.0.tar.gz`: + custom Java version from a URL ## Tips and tricks @@ -118,11 +121,12 @@ configure git to disable Windows line feeds. ### Faster checkout of big repos -Your repository can have a lot of commits, or branches with bulk resources. -The v2 version of `actions/checkout` doesn't fetch a whole repo by default -that can speed up builds greatly. But an additional configuration can be -required to fetch tags up to some level of depth for some builds which check -binary compatibility with previous tagged release from the branch. +Your repository can have a lot of commits, or branches with bulk resources. The +v2 version of `actions/checkout` doesn't fetch a whole repo by default that can +speed up builds greatly. But an additional configuration can be required to +fetch tags up to some level of depth for some builds which check binary +compatibility with previous tagged release from the branch. + ```diff +++ .github/workflows/ci.yml name: CI diff --git a/src/install.ts b/src/install.ts index c783274a..236196b8 100644 --- a/src/install.ts +++ b/src/install.ts @@ -49,29 +49,59 @@ function installJava(javaVersion: string, jabbaVersion: string) { shell.set("-ev"); shell.exec(`curl -sL -o ${jabba} ${jabbaUrl}`, { silent: true }); shell.chmod(755, jabba); - const toInstall = shell - .exec(`${jabba} ls-remote`) - .grep(javaVersion) - .head({ "-n": 1 }) - .stdout.trim(); - if (!toInstall) { - core.setFailed(`Couldn't find Java ${javaVersion}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.`); - return; - } - console.log(`Installing ${toInstall}`); - const result = shell.exec(`${jabba} install ${toInstall}`); + const jabbaInstall = javaVersion.includes("=") + ? installJavaByExactVersion(javaVersion) + : installJavaByFuzzyVersion(jabba, javaVersion); + if (!jabbaInstall) return; + console.log(`Installing ${jabbaInstall.name}`); + const result = shell.exec(`${jabba} install ${jabbaInstall.install}`); if (result.code > 0) { - core.setFailed(`Failed to install Java ${javaVersion}, Jabba stderr: ${result.stderr}`); + core.setFailed( + `Failed to install Java ${javaVersion}, Jabba stderr: ${result.stderr}` + ); return; } const javaHome = shell - .exec(`${jabba} which --home ${toInstall}`) + .exec(`${jabba} which --home ${jabbaInstall.name}`) .stdout.trim(); core.exportVariable("JAVA_HOME", javaHome); core.addPath(path.join(javaHome, "bin")); core.endGroup(); } +interface JabbaInstall { + name: string; + install: string; +} + +function installJavaByFuzzyVersion( + jabba: string, + javaVersion: string +): JabbaInstall | undefined { + const toInstall = shell + .exec(`${jabba} ls-remote`) + .grep(javaVersion) + .head({ "-n": 1 }) + .stdout.trim(); + if (!toInstall) { + core.setFailed( + `Couldn't find Java ${javaVersion}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.` + ); + return; + } + return { + name: toInstall, + install: toInstall, + }; +} + +function installJavaByExactVersion(javaVersion: string): JabbaInstall { + return { + name: javaVersion.split("=")[0], + install: javaVersion, + }; +} + function installSbt() { core.startGroup("Install sbt"); core.addPath(bin);