feat: add glob patterns support for files input

Resolves #657
This commit is contained in:
Rabyâ Raghib 2022-02-23 20:05:10 +01:00
parent b3e7f56250
commit 9b59098e04
No known key found for this signature in database
GPG key ID: 94D020F4FEFDEA95
6 changed files with 55 additions and 21 deletions

35
package-lock.json generated
View file

@ -12,6 +12,7 @@
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@actions/glob": "^0.2.0",
"node-fetch": "^3.2.0",
"openpgp": "^5.1.0"
},
@ -56,6 +57,15 @@
"@octokit/plugin-rest-endpoint-methods": "^5.1.1"
}
},
"node_modules/@actions/glob": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.0.tgz",
"integrity": "sha512-mqE2a7I66kxcvsdwxs/filQwZsq25IfktMaviGfDB51v6Q3bvxnV7mFsZnvYtLhqGZbPxwBnH8AD3UYaOWb//w==",
"dependencies": {
"@actions/core": "^1.2.6",
"minimatch": "^3.0.4"
}
},
"node_modules/@actions/http-client": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
@ -1880,8 +1890,7 @@
"node_modules/balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"node_modules/base": {
"version": "0.11.2",
@ -1927,7 +1936,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"dependencies": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2275,8 +2283,7 @@
"node_modules/concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"node_modules/convert-source-map": {
"version": "1.8.0",
@ -5097,7 +5104,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"dependencies": {
"brace-expansion": "^1.1.7"
},
@ -7667,6 +7673,15 @@
"@octokit/plugin-rest-endpoint-methods": "^5.1.1"
}
},
"@actions/glob": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/@actions/glob/-/glob-0.2.0.tgz",
"integrity": "sha512-mqE2a7I66kxcvsdwxs/filQwZsq25IfktMaviGfDB51v6Q3bvxnV7mFsZnvYtLhqGZbPxwBnH8AD3UYaOWb//w==",
"requires": {
"@actions/core": "^1.2.6",
"minimatch": "^3.0.4"
}
},
"@actions/http-client": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
@ -9094,8 +9109,7 @@
"balanced-match": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==",
"dev": true
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
"base": {
"version": "0.11.2",
@ -9137,7 +9151,6 @@
"version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"dev": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -9413,8 +9426,7 @@
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=",
"dev": true
"integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
},
"convert-source-map": {
"version": "1.8.0",
@ -11601,7 +11613,6 @@
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"dev": true,
"requires": {
"brace-expansion": "^1.1.7"
}

View file

@ -26,6 +26,7 @@
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@actions/glob": "^0.2.0",
"node-fetch": "^3.2.0",
"openpgp": "^5.1.0"
},

View file

@ -0,0 +1,7 @@
import * as glob from "@actions/glob";
// This is in a separate file so that it can be mocked in tests
export const getFilesByGlobs = async (files: string) => {
const globber = await glob.create(files.split(",").join("\n"));
return await globber.glob();
};

View file

@ -7,8 +7,17 @@ const {version} = require('../package.json');
const context = github.context;
test('no arguments', () => {
const {execArgs, failCi} = buildExec();
jest.mock("./buildExec-get-files.ts", () => {
return {
__esModule: true,
getFilesByGlobs: async (files: string) => {
return files.split(",");
}
};
});
test('no arguments', async () => {
const {execArgs, failCi} = await buildExec();
const args = [
'-n',
@ -23,7 +32,7 @@ test('no arguments', () => {
expect(failCi).toBeFalsy();
});
test('all arguments', () => {
test('all arguments', async () => {
const envs = {
'commit_parent': '83231650328f11695dfb754ca0f540516f188d27',
'directory': 'coverage/',
@ -55,7 +64,7 @@ test('all arguments', () => {
process.env['INPUT_' + env.toUpperCase()] = envs[env];
}
const {execArgs, failCi} = buildExec();
const {execArgs, failCi} = await buildExec();
expect(execArgs).toEqual([
'-n',
'codecov',

View file

@ -2,6 +2,7 @@ import * as core from '@actions/core';
import * as github from '@actions/github';
import {version} from '../package.json';
import { getFilesByGlobs } from './buildExec-get-files';
const context = github.context;
@ -16,7 +17,8 @@ const isTrue = (variable) => {
);
};
const buildExec = () => {
const buildExec = async () => {
const clean = core.getInput('move_coverage_to_trash');
const commitParent = core.getInput('commit_parent');
const envVars = core.getInput('env_vars');
@ -96,8 +98,8 @@ const buildExec = () => {
execArgs.push('-f', `${file}`);
}
if (files) {
files.split(',').forEach((f) => {
execArgs.push('-f', `${f}`);
(await getFilesByGlobs(files)).forEach((f) => {
execArgs.push("-f", `${f}`);
});
}
if (flags) {

View file

@ -17,8 +17,8 @@ import versionInfo from './version';
let failCi;
try {
const {execArgs, options, failCi, os, uploaderVersion} = buildExec();
async function main() {
const {execArgs, options, failCi, os, uploaderVersion} = await buildExec();
const platform = getPlatform(os);
const filename = path.join( __dirname, getUploaderName(platform));
@ -60,6 +60,10 @@ try {
});
});
});
}
try {
main();
} catch (err) {
setFailure(`Codecov: Encountered an unexpected error ${err.message}`, failCi);
}