Fix globbing, update metadata, update ncc (#4)

* Enable minimatch dot option
It's not a default globbing behavior, however for our use-case is much more convenient to match those files.

* Update README and package.json
This commit is contained in:
Michal Dorner 2020-05-21 13:46:48 +02:00 committed by GitHub
parent f9b6173f5e
commit 29d498d99d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 157 additions and 129 deletions

237
dist/index.js vendored
View file

@ -19,7 +19,13 @@ module.exports =
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ var threw = true;
/******/ try {
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete installedModules[moduleId];
/******/ }
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
@ -296,9 +302,9 @@ module.exports = require("tls");
/***/ }),
/***/ 18:
/***/ (function() {
/***/ (function(module) {
eval("require")("encoding");
module.exports = eval("require")("encoding");
/***/ }),
@ -4090,74 +4096,74 @@ function checkMode (stat, options) {
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const github = __importStar(__webpack_require__(469));
const filter_1 = __importDefault(__webpack_require__(235));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = core.getInput('githubToken', { required: true });
const filterYaml = core.getInput('filters', { required: true });
const client = new github.GitHub(token);
if (github.context.eventName !== 'pull_request') {
core.setFailed('This action can be triggered only by pull_request event');
return;
}
const pr = github.context.payload.pull_request;
const filter = new filter_1.default(filterYaml);
const files = yield getChangedFiles(client, pr);
const result = filter.match(files);
for (const key in result) {
core.setOutput(key, String(result[key]));
}
}
catch (error) {
core.setFailed(error.message);
}
});
}
// Uses github REST api to get list of files changed in PR
function getChangedFiles(client, pullRequest) {
return __awaiter(this, void 0, void 0, function* () {
const pageSize = 100;
const files = [];
for (let page = 0; page * pageSize < pullRequest.changed_files; page++) {
const response = yield client.pulls.listFiles({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: pullRequest.number,
page,
per_page: pageSize
});
for (const row of response.data) {
files.push(row.filename);
}
}
return files;
});
}
run();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const core = __importStar(__webpack_require__(470));
const github = __importStar(__webpack_require__(469));
const filter_1 = __importDefault(__webpack_require__(235));
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const token = core.getInput('githubToken', { required: true });
const filterYaml = core.getInput('filters', { required: true });
const client = new github.GitHub(token);
if (github.context.eventName !== 'pull_request') {
core.setFailed('This action can be triggered only by pull_request event');
return;
}
const pr = github.context.payload.pull_request;
const filter = new filter_1.default(filterYaml);
const files = yield getChangedFiles(client, pr);
const result = filter.match(files);
for (const key in result) {
core.setOutput(key, String(result[key]));
}
}
catch (error) {
core.setFailed(error.message);
}
});
}
// Uses github REST api to get list of files changed in PR
function getChangedFiles(client, pullRequest) {
return __awaiter(this, void 0, void 0, function* () {
const pageSize = 100;
const files = [];
for (let page = 0; page * pageSize < pullRequest.changed_files; page++) {
const response = yield client.pulls.listFiles({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: pullRequest.number,
page,
per_page: pageSize
});
for (const row of response.data) {
files.push(row.filename);
}
}
return files;
});
}
run();
/***/ }),
@ -4223,49 +4229,52 @@ module.exports = new Type('tag:yaml.org,2002:bool', {
/***/ (function(__unusedmodule, exports, __webpack_require__) {
"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsyaml = __importStar(__webpack_require__(414));
const minimatch = __importStar(__webpack_require__(595));
class Filter {
constructor(yaml) {
this.rules = {};
const doc = jsyaml.safeLoad(yaml);
if (typeof doc !== 'object') {
this.throwInvalidFormatError();
}
for (const name of Object.keys(doc)) {
const patterns = doc[name];
if (!Array.isArray(patterns)) {
this.throwInvalidFormatError();
}
if (!patterns.every(x => typeof x === 'string')) {
this.throwInvalidFormatError();
}
this.rules[name] = patterns.map(x => new minimatch.Minimatch(x));
}
}
// Returns dictionary with match result per rules group
match(paths) {
const result = {};
for (const [key, patterns] of Object.entries(this.rules)) {
const match = paths.some(fileName => patterns.some(rule => rule.match(fileName)));
result[key] = match;
}
return result;
}
throwInvalidFormatError() {
throw new Error('Invalid filter YAML format: Expected dictionary of string arrays');
}
}
exports.default = Filter;
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const jsyaml = __importStar(__webpack_require__(414));
const minimatch = __importStar(__webpack_require__(595));
class Filter {
constructor(yaml) {
this.rules = {};
const doc = jsyaml.safeLoad(yaml);
if (typeof doc !== 'object') {
this.throwInvalidFormatError();
}
const opts = {
dot: true
};
for (const name of Object.keys(doc)) {
const patterns = doc[name];
if (!Array.isArray(patterns)) {
this.throwInvalidFormatError();
}
if (!patterns.every(x => typeof x === 'string')) {
this.throwInvalidFormatError();
}
this.rules[name] = patterns.map(x => new minimatch.Minimatch(x, opts));
}
}
// Returns dictionary with match result per rules group
match(paths) {
const result = {};
for (const [key, patterns] of Object.entries(this.rules)) {
const match = paths.some(fileName => patterns.some(rule => rule.match(fileName)));
result[key] = match;
}
return result;
}
throwInvalidFormatError() {
throw new Error('Invalid filter YAML format: Expected dictionary of string arrays');
}
}
exports.default = Filter;
/***/ }),