Skip to content

Commit

Permalink
Add support for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
olafurpg committed Sep 29, 2019
1 parent b81f72f commit 109d71e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macOS-latest]
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v1
- run: yarn install
- run: yarn run build
- uses: ./
- run: cd test-build && sbt run
- uses: actions/checkout@v1
- run: yarn install
- run: yarn run build
- uses: ./
- run: cd test-build && sbt run
shell: bash
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ inputs:
AdoptOpenJDK 8 version, "adopt@1.11" for the latest AdoptOpenJDK 11
version, or "graalvm@" for the latest GraalVM version.
default: "adopt@1.8"
jabba-version:
description: The Jabba version to install.
default: "0.11.2"
runs:
using: "node12"
main: "lib/main.js"
Expand Down
49 changes: 36 additions & 13 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,47 @@ import * as shell from "shelljs";
import * as path from "path";

const homedir = require("os").homedir();
const bin = path.join(homedir, "bin");

export async function install(javaVersion: string) {
installJava(javaVersion);
export async function install(javaVersion: string, jabbaVersion: string) {
installJava(javaVersion, jabbaVersion);
installSbt();
}

function installJava(javaVersion: string) {
function jabbaUrlSuffix(): string {
const runnerOs = shell.env["RUNNER_OS"] || "undefined";
switch (runnerOs.toLowerCase()) {
case "linux":
return "linux-amd64";
case "macos":
return "darwin-amd64";
case "windows":
return "windows-amd64.exe";
default:
throw new Error(
`unknown runner OS: ${runnerOs}, expected one of Linux, macOS or Windows.`
);
}
}

function isWindows(): boolean {
return shell.env["RUNNER_OS"] === "Windows";
}

function jabbaName(): string {
if (isWindows()) return "jabba.exe";
else return "jabba";
}

function installJava(javaVersion: string, jabbaVersion: string) {
core.startGroup("Install Java");
shell
.exec("curl -sL https://github.com/shyiko/jabba/raw/master/install.sh", {
silent: true
})
.exec("bash");
const jabbaBin = path.join(homedir, ".jabba", "bin");
core.addPath(jabbaBin);
const jabba = path.join(jabbaBin, "jabba");
core.addPath(bin);
const jabbaUrl = `https://github.com/shyiko/jabba/releases/download/${jabbaVersion}/jabba-${jabbaVersion}-${jabbaUrlSuffix()}`;
shell.mkdir(bin);
const jabba = path.join(bin, jabbaName());
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)
Expand All @@ -36,8 +61,6 @@ function installJava(javaVersion: string) {

function installSbt() {
core.startGroup("Install sbt");
const bin = path.join(homedir, "bin");
shell.mkdir(bin);
core.addPath(bin);
curl(
"https://raw.githubusercontent.com/paulp/sbt-extras/master/sbt",
Expand Down
7 changes: 4 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { install } from "./install";

async function run() {
try {
const version = core.getInput("java-version", { required: true });
console.log(`Installing Java version '${version}'`);
await install(version);
const javaVersion = core.getInput("java-version", { required: true });
const jabbaVersion = core.getInput("jabba-version", { required: true });
console.log(`Installing Java version '${javaVersion}'`);
await install(javaVersion, jabbaVersion);
} catch (error) {
core.setFailed(error.message);
}
Expand Down

0 comments on commit 109d71e

Please sign in to comment.