Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add optional working-directory input #2

Merged
merged 1 commit into from
Feb 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ jobs:
| `issue-title` | Title of issue created for reporting results | :x: | `'Results of eslint-remote-tester-run-action'` | `'Results of weekly scheduled smoke test'` |
| `eslint-remote-tester-config` | Path to project's `eslint-remote-tester.config.js` | :x: | `'eslint-remote-tester.config.js'` | `./path/to/custom.config.js` |
| `max-result-count` | Maximum result count to be posted in result comment. Can be override with `maxResultCount` option in comment. | :x: | `50` | `100` |
| `working-directory` | The working directory where action is run | :x: | :x: | `./ci` |
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ inputs:
description: 'Maximum result count to be posted in result comment'
required: false
default: 50
working-directory:
description: The working directory where action is run
required: false

runs:
using: 'node12'
Expand Down
47 changes: 26 additions & 21 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ var require_core = __commonJS((exports2) => {
var file_command_1 = require_file_command();
var utils_1 = require_utils();
var os = __importStar(require("os"));
var path3 = __importStar(require("path"));
var path4 = __importStar(require("path"));
var ExitCode;
(function(ExitCode2) {
ExitCode2[ExitCode2["Success"] = 0] = "Success";
Expand Down Expand Up @@ -224,7 +224,7 @@ var require_core = __commonJS((exports2) => {
} else {
command_1.issueCommand("add-path", {}, inputPath);
}
process.env["PATH"] = `${inputPath}${path3.delimiter}${process.env["PATH"]}`;
process.env["PATH"] = `${inputPath}${path4.delimiter}${process.env["PATH"]}`;
}
exports2.addPath = addPath;
function getInput3(name, options) {
Expand Down Expand Up @@ -313,8 +313,8 @@ var require_context = __commonJS((exports2) => {
if (fs_1.existsSync(process.env.GITHUB_EVENT_PATH)) {
this.payload = JSON.parse(fs_1.readFileSync(process.env.GITHUB_EVENT_PATH, {encoding: "utf8"}));
} else {
const path3 = process.env.GITHUB_EVENT_PATH;
process.stdout.write(`GITHUB_EVENT_PATH ${path3} does not exist${os_1.EOL}`);
const path4 = process.env.GITHUB_EVENT_PATH;
process.stdout.write(`GITHUB_EVENT_PATH ${path4} does not exist${os_1.EOL}`);
}
}
this.eventName = process.env.GITHUB_EVENT_NAME;
Expand Down Expand Up @@ -4528,7 +4528,7 @@ var require_io_util = __commonJS((exports2) => {
Object.defineProperty(exports2, "__esModule", {value: true});
var assert_1 = require("assert");
var fs3 = require("fs");
var path3 = require("path");
var path4 = require("path");
_a = fs3.promises, exports2.chmod = _a.chmod, exports2.copyFile = _a.copyFile, exports2.lstat = _a.lstat, exports2.mkdir = _a.mkdir, exports2.readdir = _a.readdir, exports2.readlink = _a.readlink, exports2.rename = _a.rename, exports2.rmdir = _a.rmdir, exports2.stat = _a.stat, exports2.symlink = _a.symlink, exports2.unlink = _a.unlink;
exports2.IS_WINDOWS = process.platform === "win32";
function exists(fsPath) {
Expand Down Expand Up @@ -4566,7 +4566,7 @@ var require_io_util = __commonJS((exports2) => {
function mkdirP(fsPath, maxDepth = 1e3, depth = 1) {
return __awaiter(this, void 0, void 0, function* () {
assert_1.ok(fsPath, "a path argument must be provided");
fsPath = path3.resolve(fsPath);
fsPath = path4.resolve(fsPath);
if (depth >= maxDepth)
return exports2.mkdir(fsPath);
try {
Expand All @@ -4575,7 +4575,7 @@ var require_io_util = __commonJS((exports2) => {
} catch (err) {
switch (err.code) {
case "ENOENT": {
yield mkdirP(path3.dirname(fsPath), maxDepth, depth + 1);
yield mkdirP(path4.dirname(fsPath), maxDepth, depth + 1);
yield exports2.mkdir(fsPath);
return;
}
Expand Down Expand Up @@ -4606,7 +4606,7 @@ var require_io_util = __commonJS((exports2) => {
}
if (stats && stats.isFile()) {
if (exports2.IS_WINDOWS) {
const upperExt = path3.extname(filePath).toUpperCase();
const upperExt = path4.extname(filePath).toUpperCase();
if (extensions.some((validExt) => validExt.toUpperCase() === upperExt)) {
return filePath;
}
Expand All @@ -4630,11 +4630,11 @@ var require_io_util = __commonJS((exports2) => {
if (stats && stats.isFile()) {
if (exports2.IS_WINDOWS) {
try {
const directory = path3.dirname(filePath);
const upperName = path3.basename(filePath).toUpperCase();
const directory = path4.dirname(filePath);
const upperName = path4.basename(filePath).toUpperCase();
for (const actualName of yield exports2.readdir(directory)) {
if (upperName === actualName.toUpperCase()) {
filePath = path3.join(directory, actualName);
filePath = path4.join(directory, actualName);
break;
}
}
Expand Down Expand Up @@ -4698,7 +4698,7 @@ var require_io = __commonJS((exports2) => {
};
Object.defineProperty(exports2, "__esModule", {value: true});
var childProcess = require("child_process");
var path3 = require("path");
var path4 = require("path");
var util_1 = require("util");
var ioUtil = require_io_util();
var exec2 = util_1.promisify(childProcess.exec);
Expand All @@ -4709,7 +4709,7 @@ var require_io = __commonJS((exports2) => {
if (destStat && destStat.isFile() && !force) {
return;
}
const newDest = destStat && destStat.isDirectory() ? path3.join(dest, path3.basename(source)) : dest;
const newDest = destStat && destStat.isDirectory() ? path4.join(dest, path4.basename(source)) : dest;
if (!(yield ioUtil.exists(source))) {
throw new Error(`no such file or directory: ${source}`);
}
Expand All @@ -4721,7 +4721,7 @@ var require_io = __commonJS((exports2) => {
yield cpDirRecursive(source, newDest, 0, force);
}
} else {
if (path3.relative(source, newDest) === "") {
if (path4.relative(source, newDest) === "") {
throw new Error(`'${newDest}' and '${source}' are the same file`);
}
yield copyFile(source, newDest, force);
Expand All @@ -4734,7 +4734,7 @@ var require_io = __commonJS((exports2) => {
if (yield ioUtil.exists(dest)) {
let destExists = true;
if (yield ioUtil.isDirectory(dest)) {
dest = path3.join(dest, path3.basename(source));
dest = path4.join(dest, path4.basename(source));
destExists = yield ioUtil.exists(dest);
}
if (destExists) {
Expand All @@ -4745,7 +4745,7 @@ var require_io = __commonJS((exports2) => {
}
}
}
yield mkdirP(path3.dirname(dest));
yield mkdirP(path4.dirname(dest));
yield ioUtil.rename(source, dest);
});
}
Expand Down Expand Up @@ -4811,7 +4811,7 @@ var require_io = __commonJS((exports2) => {
try {
const extensions = [];
if (ioUtil.IS_WINDOWS && process.env.PATHEXT) {
for (const extension of process.env.PATHEXT.split(path3.delimiter)) {
for (const extension of process.env.PATHEXT.split(path4.delimiter)) {
if (extension) {
extensions.push(extension);
}
Expand All @@ -4829,14 +4829,14 @@ var require_io = __commonJS((exports2) => {
}
const directories = [];
if (process.env.PATH) {
for (const p of process.env.PATH.split(path3.delimiter)) {
for (const p of process.env.PATH.split(path4.delimiter)) {
if (p) {
directories.push(p);
}
}
}
for (const directory of directories) {
const filePath = yield ioUtil.tryGetExecutablePath(directory + path3.sep + tool, extensions);
const filePath = yield ioUtil.tryGetExecutablePath(directory + path4.sep + tool, extensions);
if (filePath) {
return filePath;
}
Expand Down Expand Up @@ -4940,7 +4940,7 @@ var require_toolrunner = __commonJS((exports2) => {
var os = __importStar(require("os"));
var events = __importStar(require("events"));
var child = __importStar(require("child_process"));
var path3 = __importStar(require("path"));
var path4 = __importStar(require("path"));
var io = __importStar(require_io());
var ioUtil = __importStar(require_io_util());
var IS_WINDOWS = process.platform === "win32";
Expand Down Expand Up @@ -5144,7 +5144,7 @@ var require_toolrunner = __commonJS((exports2) => {
exec() {
return __awaiter(this, void 0, void 0, function* () {
if (!ioUtil.isRooted(this.toolPath) && (this.toolPath.includes("/") || IS_WINDOWS && this.toolPath.includes("\\"))) {
this.toolPath = path3.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath);
this.toolPath = path4.resolve(process.cwd(), this.options.cwd || process.cwd(), this.toolPath);
}
this.toolPath = yield io.which(this.toolPath, true);
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -5755,6 +5755,7 @@ __export(exports, {
__handleForTests: () => __handleForTests
});
var import_fs2 = __toModule(require("fs"));
var import_path3 = __toModule(require("path"));
var core3 = __toModule(require_core());

// src/github-client.ts
Expand Down Expand Up @@ -5927,6 +5928,10 @@ async function run() {
const maxResultCount = core3.getInput("max-result-count", {
required: true
});
const workingDirectory = core3.getInput("working-directory");
if (workingDirectory) {
process.chdir(import_path3.default.join(process.cwd(), workingDirectory));
}
await core3.group("Running eslint-remote-tester", () => runTester(eslintRemoteTesterConfig));
await core3.group("Posting results", async () => {
const comparisonResults = import_fs2.default.readFileSync(RESULTS_TMP, "utf8");
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs';
import path from 'path';
import * as core from '@actions/core';

import GithubClient from './github-client';
Expand All @@ -16,6 +17,11 @@ async function run() {
required: true,
});

const workingDirectory = core.getInput('working-directory');
if (workingDirectory) {
process.chdir(path.join(process.cwd(), workingDirectory));
}

await core.group('Running eslint-remote-tester', () =>
runTester(eslintRemoteTesterConfig)
);
Expand Down
12 changes: 12 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jest.mock('../src/comment-templates', () => ({
ERROR_TEMPLATE: mockErrorTemplate,
}));

process.chdir = jest.fn();

async function runEntryPoint() {
jest.resetModules();
return require('../src/index').__handleForTests;
Expand All @@ -54,6 +56,16 @@ describe('entrypoint', () => {
);
});

test('sets working-directory', async () => {
(process.chdir as jest.Mock).mockClear();

await runEntryPoint();

expect(process.chdir).toHaveBeenCalledWith(
process.cwd() + '/mock-working-directory'
);
});

test('calls GithubClient with formatted results', async () => {
await runEntryPoint();

Expand Down