Skip to content
This repository was archived by the owner on May 8, 2024. It is now read-only.

Commit 14a05db

Browse files
author
Sophia Guo
committed
initial commit
0 parents  commit 14a05db

19 files changed

+10360
-0
lines changed

Diff for: .gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
!/.idea
2+
/.idea/*
3+
!/.idea/copyright/
4+
!/.idea/scopes/
5+
/lib
6+
/node_modules
7+
/out

Diff for: .idea/copyright/MIT__Main_.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .idea/copyright/profiles_settings.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: .project

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>install-jdk</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
</buildSpec>
9+
<natures>
10+
</natures>
11+
</projectDescription>

Diff for: LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2018 GitHub, Inc. and contributors
4+
Copyright (c) 2019-2020 Leon Linhart
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in all
14+
copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
SOFTWARE.

Diff for: README.md

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# install-jdk
2+
3+
An action to download and install JDKs for use in workflows.
4+
5+
This action is based on the [actions/setup-java](https://github.com/actions/setup-java)
6+
action by GitHub which works perfectly fine for simple workflows but does not
7+
scale and lacks configurability.
8+
9+
JDKs are downloaded from [AdoptOpenJDK](https://adoptopenjdk.net/).
10+
11+
12+
## Usage
13+
14+
See [action.yml](action.yml)
15+
16+
#### Basic
17+
18+
```
19+
steps:
20+
- uses: actions/checkout@v1
21+
- uses: AdopOpenJDK/install-jdk@v1
22+
with:
23+
version: '13'
24+
architecture: x64
25+
```
26+
27+
#### Multiple JDKs
28+
29+
Some projects may require multiple JDK versions to build. `install-jdk` supports
30+
installing JDKs to one (or more) given `target` environment variables.
31+
32+
```
33+
- uses: actions/checkout@v1
34+
- uses: AdopOpenJDK/install-jdk@v1
35+
with:
36+
version: '8'
37+
architecture: x64
38+
- uses: AdopOpenJDK/install-jdk@v1
39+
with:
40+
version: '13'
41+
architecture: x64
42+
targets: 'JDK_13'
43+
```
44+
45+
46+
### Configuration:
47+
48+
| Parameter | Default |
49+
|--------------------|-------------|
50+
| `version` | |
51+
| `architecture` | `x64` |
52+
| `source` | |
53+
| `archiveExtension` | |
54+
| `targets` | `JAVA_HOME` |
55+
| `impl ` | `hotspot` |
56+
57+
#### `version`
58+
59+
The Java version to install a JDK for. (Supported values are: `1.8`, `8`, `9`,
60+
`10`, `11`, `12`, `13`, ...)
61+
62+
By default, this action will try to install the latest JDK release for the
63+
specified version from AdoptOpenJDK. Alternatively, a `source` can be specified
64+
explicitly.
65+
66+
The `version` key should be set accordingly for custom downloads since it is
67+
used to cache JDKs which are used multiple times during the workflow.
68+
69+
#### `architecture`
70+
71+
The target architecture of the JDK to install.
72+
73+
Defaults to `x64`.
74+
75+
#### `source`
76+
77+
A custom source location of a JDK. This might be either a local directory,
78+
a compressed file, or an url.
79+
80+
#### `archiveExtension`
81+
82+
The extension of the JDK archive. (Supported values are: `.zip`, `.tar`, `.7z`)
83+
84+
Specifying this property is required when a custom `source` is set.
85+
86+
#### `targets`
87+
88+
A semicolon-separated list of environment variables which will be set up to
89+
point to the installation directory of the JDK.
90+
91+
By default, this is set to `JAVA_HOME`. Keep in mind that this is overwritten
92+
when specifying targets explicitly. Thus, if you want to make a JDK available
93+
from - say - `JDK_X` and `JAVA_HOME`, you would need to specify:
94+
95+
targets: 'JDK_X;JAVA_HOME'
96+
97+
#### `impl`
98+
99+
JVM implementation. (Supported values is `hotspot`, `openj9`)
100+

Diff for: __tests__/installer.test.ts

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import io = require("@actions/io");
2+
import fs = require("fs");
3+
import path = require("path");
4+
import child_process = require("child_process");
5+
6+
const toolDir = path.join(__dirname, "runner", "tools");
7+
const tempDir = path.join(__dirname, "runner", "temp");
8+
const javaDir = path.join(__dirname, "runner", "java");
9+
10+
process.env["RUNNER_TOOL_CACHE"] = toolDir;
11+
process.env["RUNNER_TEMP"] = tempDir;
12+
import * as installer from "../src/installer";
13+
14+
let javaFilePath = "";
15+
let javaUrl = "";
16+
let javaArchiveExtension = "";
17+
18+
if (process.platform === "win32") {
19+
javaFilePath = path.join(javaDir, "java_win.zip");
20+
javaUrl = "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_windows-x64_bin.zip";
21+
javaArchiveExtension = ".zip"
22+
} else if (process.platform === "darwin") {
23+
javaFilePath = path.join(javaDir, "java_mac.tar.gz");
24+
javaUrl = "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz";
25+
javaArchiveExtension = ".tar"
26+
} else {
27+
javaFilePath = path.join(javaDir, "java_linux.tar.gz");
28+
javaUrl = "https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz";
29+
javaArchiveExtension = ".tar"
30+
}
31+
32+
describe("installer tests", () => {
33+
beforeAll(async () => {
34+
await io.rmRF(toolDir);
35+
await io.rmRF(tempDir);
36+
if (!fs.existsSync(`${javaFilePath}.complete`)) {
37+
// Download java
38+
await io.mkdirP(javaDir);
39+
40+
console.log("Downloading java");
41+
child_process.execSync(`curl "${javaUrl}" > "${javaFilePath}"`);
42+
// Write complete file so we know it was successful
43+
fs.writeFileSync(`${javaFilePath}.complete`, "content");
44+
}
45+
}, 300000);
46+
47+
afterAll(async () => {
48+
try {
49+
await io.rmRF(toolDir);
50+
await io.rmRF(tempDir);
51+
} catch {
52+
console.log("Failed to remove test directories");
53+
}
54+
}, 100000);
55+
56+
it("Installs version of Java from jdkFile if no matching version is installed", async () => {
57+
await installer.installJDK("12", "x64", javaFilePath, javaArchiveExtension, "JAVA_HOME");
58+
const JavaDir = path.join(toolDir, "jdk-12", "1.0.0", "x64");
59+
60+
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
61+
expect(fs.existsSync(path.join(JavaDir, "bin"))).toBe(true);
62+
}, 100000);
63+
64+
it("Throws if invalid directory to jdk", async () => {
65+
let thrown = false;
66+
try {
67+
await installer.installJDK("1000", "x64", "bad path", ".zip", "JAVA_HOME");
68+
} catch {
69+
thrown = true;
70+
}
71+
expect(thrown).toBe(true);
72+
});
73+
74+
it("Downloads java if no file given", async () => {
75+
await installer.installJDK("8", "x64", "", "", "JAVA_HOME");
76+
const JavaDir = path.join(toolDir, "jdk-8", "1.0.0", "x64");
77+
78+
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
79+
expect(fs.existsSync(path.join(JavaDir, "bin"))).toBe(true);
80+
}, 100000);
81+
82+
it("Downloads java with 1.x syntax", async () => {
83+
await installer.installJDK("1.8", "x64", "", javaArchiveExtension, "JAVA_HOME");
84+
const JavaDir = path.join(toolDir, "jdk-1.8", "1.0.0", "x64");
85+
86+
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
87+
expect(fs.existsSync(path.join(JavaDir, "bin"))).toBe(true);
88+
}, 100000);
89+
90+
/*
91+
it("Downloads java with normal semver syntax", async () => {
92+
await installer.installJDK("9.0.x", "x64", "", "", "");
93+
const JavaDir = path.join(toolDir, "jdk", "9.0.7", "x64");
94+
95+
expect(fs.existsSync(`${JavaDir}.complete`)).toBe(true);
96+
expect(fs.existsSync(path.join(JavaDir, "bin"))).toBe(true);
97+
}, 100000);
98+
*/
99+
100+
it("Throws if invalid directory to jdk", async () => {
101+
let thrown = false;
102+
try {
103+
await installer.installJDK("1000", "x64", "bad path", "", "JAVA_HOME");
104+
} catch {
105+
thrown = true;
106+
}
107+
expect(thrown).toBe(true);
108+
});
109+
110+
it("Uses version of Java installed in cache", async () => {
111+
const JavaDir: string = path.join(toolDir, "jdk", "250.0.0", "x64");
112+
await io.mkdirP(JavaDir);
113+
fs.writeFileSync(`${JavaDir}.complete`, "hello");
114+
// This will throw if it doesn""t find it in the cache (because no such version exists)
115+
await installer.installJDK(
116+
"250",
117+
"x64",
118+
"path shouldnt matter, found in cache",
119+
"",
120+
"JAVA_HOME"
121+
);
122+
return;
123+
});
124+
125+
it("Doesnt use version of Java that was only partially installed in cache", async () => {
126+
const JavaDir: string = path.join(toolDir, "jdk", "251.0.0", "x64");
127+
await io.mkdirP(JavaDir);
128+
let thrown = false;
129+
try {
130+
// This will throw if it doesn""t find it in the cache (because no such version exists)
131+
await installer.installJDK("251", "x64", "bad path", "", "JAVA_HOME");
132+
} catch {
133+
thrown = true;
134+
}
135+
expect(thrown).toBe(true);
136+
return;
137+
});
138+
});

Diff for: action.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'Install JDK'
2+
description: 'Set up a specific version of the Java JDK for use during an workflow.'
3+
inputs:
4+
version:
5+
description: 'The JDK version to setup.'
6+
required: true
7+
architecture:
8+
description: 'The architecture (x86, x64) of the JDK. (This not relevant when an explicit source is specified.)'
9+
required: false
10+
default: 'x64'
11+
source:
12+
description: 'A custom JDK location. May either be a local archive, folder, or URL.'
13+
required: false
14+
archiveExtension:
15+
description: 'The extension of the JDK archive. Must be one of: [.zip, .tar, .7z] (Required when source is an URL.)'
16+
required: false
17+
targets:
18+
description: 'A semicolon-separated list of environment variables that should point to the JDK. (Defaults to "JAVA_HOME".)'
19+
required: false
20+
default: 'JAVA_HOME'
21+
impl:
22+
description: 'JVM implementation'
23+
required: false
24+
default: 'hotspot'
25+
runs:
26+
using: 'node12'
27+
main: 'dist/index.js'
28+
branding:
29+
color: white
30+
icon: download

0 commit comments

Comments
 (0)