From a9718db8baf3c1f89197842dd2ea4670edc2184d Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Sat, 21 Sep 2019 20:57:04 +0200 Subject: [PATCH 1/8] add code of conduct --- CODE_OF_CONDUCT.md | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..1a69bb8 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at paul@nosphere.org. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq From 76166f0035a8b49e874f4e40bdd3defd2eb49342 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Sat, 21 Sep 2019 21:02:05 +0200 Subject: [PATCH 2/8] refine readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 71725fd..0c0e368 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ This Github Action can be used to run arbitrary Gradle commands on any platform supported by Github Actions. +You might also be interested by the related [Gradle Plugin](https://github.com/eskatos/gradle-github-actions-plugin) that allows your build to easily get Github Actions environment and tag Gradle Build Scans accordingly. ## Usage From 8337949d8063ec2270f296fd9cacb6abef4959a2 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Sun, 22 Sep 2019 11:06:17 +0200 Subject: [PATCH 3/8] better .gitignore --- .gitignore | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3f5bd6d..990c566 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,9 @@ -__tests__/runner/* lib/ +node_modules + +.idea +*.iml +__tests__/runner/* # Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore # Logs @@ -42,7 +46,6 @@ bower_components build/Release # Dependency directories -node_modules/ jspm_packages/ # TypeScript v1 declaration files From f943246fd92762908748903799e272e7dec23608 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 23 Sep 2019 12:10:22 +0200 Subject: [PATCH 4/8] refine readme --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c0e368..c514296 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ You might also be interested by the related [Gradle Plugin](https://github.com/e ## Usage -The following workflow will run `gradle build` using the wrapper from the repository on ubuntu, macos and windows: +The following workflow will run `gradle build` using the wrapper from the repository on ubuntu, macos and windows. The only prerequisite is to have Java installed, you can define the version you need to run the build using the `actions/setup-java` action. + + ```yaml // .github/workflows/gradle-build-pr.yml @@ -95,7 +97,7 @@ Moreover, you can use the following aliases: | `nightly` | The latest [nightly](https://gradle.org/nightly/), fails if none. | | `release-nightly` | The latest [release nightly](https://gradle.org/release-nightly/), fails if none. | -This can be handy to automatically test your build with the next Gradle version once a release candidate is out: +This can be handy to, for example, automatically test your build with the next Gradle version once a release candidate is out: ```yaml // .github/workflows/test-gradle-rc.yml From 7a4f128c224a63922ebf45c3e677eeaf0543b3e4 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 23 Sep 2019 12:10:32 +0200 Subject: [PATCH 5/8] refine tsconfig --- tsconfig.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tsconfig.json b/tsconfig.json index 80c0492..a381dc4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - // "incremental": true, /* Enable incremental compilation */ + "incremental": true, /* Enable incremental compilation */ "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ // "allowJs": true, /* Allow javascript files to be compiled. */ @@ -15,7 +15,7 @@ "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ - // "removeComments": true, /* Do not emit comments to output. */ + "removeComments": true, /* Do not emit comments to output. */ // "noEmit": true, /* Do not emit outputs. */ // "importHelpers": true, /* Import emit helpers from 'tslib'. */ // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ @@ -23,13 +23,13 @@ /* Strict Type-Checking Options */ "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ + "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ "strictNullChecks": true, /* Enable strict null checks. */ "strictFunctionTypes": true, /* Enable strict checking of function types. */ "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ /* Additional Checks */ // "noUnusedLocals": true, /* Report errors on unused locals. */ From 091093ee6132fc2ecc6b9ca34ff1a0e841303723 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 23 Sep 2019 12:10:49 +0200 Subject: [PATCH 6/8] polish src/gradlew.ts --- src/gradlew.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/gradlew.ts b/src/gradlew.ts index 6437c7e..bd11935 100644 --- a/src/gradlew.ts +++ b/src/gradlew.ts @@ -1,9 +1,11 @@ -export function wrapperFilename() { - const isWindows = process.platform === "win32"; - return isWindows ? "gradlew.bat" : "gradlew"; +const IS_WINDOWS = process.platform === "win32"; + + +export function wrapperFilename(): string { + return IS_WINDOWS ? "gradlew.bat" : "gradlew"; } -export function installScriptFilename() { - const isWindows = process.platform === "win32"; - return isWindows ? "gradle.bat" : "gradle"; + +export function installScriptFilename(): string { + return IS_WINDOWS ? "gradle.bat" : "gradle"; } From 0a56b592f268b47839d8d670746d6520a2594f0e Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 23 Sep 2019 12:11:18 +0200 Subject: [PATCH 7/8] capture build scan url on failed build --- src/execution.ts | 20 +++++++++++--------- src/main.ts | 8 ++++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/execution.ts b/src/execution.ts index 4389441..dc1364d 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -4,10 +4,11 @@ import * as exec from "@actions/exec"; export async function execute(executable: string, root: string, argv: string[]): Promise { let publishing = false; - let buildScanLink: any = null; + let buildScanUrl: string | undefined; - await exec.exec(executable, argv, { + const status: number = await exec.exec(executable, argv, { cwd: root, + ignoreReturnCode: true, listeners: { stdline: (line: string) => { if (line.startsWith("Publishing build scan...")) { @@ -17,24 +18,25 @@ export async function execute(executable: string, root: string, argv: string[]): publishing = false } if (publishing && line.startsWith("http")) { - buildScanLink = line.trim(); + buildScanUrl = line.trim(); publishing = false } } } }); - if (buildScanLink != null) { - return new BuildResultImpl(buildScanLink.toString()); - } - return new BuildResultImpl(null as unknown as string); + return new BuildResultImpl(status, buildScanUrl); } export interface BuildResult { - buildScanUrl: string + readonly status: number + readonly buildScanUrl?: string } class BuildResultImpl implements BuildResult { - constructor(readonly buildScanUrl: string) { + constructor( + readonly status: number, + readonly buildScanUrl?: string + ) { } } diff --git a/src/main.ts b/src/main.ts index 174d97b..82f048f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,7 +8,7 @@ import * as provision from "./provision"; // Invoked by Github Actions -async function run() { +export async function run() { try { const baseDirectory = process.env[`GITHUB_WORKSPACE`] || ""; @@ -19,10 +19,14 @@ async function run() { parseCommandLineArguments() ); - if (result.buildScanUrl != null) { + if (result.buildScanUrl) { core.setOutput("build-scan-url", result.buildScanUrl); } + if (result.status != 0) { + core.setFailed(`Gradle process exited with status ${result.status}`) + } + } catch (error) { core.setFailed(error.message); } From 38eaee068d1243451f036cc10eddea84404a0035 Mon Sep 17 00:00:00 2001 From: Paul Merlin Date: Mon, 23 Sep 2019 12:12:03 +0200 Subject: [PATCH 8/8] polish src/provision.ts --- src/provision.ts | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/provision.ts b/src/provision.ts index 8506344..454eecb 100644 --- a/src/provision.ts +++ b/src/provision.ts @@ -9,8 +9,12 @@ import * as toolCache from "@actions/tool-cache"; import * as gradlew from "./gradlew"; +const httpc = new httpm.HttpClient("eskatos/gradle-command-action"); +const gradleVersionsBaseUrl = "https://services.gradle.org/versions"; + + /** - * @return Gradle executable + * @return Gradle executable path */ export async function gradleVersion(gradleVersion: string): Promise { switch (gradleVersion) { @@ -28,9 +32,6 @@ export async function gradleVersion(gradleVersion: string): Promise { } -const gradleVersionsBaseUrl = "https://services.gradle.org/versions"; - - async function gradleCurrent(): Promise { const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/current`); return provisionGradle(json.version, json.downloadUrl); @@ -39,7 +40,7 @@ async function gradleCurrent(): Promise { async function gradleReleaseCandidate(): Promise { const json = await gradleVersionDeclaration(`${gradleVersionsBaseUrl}/release-candidate`); - if (json != null) { + if (json) { return provisionGradle(json.version, json.downloadUrl); } return gradleCurrent(); @@ -60,39 +61,32 @@ async function gradleReleaseNightly(): Promise { async function gradle(version: string): Promise { const declaration = await findGradleVersionDeclaration(version); - if (declaration == null) { + if (!declaration) { throw new Error(`Gradle version ${version} does not exists`); } return provisionGradle(declaration.version, declaration.downloadUrl); } -async function gradleVersionDeclaration(url: string): Promise { - const httpc = new httpm.HttpClient("gradle-github-action"); - const response = await httpc.get(url); - const body = await response.readBody(); - const json = JSON.parse(body); - return (json == null || json.version == null || json.version.length <= 0) - ? null - : json +async function gradleVersionDeclaration(url: string): Promise { + const json: any = await httpGetJson(url); + return (json.version && json.version.length > 0) ? json : undefined } -async function findGradleVersionDeclaration(version: string): Promise { - const httpc = new httpm.HttpClient("gradle-github-action"); - const response = await httpc.get(`${gradleVersionsBaseUrl}/all`); - const body = await response.readBody(); - const json = JSON.parse(body); - const found = json.find(entry => { - return entry.version == version; +async function findGradleVersionDeclaration(version: string): Promise { + const json: any = await httpGetJson(`${gradleVersionsBaseUrl}/all`); + const found: any = json.find((entry: any) => { + return entry.version === version; }); - return found != undefined ? found : null + return found ? found : undefined } + async function provisionGradle(version: string, url: string): Promise { const cachedInstall: string = 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; @@ -130,9 +124,15 @@ function executableFrom(installDir: string): string { } +async function httpGetJson(url: string): Promise { + const response = await httpc.get(url); + const body = await response.readBody(); + return JSON.parse(body); +} + + async function httpDownload(url: string, path: string): Promise { 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)