Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to install custom Java version #28

Merged
merged 4 commits into from
Oct 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ jobs:
- uses: ./
- run: cd test-build && sbt run
shell: bash
custom-url:
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-amd64-20.2.0.tar.gz
- run: cd test-build && sbt run
shell: bash
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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-amd64-20.2.0.tar.gz`:
custom Java version from a URL

## Tips and tricks

Expand Down Expand Up @@ -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
Expand Down
62 changes: 43 additions & 19 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,35 +49,59 @@ function installJava(javaVersion: string, jabbaVersion: string) {
shell.set("-ev");
shell.exec(`curl -sL -o ${jabba} ${jabbaUrl}`, { silent: true });
shell.chmod(755, jabba);
// if a string using the 'version=url' format is provided, respect it (e.g. 1.14.0=tgz+https://link.to.tarball.tgz)
const javaVersionSearch = javaVersion.split('=')[0];
const useVersion = shell
.exec(`${jabba} ls-remote`)
.grep(javaVersionSearch)
.head({ "-n": 1 })
.stdout.trim();
var toInstall = useVersion;
if (!useVersion) {
core.setFailed(`Couldn't find Java ${javaVersionSearch}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.`);
return;
}
if (javaVersion !== javaVersionSearch) {
toInstall = javaVersion;
}
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 ${toInstall}, Jabba stderr: ${result.stderr}`);
core.setFailed(
`Failed to install Java ${javaVersion}, Jabba stderr: ${result.stderr}`
);
return;
}
const javaHome = shell
.exec(`${jabba} which --home ${useVersion}`)
.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);
Expand Down
Loading