diff --git a/.github/workflows/test-nightly.yml b/.github/workflows/test-nightly.yml new file mode 100644 index 00000000..63aa2f0d --- /dev/null +++ b/.github/workflows/test-nightly.yml @@ -0,0 +1,37 @@ +name: 'nightly' +on: + schedule: + - cron: '0 0 * * *' +jobs: + run: + name: Run + runs-on: ${{ matrix.operating-system }} + strategy: + matrix: + operating-system: [ubuntu-latest, macOS-latest, windows-latest] + jdk-version: [8, 11, 14] + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Set Node.js 12.x + uses: actions/setup-node@v1 + with: + node-version: 12.x + - name: npm install + run: npm install + - name: Clear tool cache + if: runner.os != 'windows' + run: mv "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old" + - name: Clear tool cache (Windows) + if: runner.os == 'windows' + run: move "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old" + - name: Setup Java ${{ matrix.java-version}} + uses: ./ + with: + java-version: ${{ matrix.jdk-version }} + - name: Verify Java ${{ matrix.java-version}} + if: runner.os != 'windows' + run: __tests__/verify-java.sh ${{ matrix.java-version }} + - name: Verify Java ${{ matrix.java-version}} (Windows) + if: runner.os == 'windows' + run: __tests__/verify-java.ps1 ${{ matrix.java-version }} diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index dda73067..d781f665 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.operating-system }} strategy: matrix: - operating-system: [ubuntu-latest, windows-latest] + operating-system: [ubuntu-latest, macOS-latest, windows-latest] steps: - name: Checkout uses: actions/checkout@v2 @@ -24,7 +24,8 @@ jobs: runs-on: ${{ matrix.operating-system }} strategy: matrix: - operating-system: [ubuntu-latest, windows-latest] + operating-system: [ubuntu-latest, macOS-latest, windows-latest] + java-version: [8, 11, 14] steps: - name: Checkout uses: actions/checkout@v2 @@ -34,16 +35,16 @@ jobs: - name: Clear tool cache (Windows) if: runner.os == 'windows' run: move "${{ runner.tool_cache }}" "${{ runner.tool_cache }}.old" - - name: Setup Java 13 + - name: Setup Java ${{ matrix.java-version}} uses: ./ with: - java-version: 13.0.2 - - name: Verify Java 13 + java-version: ${{ matrix.java-version }} + - name: Verify Java ${{ matrix.java-version}} if: runner.os != 'windows' - run: __tests__/verify-java.sh 13.0.2 - - name: Verify Java 13 (Windows) + run: __tests__/verify-java.sh ${{ matrix.java-version }} + - name: Verify Java ${{ matrix.java-version}} (Windows) if: runner.os == 'windows' - run: __tests__/verify-java.ps1 13.0.2 + run: __tests__/verify-java.ps1 ${{ matrix.java-version }} test-proxy: runs-on: ubuntu-latest @@ -61,25 +62,25 @@ jobs: - uses: actions/checkout@v2 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup Java 13 + - name: Setup Java 11 uses: ./ with: - java-version: 13.0.2 - - name: Verify Java 13 - run: __tests__/verify-java.sh 13.0.2 + java-version: 11 + - name: Verify Java 11 + run: __tests__/verify-java.sh 11 test-bypass-proxy: runs-on: ubuntu-latest env: https_proxy: http://no-such-proxy:3128 - no_proxy: github.com,static.azul.com + no_proxy: github.com,static.azul.com,api.adoptopenjdk.net,github-production-release-asset-2e65be.s3.amazonaws.com steps: - uses: actions/checkout@v2 - name: Clear tool cache run: rm -rf $RUNNER_TOOL_CACHE/* - - name: Setup Java 13 + - name: Setup Java 11 uses: ./ with: - java-version: 13.0.2 - - name: Verify Java 13 - run: __tests__/verify-java.sh 13.0.2 + java-version: 11 + - name: Verify Java 11 + run: __tests__/verify-java.sh 11 diff --git a/LICENSE b/LICENSE index a426ef25..5a17942c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,7 +1,7 @@ The MIT License (MIT) -Copyright (c) 2018 GitHub, Inc. and contributors +Copyright (c) 2018 GitHub, Inc. and contributors, Jochen Schalanda Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/README.md b/README.md index c7f492b3..2ab38edc 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ -# setup-java +# setup-jdk
-This action sets up a java environment for use in actions by: +This action sets up a Java development environment with the OpenJDK distribution from [AdoptOpenJDK](https://adoptopenjdk.net/) for use in actions by: -- optionally downloading and caching a requested version of java by version and adding to PATH. Default downloads are populated from the [Zulu Community distribution of OpenJDK](http://static.azul.com/zulu/bin/) -- registering problem matchers for error output +- Downloading and caching a version of the OpenJDK by version and adding to `PATH`. Downloads from [AdoptOpenJDK](https://adoptopenjdk.net/). +- Registering problem matchers for error output. + +The action is based on [actions/setup-java](https://github.com/actions/setup-java) and is using the [AdoptOpenJDK API](https://api.adoptopenjdk.net/) for fetching the JDK binaries. # Usage @@ -17,47 +19,18 @@ See [action.yml](action.yml) ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-java@v1 +- uses: joschi/setup-jdk@v2 with: - java-version: '9.0.4' # The JDK version to make available on the path. - java-package: jdk # (jre, jdk, or jdk+fx) - defaults to jdk - architecture: x64 # (x64 or x86) - defaults to x64 + java-version: '11' # The OpenJDK version to make available on the path + architecture: 'x64' # defaults to 'x64' - run: java -cp java HelloWorldApp ``` -Examples of version specifications that the java-version parameter will accept: - -- A major Java version - - e.g. ```6, 7, 8, 9, 10, 11, 12, 13, ...``` - -- A semver Java version specification - - e.g. ```8.0.232, 7.0.181, 11.0.4``` - - e.g. ```8.0.x, >11.0.3, >=13.0.1, <8.0.212``` - -- An early access (EA) Java version - - e.g. ```14-ea, 15-ea``` - - e.g. ```14.0.0-ea, 15.0.0-ea``` - - e.g. ```14.0.0-ea.28, 15.0.0-ea.2``` (syntax for specifying an EA build number) - - Note that, per semver rules, EA builds will be matched by explicit EA version specifications. - -- 1.x syntax - - e.g. ```1.8``` (same as ```8```) - - e.g. ```1.8.0.212``` (same as ```8.0.212```) - ## Local file ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-java@v1 +- uses: joschi/setup-jdk@v2 with: java-version: '4.0.0' architecture: x64 @@ -69,18 +42,18 @@ steps: ```yaml jobs: build: - runs-on: ubuntu-16.04 + runs-on: ubuntu-latest strategy: matrix: - # test against latest update of each major Java version, as well as specific updates of LTS versions: - java: [ 1.6, 6.0.83, 7, 7.0.181, 8, 8.0.192, 9.0.x, 10, 11.0.x, 11.0.3, 12, 13 ] + java: [ '8', '11', '13' ] name: Java ${{ matrix.java }} sample steps: - uses: actions/checkout@v2 - name: Setup java - uses: actions/setup-java@v1 + uses: joschi/setup-jdk@v2 with: java-version: ${{ matrix.java }} + architecture: x64 - run: java -cp java HelloWorldApp ``` @@ -94,9 +67,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + uses: joschi/setup-jdk@v2 with: - java-version: 1.8 + java-version: '8' - name: Build with Maven run: mvn -B package --file pom.xml @@ -107,9 +80,9 @@ jobs: GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN is the default env for the password - name: Set up Apache Maven Central - uses: actions/setup-java@v1 - with: # running setup-java again overwrites the settings.xml - java-version: 1.8 + uses: joschi/setup-jdk@v2 + with: # running setup-jdk again overwrites the settings.xml + java-version: '8' server-id: maven # Value of the distributionManagement/repository/id field of the pom.xml server-username: MAVEN_USERNAME # env variable for username in deploy server-password: MAVEN_CENTRAL_TOKEN # env variable for token in deploy @@ -160,7 +133,7 @@ jobs: - uses: actions/checkout@v2 - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + uses: joschi/setup-jdk@v2 - name: Build with Gradle run: gradle build @@ -189,9 +162,9 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up JDK 1.8 for Shared Runner - uses: actions/setup-java@v1 + uses: joschi/setup-jdk@v2 with: - java-version: 1.8 + java-version: '8' server-id: github # Value of the distributionManagement/repository/id field of the pom.xml settings-path: ${{ github.workspace }} # location for the settings.xml file diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index ff2d61b5..a764dbe5 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -3,6 +3,7 @@ import fs = require('fs'); import path = require('path'); import child_process = require('child_process'); +const toolName = 'AdoptOpenJDK'; const toolDir = path.join(__dirname, 'runner', 'tools'); const tempDir = path.join(__dirname, 'runner', 'temp'); const javaDir = path.join(__dirname, 'runner', 'java'); @@ -13,20 +14,26 @@ import * as installer from '../src/installer'; let javaFilePath = ''; let javaUrl = ''; +let os = ''; if (process.platform === 'win32') { javaFilePath = path.join(javaDir, 'java_win.zip'); javaUrl = 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_windows-x64_bin.zip'; + os = 'windows'; } else if (process.platform === 'darwin') { javaFilePath = path.join(javaDir, 'java_mac.tar.gz'); javaUrl = 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_osx-x64_bin.tar.gz'; + os = 'mac'; } else { javaFilePath = path.join(javaDir, 'java_linux.tar.gz'); javaUrl = 'https://download.java.net/java/GA/jdk12/33/GPL/openjdk-12_linux-x64_bin.tar.gz'; + os = 'linux'; } +jest.setTimeout(10000); + describe('installer tests', () => { beforeAll(async () => { await io.rmRF(toolDir); @@ -143,6 +150,166 @@ describe('installer tests', () => { return; }); + it('Throws if invalid release_type', async () => { + let thrown = false; + try { + await installer.getAdoptOpenJDK( + 'invalid-release-type', + '11', + 'jdk', + 'hotspot', + 'x64', + 'normal', + 'latest', + '' + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Throws if invalid version', async () => { + let thrown = false; + try { + await installer.getAdoptOpenJDK( + 'ga', + 'invalid-version', + 'jdk', + 'hotspot', + 'x64', + 'normal', + 'latest', + '' + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Throws if invalid image_type', async () => { + let thrown = false; + try { + await installer.getAdoptOpenJDK( + 'ga', + '11', + 'invalid-image_type', + 'hotspot', + 'x64', + 'normal', + 'latest', + '' + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Throws if invalid openjdk_impl', async () => { + let thrown = false; + try { + await installer.getAdoptOpenJDK( + 'ga', + '11', + 'jdk', + 'invalid-openjdk_impl', + 'x64', + 'normal', + 'latest', + '' + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Throws if invalid arch', async () => { + let thrown = false; + try { + await installer.getAdoptOpenJDK( + 'ga', + '11', + 'jdk', + 'hotspot', + 'invalid-arch', + 'normal', + 'latest', + '' + ); + } catch { + thrown = true; + } + expect(thrown).toBe(true); + }); + + it('Downloads JDK with normal syntax', async () => { + await installer.getAdoptOpenJDK( + 'ga', + '11', + 'jdk', + 'hotspot', + 'x64', + 'normal', + 'jdk-11.0.4+11', + '' + ); + const JavaDir = path.join( + toolDir, + toolName, + `1.0.0-ga-11-jdk-hotspot-${os}-x64-normal-jdk-11.0.4`, + 'x64' + ); + + expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); + }, 100000); + + it('Downloads JRE with normal syntax', async () => { + await installer.getAdoptOpenJDK( + 'ga', + '11', + 'jre', + 'hotspot', + 'x64', + 'normal', + 'jdk-11.0.4+11', + '' + ); + const JavaDir = path.join( + toolDir, + toolName, + `1.0.0-ga-11-jdk-hotspot-${os}-x64-normal-jdk-11.0.4`, + 'x64' + ); + + expect(fs.existsSync(path.join(JavaDir, 'bin'))).toBe(true); + }, 100000); + + it('Uses version of JDK installed in cache', async () => { + const JavaDir: string = path.join( + toolDir, + toolName, + `1.0.0-ga-my-custom-version-jdk-hotspot-${os}-x64-normal-123.4.5`, + 'x64' + ); + await io.mkdirP(JavaDir); + fs.writeFileSync(`${JavaDir}.complete`, 'hello'); + // This will throw if it doesn't find it in the cache (because no such version exists) + await installer.getAdoptOpenJDK( + 'ga', + 'my-custom-version', + 'jdk', + 'hotspot', + 'x64', + 'normal', + '123.4.5', + '' + ); + return; + }); + it('Doesnt use version of Java that was only partially installed in cache', async () => { const JavaDir: string = path.join(toolDir, 'jdk', '251.0.0', 'x64'); await io.mkdirP(JavaDir); diff --git a/__tests__/verify-java.ps1 b/__tests__/verify-java.ps1 index 9f675c89..8bab3178 100644 --- a/__tests__/verify-java.ps1 +++ b/__tests__/verify-java.ps1 @@ -5,7 +5,7 @@ if (!$args.Count -or !$args[0]) $java_version = & cmd.exe /c "java -version 2>&1" | Out-String Write-Host "Found java version: $java_version" -if (!$java_version.Contains($args[0])) +if (!$java_version -contains $args[0]) { throw "Unexpected version" } diff --git a/action.yml b/action.yml index de7711fa..f89f7239 100644 --- a/action.yml +++ b/action.yml @@ -1,22 +1,40 @@ -name: 'Setup Java JDK' -description: 'Set up a specific version of the Java JDK and add the +name: 'Setup AdoptOpenJDK' +description: 'Set up a specific version of the Java JDK from AdoptOpenJDK and add the command-line tools to the PATH' -author: 'GitHub' +author: 'Jochen Schalanda' inputs: + release_type: + description: 'Type of release. Either a release version, known as + General Availability ("ga") or an Early Access ("ea"). Default: "ga"' + required: false + default: 'ga' java-version: - description: 'The Java version to make available on the path. Takes a whole - or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). - Early access versions can be specified in the form of e.g. 14-ea, - 14.0.0-ea, or 14.0.0-ea.28' + description: 'OpenJDK feature release version you wish to download. + Feature versions are whole numbers, example 8, 9, 10, 11, 12, 13, 14' required: true java-package: - description: 'The package type (jre, jdk, jdk+fx)' + description: 'The package type (jre, jdk). Default: "jdk"' required: false default: 'jdk' + openjdk_impl: + description: 'JVM implementation, example: "hotspot", "openj9". Default: "hotspot"' + required: false + default: 'hotspot' architecture: - description: 'The architecture (x86, x64) of the package.' + description: 'Architecture of the JDK, example: "x64", "x32", "ppc64", "s390x", + "ppc64le", "aarch64". Default: "x64"' required: false default: 'x64' + heap_size: + description: 'Heap size for OpenJ9, example: "normal", "large" (for heaps >=57 GiB). + Default: "normal"' + required: false + default: 'normal' + release: + description: 'Exact release of OpenJDK, example: "latest", "jdk-11.0.4+11.4", + "jdk8u172-b00-201807161800". Default: "latest"' + required: false + default: 'latest' jdkFile: description: 'Path to where the compressed JDK is located. The path could be in your source repository or a local path on the agent.' @@ -39,3 +57,6 @@ inputs: runs: using: 'node12' main: 'dist/index.js' +branding: + icon: 'download' + color: 'blue' diff --git a/dist/index.js b/dist/index.js index 96632653..de852768 100644 --- a/dist/index.js +++ b/dist/index.js @@ -34,7 +34,7 @@ module.exports = /******/ // the startup function /******/ function startup() { /******/ // Load entry module and return exports -/******/ return __webpack_require__(811); +/******/ return __webpack_require__(540); /******/ }; /******/ /******/ // run startup @@ -3770,6 +3770,7 @@ var HttpCodes; HttpCodes[HttpCodes["RequestTimeout"] = 408] = "RequestTimeout"; HttpCodes[HttpCodes["Conflict"] = 409] = "Conflict"; HttpCodes[HttpCodes["Gone"] = 410] = "Gone"; + HttpCodes[HttpCodes["TooManyRequests"] = 429] = "TooManyRequests"; HttpCodes[HttpCodes["InternalServerError"] = 500] = "InternalServerError"; HttpCodes[HttpCodes["NotImplemented"] = 501] = "NotImplemented"; HttpCodes[HttpCodes["BadGateway"] = 502] = "BadGateway"; @@ -3794,8 +3795,18 @@ function getProxyUrl(serverUrl) { return proxyUrl ? proxyUrl.href : ''; } exports.getProxyUrl = getProxyUrl; -const HttpRedirectCodes = [HttpCodes.MovedPermanently, HttpCodes.ResourceMoved, HttpCodes.SeeOther, HttpCodes.TemporaryRedirect, HttpCodes.PermanentRedirect]; -const HttpResponseRetryCodes = [HttpCodes.BadGateway, HttpCodes.ServiceUnavailable, HttpCodes.GatewayTimeout]; +const HttpRedirectCodes = [ + HttpCodes.MovedPermanently, + HttpCodes.ResourceMoved, + HttpCodes.SeeOther, + HttpCodes.TemporaryRedirect, + HttpCodes.PermanentRedirect +]; +const HttpResponseRetryCodes = [ + HttpCodes.BadGateway, + HttpCodes.ServiceUnavailable, + HttpCodes.GatewayTimeout +]; const RetryableHttpVerbs = ['OPTIONS', 'GET', 'DELETE', 'HEAD']; const ExponentialBackoffCeiling = 10; const ExponentialBackoffTimeSlice = 5; @@ -3920,18 +3931,22 @@ class HttpClient { */ async request(verb, requestUrl, data, headers) { if (this._disposed) { - throw new Error("Client has already been disposed."); + throw new Error('Client has already been disposed.'); } let parsedUrl = url.parse(requestUrl); let info = this._prepareRequest(verb, parsedUrl, headers); // Only perform retries on reads since writes may not be idempotent. - let maxTries = (this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1) ? this._maxRetries + 1 : 1; + let maxTries = this._allowRetries && RetryableHttpVerbs.indexOf(verb) != -1 + ? this._maxRetries + 1 + : 1; let numTries = 0; let response; while (numTries < maxTries) { response = await this.requestRaw(info, data); // Check if it's an authentication challenge - if (response && response.message && response.message.statusCode === HttpCodes.Unauthorized) { + if (response && + response.message && + response.message.statusCode === HttpCodes.Unauthorized) { let authenticationHandler; for (let i = 0; i < this.handlers.length; i++) { if (this.handlers[i].canHandleAuthentication(response)) { @@ -3949,21 +3964,32 @@ class HttpClient { } } let redirectsRemaining = this._maxRedirects; - while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 - && this._allowRedirects - && redirectsRemaining > 0) { - const redirectUrl = response.message.headers["location"]; + while (HttpRedirectCodes.indexOf(response.message.statusCode) != -1 && + this._allowRedirects && + redirectsRemaining > 0) { + const redirectUrl = response.message.headers['location']; if (!redirectUrl) { // if there's no location to redirect to, we won't break; } let parsedRedirectUrl = url.parse(redirectUrl); - if (parsedUrl.protocol == 'https:' && parsedUrl.protocol != parsedRedirectUrl.protocol && !this._allowRedirectDowngrade) { - throw new Error("Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true."); + if (parsedUrl.protocol == 'https:' && + parsedUrl.protocol != parsedRedirectUrl.protocol && + !this._allowRedirectDowngrade) { + throw new Error('Redirect from HTTPS to HTTP protocol. This downgrade is not allowed for security reasons. If you want to allow this behavior, set the allowRedirectDowngrade option to true.'); } // we need to finish reading the response before reassigning response // which will leak the open socket. await response.readBody(); + // strip authorization header if redirected to a different hostname + if (parsedRedirectUrl.hostname !== parsedUrl.hostname) { + for (let header in headers) { + // header names are case insensitive + if (header.toLowerCase() === 'authorization') { + delete headers[header]; + } + } + } // let's make the request with the new redirectUrl info = this._prepareRequest(verb, parsedRedirectUrl, headers); response = await this.requestRaw(info, data); @@ -4014,8 +4040,8 @@ class HttpClient { */ requestRawWithCallback(info, data, onResult) { let socket; - if (typeof (data) === 'string') { - info.options.headers["Content-Length"] = Buffer.byteLength(data, 'utf8'); + if (typeof data === 'string') { + info.options.headers['Content-Length'] = Buffer.byteLength(data, 'utf8'); } let callbackCalled = false; let handleResult = (err, res) => { @@ -4028,7 +4054,7 @@ class HttpClient { let res = new HttpClientResponse(msg); handleResult(null, res); }); - req.on('socket', (sock) => { + req.on('socket', sock => { socket = sock; }); // If we ever get disconnected, we want the socket to timeout eventually @@ -4043,10 +4069,10 @@ class HttpClient { // res should have headers handleResult(err, null); }); - if (data && typeof (data) === 'string') { + if (data && typeof data === 'string') { req.write(data, 'utf8'); } - if (data && typeof (data) !== 'string') { + if (data && typeof data !== 'string') { data.on('close', function () { req.end(); }); @@ -4073,31 +4099,34 @@ class HttpClient { const defaultPort = usingSsl ? 443 : 80; info.options = {}; info.options.host = info.parsedUrl.hostname; - info.options.port = info.parsedUrl.port ? parseInt(info.parsedUrl.port) : defaultPort; - info.options.path = (info.parsedUrl.pathname || '') + (info.parsedUrl.search || ''); + info.options.port = info.parsedUrl.port + ? parseInt(info.parsedUrl.port) + : defaultPort; + info.options.path = + (info.parsedUrl.pathname || '') + (info.parsedUrl.search || ''); info.options.method = method; info.options.headers = this._mergeHeaders(headers); if (this.userAgent != null) { - info.options.headers["user-agent"] = this.userAgent; + info.options.headers['user-agent'] = this.userAgent; } info.options.agent = this._getAgent(info.parsedUrl); // gives handlers an opportunity to participate if (this.handlers) { - this.handlers.forEach((handler) => { + this.handlers.forEach(handler => { handler.prepareRequest(info.options); }); } return info; } _mergeHeaders(headers) { - const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {}); + const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {}); if (this.requestOptions && this.requestOptions.headers) { return Object.assign({}, lowercaseKeys(this.requestOptions.headers), lowercaseKeys(headers)); } return lowercaseKeys(headers || {}); } _getExistingOrDefaultHeader(additionalHeaders, header, _default) { - const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => (c[k.toLowerCase()] = obj[k], c), {}); + const lowercaseKeys = obj => Object.keys(obj).reduce((c, k) => ((c[k.toLowerCase()] = obj[k]), c), {}); let clientHeader; if (this.requestOptions && this.requestOptions.headers) { clientHeader = lowercaseKeys(this.requestOptions.headers)[header]; @@ -4135,7 +4164,7 @@ class HttpClient { proxyAuth: proxyUrl.auth, host: proxyUrl.hostname, port: proxyUrl.port - }, + } }; let tunnelAgent; const overHttps = proxyUrl.protocol === 'https:'; @@ -4162,7 +4191,9 @@ class HttpClient { // we don't want to set NODE_TLS_REJECT_UNAUTHORIZED=0 since that will affect request for entire process // http.RequestOptions doesn't expose a way to modify RequestOptions.agent.options // we have to cast it to any and change it directly - agent.options = Object.assign(agent.options || {}, { rejectUnauthorized: false }); + agent.options = Object.assign(agent.options || {}, { + rejectUnauthorized: false + }); } return agent; } @@ -4223,7 +4254,7 @@ class HttpClient { msg = contents; } else { - msg = "Failed request: (" + statusCode + ")"; + msg = 'Failed request: (' + statusCode + ')'; } let err = new Error(msg); // attach statusCode and body obj (if available) to the error object @@ -4242,6 +4273,68 @@ class HttpClient { exports.HttpClient = HttpClient; +/***/ }), + +/***/ 540: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(__webpack_require__(470)); +const installer = __importStar(__webpack_require__(923)); +const auth = __importStar(__webpack_require__(331)); +const path = __importStar(__webpack_require__(622)); +function run() { + return __awaiter(this, void 0, void 0, function* () { + try { + // Type of release. Either a release version, known as General Availability ("ga") or an Early Access ("ea") + const release_type = core.getInput('release_type') || 'ga'; + // OpenJDK feature release version, example: "8", "11", "13". + const javaVersion = core.getInput('java-version', { required: true }); + // OpenJDK implementation, example: "hotspot", "openj9". + const openjdk_impl = core.getInput('openjdk_impl') || 'hotspot'; + // Architecture of the JDK, example: "x64", "x32", "arm", "ppc64", "s390x", "ppc64le", "aarch64", "sparcv9". + const arch = core.getInput('architecture', { required: false }) || 'x64'; + // Heap size for OpenJ9, example: "normal", "large" (for heaps >=57 GiB). + const heap_size = core.getInput('heap_size', { required: false }) || 'normal'; + // Exact release of OpenJDK, example: "latest", "jdk-11.0.4+11.4", "jdk8u172-b00-201807161800". + const release = core.getInput('release') || 'latest'; + // The image type (jre, jdk) + const javaPackage = core.getInput('java-package', { required: false }) || 'jdk'; + const jdkFile = core.getInput('jdkFile', { required: false }) || ''; + yield installer.getAdoptOpenJDK(release_type, javaVersion, javaPackage, openjdk_impl, arch, heap_size, release, jdkFile); + const matchersPath = path.join(__dirname, '..', '.github'); + console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); + const id = core.getInput('server-id', { required: false }) || undefined; + const username = core.getInput('server-username', { required: false }) || undefined; + const password = core.getInput('server-password', { required: false }) || undefined; + yield auth.configAuthentication(id, username, password); + } + catch (error) { + core.setFailed(error.message); + } + }); +} +run(); + + /***/ }), /***/ 605: @@ -4519,60 +4612,6 @@ module.exports = bytesToUuid; module.exports = require("fs"); -/***/ }), - -/***/ 811: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const core = __importStar(__webpack_require__(470)); -const installer = __importStar(__webpack_require__(923)); -const auth = __importStar(__webpack_require__(331)); -const path = __importStar(__webpack_require__(622)); -function run() { - return __awaiter(this, void 0, void 0, function* () { - try { - let version = core.getInput('version'); - if (!version) { - version = core.getInput('java-version', { required: true }); - } - const arch = core.getInput('architecture', { required: true }); - const javaPackage = core.getInput('java-package', { required: true }); - const jdkFile = core.getInput('jdkFile', { required: false }) || ''; - yield installer.getJava(version, arch, jdkFile, javaPackage); - const matchersPath = path.join(__dirname, '..', '.github'); - console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); - const id = core.getInput('server-id', { required: false }) || undefined; - const username = core.getInput('server-username', { required: false }) || undefined; - const password = core.getInput('server-password', { required: false }) || undefined; - yield auth.configAuthentication(id, username, password); - } - catch (error) { - core.setFailed(error.message); - } - }); -} -run(); - - /***/ }), /***/ 826: @@ -4650,6 +4689,9 @@ const fs = __importStar(__webpack_require__(747)); const path = __importStar(__webpack_require__(622)); const semver = __importStar(__webpack_require__(280)); const IS_WINDOWS = process.platform === 'win32'; +const IS_MACOS = process.platform === 'darwin'; +const toolName = 'AdoptOpenJDK'; +const os = getOsString(process.platform); if (!tempDirectory) { let baseLocation; if (IS_WINDOWS) { @@ -4795,7 +4837,7 @@ function unzipJavaDownload(repoRoot, fileEnding, destinationFolder, extension) { const stats = fs.statSync(jdkFile); if (stats.isFile()) { yield extractFiles(jdkFile, fileEnding, destinationFolder); - const jdkDirectory = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]); + const jdkDirectory = getJdkDirectory(destinationFolder); yield unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin')); return jdkDirectory; } @@ -4898,6 +4940,78 @@ function normalizeVersion(version) { } return version; } +function getOsString(platform) { + switch (platform) { + case 'win32': + return 'windows'; + case 'darwin': + return 'mac'; + default: + return 'linux'; + } +} +function getCacheVersionSpec(release_type, version, image_type, jvm_impl, os, arch, heap_size, release) { + return `1.0.0-${release_type}-${version}-${image_type}-${jvm_impl}-${os}-${arch}-${heap_size}-${release}`; +} +function getAdoptOpenJDK(release_type, version, image_type, jvm_impl, arch, heap_size, release, jdkFile) { + return __awaiter(this, void 0, void 0, function* () { + return downloadJavaBinary(release_type, version, image_type, jvm_impl, os, arch, heap_size, release, jdkFile); + }); +} +exports.getAdoptOpenJDK = getAdoptOpenJDK; +function getAdoptOpenJdkUrl(release_type, version, image_type, jvm_impl, os, arch, heap_size, release) { + const feature_version = version; + const release_type_parsed = release_type; + if (release == 'latest') { + return `https://api.adoptopenjdk.net/v3/binary/latest/${feature_version}/${release_type_parsed}/${os}/${arch}/${image_type}/${jvm_impl}/${heap_size}/adoptopenjdk`; + } + else { + const release_name = encodeURIComponent(release); + return `https://api.adoptopenjdk.net/v3/binary/version/${release_name}/${os}/${arch}/${image_type}/${jvm_impl}/${heap_size}/adoptopenjdk`; + } +} +function getJdkDirectory(destinationFolder) { + const jdkRoot = path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]); + if (IS_MACOS) { + const binDirectory = path.join(jdkRoot, 'bin'); + if (fs.existsSync(binDirectory)) { + return jdkRoot; + } + else { + return path.join(jdkRoot, 'Contents', 'Home'); + } + } + else { + return jdkRoot; + } +} +function downloadJavaBinary(release_type, version, image_type, jvm_impl, os, arch, heap_size, release, jdkFile) { + return __awaiter(this, void 0, void 0, function* () { + const versionSpec = getCacheVersionSpec(release_type, version, image_type, jvm_impl, os, arch, heap_size, release); + let toolPath = tc.find(toolName, versionSpec, arch); + if (toolPath) { + core.debug(`Tool found in cache ${toolPath}`); + } + else { + let compressedFileExtension = ''; + if (!jdkFile) { + core.debug('Downloading JDK from AdoptOpenJDK'); + const url = getAdoptOpenJdkUrl(release_type, version, image_type, jvm_impl, os, arch, heap_size, release); + jdkFile = yield tc.downloadTool(url); + compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; + } + compressedFileExtension = compressedFileExtension || getFileEnding(jdkFile); + let tempDir = path.join(tempDirectory, 'adoptopenjdk_' + Math.floor(Math.random() * 2000000000)); + const jdkDir = yield unzipJavaDownload(jdkFile, compressedFileExtension, tempDir); + core.debug(`JDK extracted to ${jdkDir}`); + toolPath = yield tc.cacheDir(jdkDir, toolName, versionSpec, arch); + } + const extendedJavaHome = `JAVA_HOME_${version}_${arch}`; + core.exportVariable('JAVA_HOME', toolPath); + core.exportVariable(extendedJavaHome, toolPath); + core.addPath(path.join(toolPath, 'bin')); + }); +} /***/ }), @@ -4917,12 +5031,10 @@ function getProxyUrl(reqUrl) { } let proxyVar; if (usingSsl) { - proxyVar = process.env["https_proxy"] || - process.env["HTTPS_PROXY"]; + proxyVar = process.env['https_proxy'] || process.env['HTTPS_PROXY']; } else { - proxyVar = process.env["http_proxy"] || - process.env["HTTP_PROXY"]; + proxyVar = process.env['http_proxy'] || process.env['HTTP_PROXY']; } if (proxyVar) { proxyUrl = url.parse(proxyVar); @@ -4934,7 +5046,7 @@ function checkBypass(reqUrl) { if (!reqUrl.hostname) { return false; } - let noProxy = process.env["no_proxy"] || process.env["NO_PROXY"] || ''; + let noProxy = process.env['no_proxy'] || process.env['NO_PROXY'] || ''; if (!noProxy) { return false; } @@ -4955,7 +5067,10 @@ function checkBypass(reqUrl) { upperReqHosts.push(`${upperReqHosts[0]}:${reqPort}`); } // Compare request host against noproxy - for (let upperNoProxyItem of noProxy.split(',').map(x => x.trim().toUpperCase()).filter(x => x)) { + for (let upperNoProxyItem of noProxy + .split(',') + .map(x => x.trim().toUpperCase()) + .filter(x => x)) { if (upperReqHosts.some(x => x === upperNoProxyItem)) { return true; } diff --git a/docs/contributors.md b/docs/contributors.md index fbf0c1ed..62760204 100644 --- a/docs/contributors.md +++ b/docs/contributors.md @@ -31,4 +31,4 @@ Any files generated using `tsc` will be added to `lib/*`, however those files al Tests are included under `_tests_/*` and can be run using `npm run-script test`. -We ask that you include a link to a successful run that utilizes the changes you are working on. For example, if your changes are in the branch `newAwesomeFeature`, then show an example run that uses `setup-python@newAwesomeFeature` or `my-fork@newAwesomeFeature`. This will help speed up testing and help us confirm that there are no breaking changes or bugs. \ No newline at end of file +We ask that you include a link to a successful run that utilizes the changes you are working on. For example, if your changes are in the branch `newAwesomeFeature`, then show an example run that uses `setup-python@newAwesomeFeature` or `my-fork@newAwesomeFeature`. This will help speed up testing and help us confirm that there are no breaking changes or bugs. diff --git a/lib/installer.js b/lib/installer.js new file mode 100644 index 00000000..baf792a2 --- /dev/null +++ b/lib/installer.js @@ -0,0 +1,169 @@ +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); +const io = __importStar(require("@actions/io")); +const exec = __importStar(require("@actions/exec")); +const tc = __importStar(require("@actions/tool-cache")); +const fs = __importStar(require("fs")); +const path = __importStar(require("path")); +const IS_WINDOWS = process.platform === 'win32'; +const IS_MACOS = process.platform === 'darwin'; +const toolName = 'AdoptOpenJDK'; +const os = getOsString(process.platform); +const tempDirectory = getTempDirectory(process.env['RUNNER_TEMP'] || ''); +function getTempDirectory(tempDirectory) { + if (!tempDirectory) { + let baseLocation; + switch (process.platform) { + case 'win32': + baseLocation = process.env['USERPROFILE'] || 'C:\\'; + break; + case 'darwin': + baseLocation = '/Users'; + break; + default: + baseLocation = '/home'; + } + return path.join(baseLocation, 'actions', 'temp'); + } + else { + return tempDirectory; + } +} +function getOsString(platform) { + switch (platform) { + case 'win32': + return 'windows'; + case 'darwin': + return 'mac'; + default: + return 'linux'; + } +} +function getFeatureVersion(version) { + return version.replace('openjdk', ''); +} +function getReleaseType(release_type) { + switch (release_type) { + case 'releases': + return 'ga'; + case 'nightly': + return 'ea'; + default: + return release_type; + } +} +function getAdoptOpenJdkUrl(release_type, version, jvm_impl, os, arch, heap_size, release) { + const feature_version = getFeatureVersion(version); + const release_type_parsed = getReleaseType(release_type); + if (release == 'latest') { + return `https://api.adoptopenjdk.net/v3/binary/latest/${feature_version}/${release_type_parsed}/${os}/${arch}/jdk/${jvm_impl}/${heap_size}/adoptopenjdk`; + } + else { + const release_name = encodeURIComponent(release); + return `https://api.adoptopenjdk.net/v3/binary/version/${release_name}/${os}/${arch}/jdk/${jvm_impl}/${heap_size}/adoptopenjdk`; + } +} +async function getJava(release_type, version, jvm_impl, arch, heap_size, release) { + return downloadJavaBinary(release_type, version, jvm_impl, os, arch, heap_size, release); +} +exports.getJava = getJava; +async function downloadJavaBinary(release_type, version, jvm_impl, os, arch, heap_size, release) { + const versionSpec = getCacheVersionSpec(release_type, version, jvm_impl, os, heap_size, release); + let toolPath = tc.find(toolName, versionSpec, arch); + if (toolPath) { + core.debug(`Tool found in cache ${toolPath}`); + } + else { + core.debug('Downloading JDK from AdoptOpenJDK'); + const release_encoded = encodeURIComponent(release); + const url = getAdoptOpenJdkUrl(release_type, version, jvm_impl, os, arch, heap_size, release); + const jdkFile = await tc.downloadTool(url); + const compressedFileExtension = IS_WINDOWS ? '.zip' : '.tar.gz'; + const tempDir = path.join(tempDirectory, 'adoptopenjdk_' + Math.floor(Math.random() * 2000000000)); + const jdkDir = await unzipJavaDownload(jdkFile, compressedFileExtension, tempDir); + core.debug(`JDK extracted to ${jdkDir}`); + toolPath = await tc.cacheDir(jdkDir, toolName, versionSpec, arch); + } + const extendedJavaHome = `JAVA_HOME_${version}_${arch}`; + core.exportVariable('JAVA_HOME', toolPath); + core.exportVariable(extendedJavaHome, toolPath); + core.addPath(path.join(toolPath, 'bin')); +} +function getCacheVersionSpec(release_type, version, jvm_impl, os, heap_size, release) { + return `1.0.0-${release_type}-${version}-${jvm_impl}-${heap_size}-${release}`; +} +async function extractFiles(file, fileEnding, destinationFolder) { + const stats = fs.statSync(file); + if (!stats) { + throw new Error(`Failed to extract ${file} - it doesn't exist`); + } + else if (stats.isDirectory()) { + throw new Error(`Failed to extract ${file} - it is a directory`); + } + switch (fileEnding) { + case '.tar': + case '.tar.gz': + await tc.extractTar(file, destinationFolder); + break; + case '.zip': + await tc.extractZip(file, destinationFolder); + break; + case '.7z': + await tc.extract7z(file, destinationFolder); + break; + default: + throw new Error(`Failed to extract ${file} - unknown compression`); + } +} +// This method recursively finds all .pack files under fsPath and unpacks them with the unpack200 tool +async function unpackJars(fsPath, javaBinPath) { + if (fs.existsSync(fsPath)) { + if (fs.lstatSync(fsPath).isDirectory()) { + for (const file in fs.readdirSync(fsPath)) { + const curPath = path.join(fsPath, file); + await unpackJars(curPath, javaBinPath); + } + } + else if (path.extname(fsPath).toLowerCase() === '.pack') { + // Unpack the pack file synchonously + const p = path.parse(fsPath); + const toolName = IS_WINDOWS ? 'unpack200.exe' : 'unpack200'; + const args = IS_WINDOWS ? '-r -v -l ""' : ''; + const name = path.join(p.dir, p.name); + await exec.exec(`"${path.join(javaBinPath, toolName)}"`, [ + `${args} "${name}.pack" "${name}.jar"` + ]); + } + } +} +async function unzipJavaDownload(repoRoot, fileEnding, destinationFolder) { + // Create the destination folder if it doesn't exist + await io.mkdirP(destinationFolder); + const jdkFile = path.normalize(repoRoot); + const stats = fs.statSync(jdkFile); + if (stats.isFile()) { + await extractFiles(jdkFile, fileEnding, destinationFolder); + const jdkDirectory = getJdkDirectory(destinationFolder); + await unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin')); + return jdkDirectory; + } + else { + throw new Error(`JDK argument ${jdkFile} is not a file`); + } +} +function getJdkDirectory(destinationFolder) { + if (IS_MACOS) { + return path.join(destinationFolder, fs.readdirSync(destinationFolder)[0], 'Contents', 'Home'); + } + else { + return path.join(destinationFolder, fs.readdirSync(destinationFolder)[0]); + } +} diff --git a/lib/setup-jdk.js b/lib/setup-jdk.js new file mode 100644 index 00000000..a082df69 --- /dev/null +++ b/lib/setup-jdk.js @@ -0,0 +1,35 @@ +"use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const core = __importStar(require("@actions/core")); +const installer = __importStar(require("./installer")); +const path = __importStar(require("path")); +async function run() { + try { + // Type of release. Either a release version, known as General Availability ("ga") or an Early Access ("ea") + const release_type = core.getInput('release_type') || 'ga'; + // OpenJDK feature release version, example: "8", "11", "13". + const javaVersion = core.getInput('java-version', { required: true }); + // OpenJDK implementation, example: "hotspot", "openj9". + const openjdk_impl = core.getInput('openjdk_impl') || 'hotspot'; + // Architecture of the JDK, example: "x64", "x32", "arm", "ppc64", "s390x", "ppc64le", "aarch64", "sparcv9". + const arch = core.getInput('architecture', { required: false }) || 'x64'; + // Heap size for OpenJ9, example: "normal", "large" (for heaps >=57 GiB). + const heap_size = core.getInput('heap_size', { required: false }) || 'normal'; + // Exact release of OpenJDK, example: "latest", "jdk-11.0.4+11.4", "jdk8u172-b00-201807161800". + const release = core.getInput('release') || 'latest'; + await installer.getJava(release_type, javaVersion, openjdk_impl, arch, heap_size, release); + const matchersPath = path.join(__dirname, '..', '.github'); + console.log(`##[add-matcher]${path.join(matchersPath, 'java.json')}`); + } + catch (error) { + core.setFailed(error.message); + } +} +run(); diff --git a/package-lock.json b/package-lock.json index 12271ed0..30d1ed79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "setup-java", + "name": "setup-jdk", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/package.json b/package.json index bc97adc1..43da0aeb 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "setup-java", + "name": "setup-jdk", "version": "1.0.0", "private": true, - "description": "setup java action", + "description": "Setup JDK action", "main": "dist/index.js", "scripts": { - "build": "ncc build src/setup-java.ts", + "build": "ncc build src/setup-jdk.ts", "format": "prettier --write **/*.ts", "format-check": "prettier --check **/*.ts", "prerelease": "npm run-script build", @@ -14,14 +14,16 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/actions/setup-java.git" + "url": "git+https://github.com/joschi/setup-jdk.git" }, "keywords": [ "actions", - "node", + "java", + "openjdk", + "adoptopenjdk", "setup" ], - "author": "GitHub", + "author": "Jochen Schalanda", "license": "MIT", "dependencies": { "@actions/core": "^1.0.0", diff --git a/src/installer.ts b/src/installer.ts index cce8fa3d..6264b072 100644 --- a/src/installer.ts +++ b/src/installer.ts @@ -10,6 +10,9 @@ import * as path from 'path'; import * as semver from 'semver'; const IS_WINDOWS = process.platform === 'win32'; +const IS_MACOS = process.platform === 'darwin'; +const toolName = 'AdoptOpenJDK'; +const os = getOsString(process.platform); if (!tempDirectory) { let baseLocation; @@ -87,6 +90,7 @@ export async function getJava( } let extendedJavaHome = 'JAVA_HOME_' + version + '_' + arch; + core.exportVariable('JAVA_HOME', toolPath); core.exportVariable(extendedJavaHome, toolPath); core.addPath(path.join(toolPath, 'bin')); @@ -174,10 +178,7 @@ async function unzipJavaDownload( const stats = fs.statSync(jdkFile); if (stats.isFile()) { await extractFiles(jdkFile, fileEnding, destinationFolder); - const jdkDirectory = path.join( - destinationFolder, - fs.readdirSync(destinationFolder)[0] - ); + const jdkDirectory = getJdkDirectory(destinationFolder); await unpackJars(jdkDirectory, path.join(jdkDirectory, 'bin')); return jdkDirectory; } else { @@ -297,3 +298,150 @@ function normalizeVersion(version: string): string { return version; } + +function getOsString(platform: string): string { + switch (platform) { + case 'win32': + return 'windows'; + case 'darwin': + return 'mac'; + default: + return 'linux'; + } +} + +function getCacheVersionSpec( + release_type: string, + version: string, + image_type: string, + jvm_impl: string, + os: string, + arch: string, + heap_size: string, + release: string +): string { + return `1.0.0-${release_type}-${version}-${image_type}-${jvm_impl}-${os}-${arch}-${heap_size}-${release}`; +} + +export async function getAdoptOpenJDK( + release_type: string, + version: string, + image_type: string, + jvm_impl: string, + arch: string, + heap_size: string, + release: string, + jdkFile: string +): Promise