mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-12-26 01:46:18 +08:00
build
This commit is contained in:
parent
e561eefa28
commit
6170f06e8d
@ -20,9 +20,10 @@ const exec = __importStar(require("@actions/exec"));
|
|||||||
function execute(executable, root, argv) {
|
function execute(executable, root, argv) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
let publishing = false;
|
let publishing = false;
|
||||||
let buildScanLink = null;
|
let buildScanUrl;
|
||||||
yield exec.exec(executable, argv, {
|
const status = yield exec.exec(executable, argv, {
|
||||||
cwd: root,
|
cwd: root,
|
||||||
|
ignoreReturnCode: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stdline: (line) => {
|
stdline: (line) => {
|
||||||
if (line.startsWith("Publishing build scan...")) {
|
if (line.startsWith("Publishing build scan...")) {
|
||||||
@ -32,21 +33,19 @@ function execute(executable, root, argv) {
|
|||||||
publishing = false;
|
publishing = false;
|
||||||
}
|
}
|
||||||
if (publishing && line.startsWith("http")) {
|
if (publishing && line.startsWith("http")) {
|
||||||
buildScanLink = line.trim();
|
buildScanUrl = line.trim();
|
||||||
publishing = false;
|
publishing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (buildScanLink != null) {
|
return new BuildResultImpl(status, buildScanUrl);
|
||||||
return new BuildResultImpl(buildScanLink.toString());
|
|
||||||
}
|
|
||||||
return new BuildResultImpl(null);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.execute = execute;
|
exports.execute = execute;
|
||||||
class BuildResultImpl {
|
class BuildResultImpl {
|
||||||
constructor(buildScanUrl) {
|
constructor(status, buildScanUrl) {
|
||||||
|
this.status = status;
|
||||||
this.buildScanUrl = buildScanUrl;
|
this.buildScanUrl = buildScanUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const IS_WINDOWS = process.platform === "win32";
|
||||||
function wrapperFilename() {
|
function wrapperFilename() {
|
||||||
const isWindows = process.platform === "win32";
|
return IS_WINDOWS ? "gradlew.bat" : "gradlew";
|
||||||
return isWindows ? "gradlew.bat" : "gradlew";
|
|
||||||
}
|
}
|
||||||
exports.wrapperFilename = wrapperFilename;
|
exports.wrapperFilename = wrapperFilename;
|
||||||
function installScriptFilename() {
|
function installScriptFilename() {
|
||||||
const isWindows = process.platform === "win32";
|
return IS_WINDOWS ? "gradle.bat" : "gradle";
|
||||||
return isWindows ? "gradle.bat" : "gradle";
|
|
||||||
}
|
}
|
||||||
exports.installScriptFilename = installScriptFilename;
|
exports.installScriptFilename = installScriptFilename;
|
||||||
|
@ -22,21 +22,24 @@ const string_argv_1 = require("string-argv");
|
|||||||
const execution = __importStar(require("./execution"));
|
const execution = __importStar(require("./execution"));
|
||||||
const gradlew = __importStar(require("./gradlew"));
|
const gradlew = __importStar(require("./gradlew"));
|
||||||
const provision = __importStar(require("./provision"));
|
const provision = __importStar(require("./provision"));
|
||||||
// Invoked by Github Actions
|
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
|
const baseDirectory = process.env[`GITHUB_WORKSPACE`] || "";
|
||||||
let result = yield execution.execute(yield resolveGradleExecutable(baseDirectory), resolveBuildRootDirectory(baseDirectory), parseCommandLineArguments());
|
let result = yield execution.execute(yield resolveGradleExecutable(baseDirectory), resolveBuildRootDirectory(baseDirectory), parseCommandLineArguments());
|
||||||
if (result.buildScanUrl != null) {
|
if (result.buildScanUrl) {
|
||||||
core.setOutput("build-scan-url", result.buildScanUrl);
|
core.setOutput("build-scan-url", result.buildScanUrl);
|
||||||
}
|
}
|
||||||
|
if (result.status != 0) {
|
||||||
|
core.setFailed(`Gradle process exited with status ${result.status}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
exports.run = run;
|
||||||
run();
|
run();
|
||||||
function resolveGradleExecutable(baseDirectory) {
|
function resolveGradleExecutable(baseDirectory) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
@ -24,9 +24,8 @@ const core = __importStar(require("@actions/core"));
|
|||||||
const io = __importStar(require("@actions/io"));
|
const io = __importStar(require("@actions/io"));
|
||||||
const toolCache = __importStar(require("@actions/tool-cache"));
|
const toolCache = __importStar(require("@actions/tool-cache"));
|
||||||
const gradlew = __importStar(require("./gradlew"));
|
const gradlew = __importStar(require("./gradlew"));
|
||||||
/**
|
const httpc = new httpm.HttpClient("eskatos/gradle-command-action");
|
||||||
* @return Gradle executable
|
const gradleVersionsBaseUrl = "https://services.gradle.org/versions";
|
||||||
*/
|
|
||||||
function gradleVersion(gradleVersion) {
|
function gradleVersion(gradleVersion) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
switch (gradleVersion) {
|
switch (gradleVersion) {
|
||||||
@ -44,7 +43,6 @@ function gradleVersion(gradleVersion) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.gradleVersion = gradleVersion;
|
exports.gradleVersion = gradleVersion;
|
||||||
const gradleVersionsBaseUrl = "https://services.gradle.org/versions";
|
|
||||||
function gradleCurrent() {
|
function gradleCurrent() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
|
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`);
|
||||||
@ -54,7 +52,7 @@ function gradleCurrent() {
|
|||||||
function gradleReleaseCandidate() {
|
function gradleReleaseCandidate() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
|
const json = yield gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`);
|
||||||
if (json != null) {
|
if (json) {
|
||||||
return provisionGradle(json.version, json.downloadUrl);
|
return provisionGradle(json.version, json.downloadUrl);
|
||||||
}
|
}
|
||||||
return gradleCurrent();
|
return gradleCurrent();
|
||||||
@ -75,7 +73,7 @@ function gradleReleaseNightly() {
|
|||||||
function gradle(version) {
|
function gradle(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const declaration = yield findGradleVersionDeclaration(version);
|
const declaration = yield findGradleVersionDeclaration(version);
|
||||||
if (declaration == null) {
|
if (!declaration) {
|
||||||
throw new Error(`Gradle version ${version} does not exists`);
|
throw new Error(`Gradle version ${version} does not exists`);
|
||||||
}
|
}
|
||||||
return provisionGradle(declaration.version, declaration.downloadUrl);
|
return provisionGradle(declaration.version, declaration.downloadUrl);
|
||||||
@ -83,31 +81,23 @@ function gradle(version) {
|
|||||||
}
|
}
|
||||||
function gradleVersionDeclaration(url) {
|
function gradleVersionDeclaration(url) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpc = new httpm.HttpClient("gradle-github-action");
|
const json = yield httpGetJson(url);
|
||||||
const response = yield httpc.get(url);
|
return (json.version && json.version.length > 0) ? json : undefined;
|
||||||
const body = yield response.readBody();
|
|
||||||
const json = JSON.parse(body);
|
|
||||||
return (json == null || json.version == null || json.version.length <= 0)
|
|
||||||
? null
|
|
||||||
: json;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function findGradleVersionDeclaration(version) {
|
function findGradleVersionDeclaration(version) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const httpc = new httpm.HttpClient("gradle-github-action");
|
const json = yield httpGetJson(`${gradleVersionsBaseUrl}/all`);
|
||||||
const response = yield httpc.get(`${gradleVersionsBaseUrl}/all`);
|
const found = json.find((entry) => {
|
||||||
const body = yield response.readBody();
|
return entry.version === version;
|
||||||
const json = JSON.parse(body);
|
|
||||||
const found = json.find(entry => {
|
|
||||||
return entry.version == version;
|
|
||||||
});
|
});
|
||||||
return found != undefined ? found : null;
|
return found ? found : undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function provisionGradle(version, url) {
|
function provisionGradle(version, url) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const cachedInstall = toolCache.find("gradle", version);
|
const cachedInstall = toolCache.find("gradle", version);
|
||||||
if (cachedInstall != null && cachedInstall.length > 0) {
|
if (cachedInstall.length > 0) {
|
||||||
const cachedExecutable = executableFrom(cachedInstall);
|
const cachedExecutable = executableFrom(cachedInstall);
|
||||||
core.info(`Provisioned Gradle executable ${cachedExecutable}`);
|
core.info(`Provisioned Gradle executable ${cachedExecutable}`);
|
||||||
return cachedExecutable;
|
return cachedExecutable;
|
||||||
@ -135,10 +125,16 @@ function provisionGradle(version, url) {
|
|||||||
function executableFrom(installDir) {
|
function executableFrom(installDir) {
|
||||||
return path.join(installDir, "bin", `${gradlew.installScriptFilename()}`);
|
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) {
|
function httpDownload(url, path) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
const httpc = new httpm.HttpClient("gradle-github-action");
|
|
||||||
const writeStream = fs.createWriteStream(path);
|
const writeStream = fs.createWriteStream(path);
|
||||||
httpc.get(url).then(response => {
|
httpc.get(url).then(response => {
|
||||||
response.message.pipe(writeStream)
|
response.message.pipe(writeStream)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user