This commit is contained in:
Paul Merlin
2019-09-23 12:20:06 +02:00
parent e561eefa28
commit 6170f06e8d
4 changed files with 33 additions and 36 deletions

View File

@@ -24,9 +24,8 @@ const core = __importStar(require("@actions/core"));
const io = __importStar(require("@actions/io"));
const toolCache = __importStar(require("@actions/tool-cache"));
const gradlew = __importStar(require("./gradlew"));
/**
* @return Gradle executable
*/
const httpc = new httpm.HttpClient("eskatos/gradle-command-action");
const gradleVersionsBaseUrl = "https://services.gradle.org/versions";
function gradleVersion(gradleVersion) {
return __awaiter(this, void 0, void 0, function* () {
switch (gradleVersion) {
@@ -44,7 +43,6 @@ function gradleVersion(gradleVersion) {
});
}
exports.gradleVersion = gradleVersion;
const gradleVersionsBaseUrl = "https://services.gradle.org/versions";
function gradleCurrent() {
return __awaiter(this, void 0, void 0, function* () {
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
@@ -54,7 +52,7 @@ function gradleCurrent() {
function gradleReleaseCandidate() {
return __awaiter(this, void 0, void 0, function* () {
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
if (json != null) {
if (json) {
return provisionGradle(json.version, json.downloadUrl);
}
return gradleCurrent();
@@ -75,7 +73,7 @@ function gradleReleaseNightly() {
function gradle(version) {
return __awaiter(this, void 0, void 0, function* () {
const declaration = yield findGradleVersionDeclaration(version);
if (declaration == null) {
if (!declaration) {
throw new Error(`Gradle version ${version} does not exists`);
}
return provisionGradle(declaration.version, declaration.downloadUrl);
@@ -83,31 +81,23 @@ function gradle(version) {
}
function gradleVersionDeclaration(url) {
return __awaiter(this, void 0, void 0, function* () {
const httpc = new httpm.HttpClient("gradle-github-action");
const response = yield httpc.get(url);
const body = yield response.readBody();
const json = JSON.parse(body);
return (json == null || json.version == null || json.version.length <= 0)
? null
: json;
const json = yield httpGetJson(url);
return (json.version && json.version.length > 0) ? json : undefined;
});
}
function findGradleVersionDeclaration(version) {
return __awaiter(this, void 0, void 0, function* () {
const httpc = new httpm.HttpClient("gradle-github-action");
const response = yield httpc.get(`${gradleVersionsBaseUrl}/all`);
const body = yield response.readBody();
const json = JSON.parse(body);
const found = json.find(entry => {
return entry.version == version;
const json = yield httpGetJson(`${gradleVersionsBaseUrl}/all`);
const found = json.find((entry) => {
return entry.version === version;
});
return found != undefined ? found : null;
return found ? found : undefined;
});
}
function provisionGradle(version, url) {
return __awaiter(this, void 0, void 0, function* () {
const cachedInstall = toolCache.find("gradle", version);
if (cachedInstall != null && cachedInstall.length > 0) {
if (cachedInstall.length > 0) {
const cachedExecutable = executableFrom(cachedInstall);
core.info(`Provisioned Gradle executable ${cachedExecutable}`);
return cachedExecutable;
@@ -135,10 +125,16 @@ function provisionGradle(version, url) {
function executableFrom(installDir) {
return path.join(installDir, "bin", `${gradlew.installScriptFilename()}`);
}
function httpGetJson(url) {
return __awaiter(this, void 0, void 0, function* () {
const response = yield httpc.get(url);
const body = yield response.readBody();
return JSON.parse(body);
});
}
function httpDownload(url, path) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise(function (resolve, reject) {
const httpc = new httpm.HttpClient("gradle-github-action");
const writeStream = fs.createWriteStream(path);
httpc.get(url).then(response => {
response.message.pipe(writeStream)