Compare commits

...

2 Commits

Author SHA1 Message Date
Fabio Niephaus
4aba115fa5 Improve error message when url not found. 2022-12-16 18:43:51 +01:00
Fabio Niephaus
7c84ab1ba7 Let getLatestRelease() always query github.com.
This should allow GitHub Enterprise users to use this action.

Resolves #26, resolves #27.
2022-12-13 09:12:43 +01:00
5 changed files with 80 additions and 22 deletions

25
__tests__/graalvm.test.ts Normal file
View File

@@ -0,0 +1,25 @@
import * as path from 'path'
import * as graalvm from '../src/graalvm'
import {expect, test} from '@jest/globals'
process.env['RUNNER_TOOL_CACHE'] = path.join(__dirname, 'TOOL_CACHE')
process.env['RUNNER_TEMP'] = path.join(__dirname, 'TEMP')
test('request invalid version/javaVersion', async () => {
for (var combination of [
['22.3.0', '7'],
['22.3', '17'],
['22.3', '7']
]) {
let error = new Error('unexpected')
try {
await graalvm.setUpGraalVMRelease('', combination[0], combination[1])
} catch (err) {
error = err
}
expect(error).not.toBeUndefined()
expect(error.message).toContain('Failed to download')
expect(error.message).toContain('Are you sure version')
}
})

8
dist/cleanup/index.js generated vendored
View File

@@ -74415,9 +74415,9 @@ const fs_1 = __nccwpck_require__(7147);
const core_1 = __nccwpck_require__(6762);
const crypto_1 = __nccwpck_require__(6113);
const path_1 = __nccwpck_require__(1017);
// Set up Octokit in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com';
const GitHub = core_1.Octokit.defaults({
// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = 'https://api.github.com';
const GitHubDotCom = core_1.Octokit.defaults({
baseUrl,
request: {
agent: new httpClient.HttpClient().getAgent(baseUrl)
@@ -74438,7 +74438,7 @@ function getLatestRelease(repo) {
return __awaiter(this, void 0, void 0, function* () {
const githubToken = getGitHubToken();
const options = githubToken.length > 0 ? { auth: githubToken } : {};
const octokit = new GitHub(options);
const octokit = new GitHubDotCom(options);
return (yield octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: c.GRAALVM_GH_USER,
repo

28
dist/main/index.js generated vendored
View File

@@ -74747,15 +74747,13 @@ exports.setUpGraalVMDevBuild = setUpGraalVMDevBuild;
function setUpGraalVMRelease(gdsToken, version, javaVersion) {
return __awaiter(this, void 0, void 0, function* () {
const isEE = gdsToken.length > 0;
const graalVMIdentifier = determineGraalVMIdentifier(isEE, version, javaVersion);
const toolName = determineToolName(isEE, javaVersion);
let downloader;
if (isEE) {
downloader = () => __awaiter(this, void 0, void 0, function* () { return gds_1.downloadGraalVMEE(gdsToken, version, javaVersion); });
}
else {
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`;
downloader = () => __awaiter(this, void 0, void 0, function* () { return tool_cache_1.downloadTool(downloadUrl); });
downloader = () => __awaiter(this, void 0, void 0, function* () { return downloadGraalVMCE(version, javaVersion); });
}
return utils_1.downloadExtractAndCacheJDK(downloader, toolName, version);
});
@@ -74767,6 +74765,22 @@ function determineGraalVMIdentifier(isEE, version, javaVersion) {
function determineToolName(isEE, javaVersion) {
return `graalvm-${isEE ? 'ee' : 'ce'}-java${javaVersion}-${c.GRAALVM_PLATFORM}`;
}
function downloadGraalVMCE(version, javaVersion) {
return __awaiter(this, void 0, void 0, function* () {
const graalVMIdentifier = determineGraalVMIdentifier(false, version, javaVersion);
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`;
try {
return yield tool_cache_1.downloadTool(downloadUrl);
}
catch (error) {
if (error instanceof Error && error.message.includes('404')) {
// Not Found
throw new Error(`Failed to download ${graalVMIdentifier}. Are you sure version: '${version}' and javaVersion: '${javaVersion}' are correct?`);
}
throw new Error(`Failed to download ${graalVMIdentifier} (error: ${error}).`);
}
});
}
/***/ }),
@@ -75162,9 +75176,9 @@ const fs_1 = __nccwpck_require__(7147);
const core_1 = __nccwpck_require__(6762);
const crypto_1 = __nccwpck_require__(6113);
const path_1 = __nccwpck_require__(1017);
// Set up Octokit in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com';
const GitHub = core_1.Octokit.defaults({
// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = 'https://api.github.com';
const GitHubDotCom = core_1.Octokit.defaults({
baseUrl,
request: {
agent: new httpClient.HttpClient().getAgent(baseUrl)
@@ -75185,7 +75199,7 @@ function getLatestRelease(repo) {
return __awaiter(this, void 0, void 0, function* () {
const githubToken = getGitHubToken();
const options = githubToken.length > 0 ? { auth: githubToken } : {};
const octokit = new GitHub(options);
const octokit = new GitHubDotCom(options);
return (yield octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: c.GRAALVM_GH_USER,
repo

View File

@@ -63,18 +63,12 @@ export async function setUpGraalVMRelease(
javaVersion: string
): Promise<string> {
const isEE = gdsToken.length > 0
const graalVMIdentifier = determineGraalVMIdentifier(
isEE,
version,
javaVersion
)
const toolName = determineToolName(isEE, javaVersion)
let downloader: () => Promise<string>
if (isEE) {
downloader = async () => downloadGraalVMEE(gdsToken, version, javaVersion)
} else {
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
downloader = async () => downloadTool(downloadUrl)
downloader = async () => downloadGraalVMCE(version, javaVersion)
}
return downloadExtractAndCacheJDK(downloader, toolName, version)
}
@@ -94,3 +88,28 @@ function determineToolName(isEE: boolean, javaVersion: string): string {
c.GRAALVM_PLATFORM
}`
}
async function downloadGraalVMCE(
version: string,
javaVersion: string
): Promise<string> {
const graalVMIdentifier = determineGraalVMIdentifier(
false,
version,
javaVersion
)
const downloadUrl = `${GRAALVM_CE_DL_BASE}/${GRAALVM_TAG_PREFIX}${version}/${graalVMIdentifier}${c.GRAALVM_FILE_EXTENSION}`
try {
return await downloadTool(downloadUrl)
} catch (error) {
if (error instanceof Error && error.message.includes('404')) {
// Not Found
throw new Error(
`Failed to download ${graalVMIdentifier}. Are you sure version: '${version}' and javaVersion: '${javaVersion}' are correct?`
)
}
throw new Error(
`Failed to download ${graalVMIdentifier} (error: ${error}).`
)
}
}

View File

@@ -9,9 +9,9 @@ import {Octokit} from '@octokit/core'
import {createHash} from 'crypto'
import {join} from 'path'
// Set up Octokit in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = process.env['GITHUB_API_URL'] || 'https://api.github.com'
const GitHub = Octokit.defaults({
// Set up Octokit for github.com only and in the same way as @actions/github (see https://git.io/Jy9YP)
const baseUrl = 'https://api.github.com'
const GitHubDotCom = Octokit.defaults({
baseUrl,
request: {
agent: new httpClient.HttpClient().getAgent(baseUrl)
@@ -38,7 +38,7 @@ export async function getLatestRelease(
): Promise<c.LatestReleaseResponse['data']> {
const githubToken = getGitHubToken()
const options = githubToken.length > 0 ? {auth: githubToken} : {}
const octokit = new GitHub(options)
const octokit = new GitHubDotCom(options)
return (
await octokit.request('GET /repos/{owner}/{repo}/releases/latest', {
owner: c.GRAALVM_GH_USER,