Skip to content

Commit edbd478

Browse files
authored
Add support to install custom Java version (#28)
1 parent a413c36 commit edbd478

File tree

4 files changed

+834
-795
lines changed

4 files changed

+834
-795
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,14 @@ jobs:
1515
- uses: ./
1616
- run: cd test-build && sbt run
1717
shell: bash
18+
custom-url:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v1
22+
- run: yarn install
23+
- run: yarn run build
24+
- uses: ./
25+
with:
26+
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
27+
- run: cd test-build && sbt run
28+
shell: bash

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Setup Scala GitHub Action
22

3-
A GitHub Action to install Java via [Jabba](https://github.com/shyiko/jabba)
4-
and sbt.
3+
A GitHub Action to install Java via [Jabba](https://github.com/shyiko/jabba) and
4+
sbt.
55

66
- Configurable Java version: supports OpenJDK, GraalVM, Zulu and any other Java
77
version that's installable via Jabba.
88
- The `sbt` command is installed using the
99
[paulp/sbt-extras](https://github.com/paulp/sbt-extras/) launcher.
1010
- For faster startup, the `csbt` command is installed using the Coursier-based
11-
[coursier/sbt-extras](https://github.com/coursier/sbt-extras/) launcher. This launcher
12-
does not work with all builds, only use `csbt` if you know what you are doing.
11+
[coursier/sbt-extras](https://github.com/coursier/sbt-extras/) launcher. This
12+
launcher does not work with all builds, only use `csbt` if you know what you
13+
are doing.
1314
- Cross-platform: works on Linux, macOS, Windows.
1415

1516
## Usage:
@@ -58,6 +59,8 @@ More Java version examples:
5859
- `graalvm@`: the latest GraalVM
5960
- `openjdk@1.14`: the latest OpenJDK 14 version
6061
- `zulu@1.11`: the latest Zulu OpenJDK 11
62+
- `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`:
63+
custom Java version from a URL
6164

6265
## Tips and tricks
6366

@@ -118,11 +121,12 @@ configure git to disable Windows line feeds.
118121

119122
### Faster checkout of big repos
120123

121-
Your repository can have a lot of commits, or branches with bulk resources.
122-
The v2 version of `actions/checkout` doesn't fetch a whole repo by default
123-
that can speed up builds greatly. But an additional configuration can be
124-
required to fetch tags up to some level of depth for some builds which check
125-
binary compatibility with previous tagged release from the branch.
124+
Your repository can have a lot of commits, or branches with bulk resources. The
125+
v2 version of `actions/checkout` doesn't fetch a whole repo by default that can
126+
speed up builds greatly. But an additional configuration can be required to
127+
fetch tags up to some level of depth for some builds which check binary
128+
compatibility with previous tagged release from the branch.
129+
126130
```diff
127131
+++ .github/workflows/ci.yml
128132
name: CI

src/install.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,35 +49,59 @@ function installJava(javaVersion: string, jabbaVersion: string) {
4949
shell.set("-ev");
5050
shell.exec(`curl -sL -o ${jabba} ${jabbaUrl}`, { silent: true });
5151
shell.chmod(755, jabba);
52-
// if a string using the 'version=url' format is provided, respect it (e.g. 1.14.0=tgz+https://link.to.tarball.tgz)
53-
const javaVersionSearch = javaVersion.split('=')[0];
54-
const useVersion = shell
55-
.exec(`${jabba} ls-remote`)
56-
.grep(javaVersionSearch)
57-
.head({ "-n": 1 })
58-
.stdout.trim();
59-
var toInstall = useVersion;
60-
if (!useVersion) {
61-
core.setFailed(`Couldn't find Java ${javaVersionSearch}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.`);
62-
return;
63-
}
64-
if (javaVersion !== javaVersionSearch) {
65-
toInstall = javaVersion;
66-
}
67-
console.log(`Installing ${toInstall}`);
68-
const result = shell.exec(`${jabba} install ${toInstall}`);
52+
const jabbaInstall = javaVersion.includes("=")
53+
? installJavaByExactVersion(javaVersion)
54+
: installJavaByFuzzyVersion(jabba, javaVersion);
55+
if (!jabbaInstall) return;
56+
console.log(`Installing ${jabbaInstall.name}`);
57+
const result = shell.exec(`${jabba} install ${jabbaInstall.install}`);
6958
if (result.code > 0) {
70-
core.setFailed(`Failed to install Java ${toInstall}, Jabba stderr: ${result.stderr}`);
59+
core.setFailed(
60+
`Failed to install Java ${javaVersion}, Jabba stderr: ${result.stderr}`
61+
);
7162
return;
7263
}
7364
const javaHome = shell
74-
.exec(`${jabba} which --home ${useVersion}`)
65+
.exec(`${jabba} which --home ${jabbaInstall.name}`)
7566
.stdout.trim();
7667
core.exportVariable("JAVA_HOME", javaHome);
7768
core.addPath(path.join(javaHome, "bin"));
7869
core.endGroup();
7970
}
8071

72+
interface JabbaInstall {
73+
name: string;
74+
install: string;
75+
}
76+
77+
function installJavaByFuzzyVersion(
78+
jabba: string,
79+
javaVersion: string
80+
): JabbaInstall | undefined {
81+
const toInstall = shell
82+
.exec(`${jabba} ls-remote`)
83+
.grep(javaVersion)
84+
.head({ "-n": 1 })
85+
.stdout.trim();
86+
if (!toInstall) {
87+
core.setFailed(
88+
`Couldn't find Java ${javaVersion}. To fix this problem, run 'jabba ls-remote' to see the list of valid Java versions.`
89+
);
90+
return;
91+
}
92+
return {
93+
name: toInstall,
94+
install: toInstall,
95+
};
96+
}
97+
98+
function installJavaByExactVersion(javaVersion: string): JabbaInstall {
99+
return {
100+
name: javaVersion.split("=")[0],
101+
install: javaVersion,
102+
};
103+
}
104+
81105
function installSbt() {
82106
core.startGroup("Install sbt");
83107
core.addPath(bin);

0 commit comments

Comments
 (0)