Compare commits

..

23 Commits

Author SHA1 Message Date
Thomas Hu
7de38c9dc9 Add logging 2020-08-18 22:24:45 -04:00
Thomas Hu
6145016ec0 Update name default 2020-08-18 22:16:42 -04:00
Thomas Hu
6004246f47 Merge pull request #114 from codecov/timeouts
Add more timeout tries and decrease timeout time
2020-08-17 22:13:50 -04:00
Thomas Hu
5d3f01ccdc Up the number of attempts 2020-08-17 17:14:51 -04:00
Thomas Hu
2d80980946 Add more timeouts and sharter timeout 2020-08-17 17:05:37 -04:00
Thomas Hu
fadbb25281 Merge pull request #109 from ibrahim0814/patch-1
Update action.yml with new authors
2020-08-12 13:09:38 -04:00
Ibrahim Ali
ad774549da Update action.yml with new authors
Add Thomas Hu as new author 👍
2020-08-12 00:15:12 -07:00
Thomas Hu
07127fde53 Merge pull request #97 from codecov/dependabot/npm_and_yarn/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19
2020-07-22 09:57:50 -04:00
dependabot[bot]
9128542d5d Bump lodash from 4.17.15 to 4.17.19
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-17 18:34:08 +00:00
Thomas Hu
6d208f5b52 Merge pull request #96 from codecov/1.0.12
Wrap request promise in try catch
2020-07-17 14:33:32 -04:00
Thomas Hu
8ddda09c14 Wrap request promise in try catch 2020-07-17 11:57:18 -04:00
Thomas Hu
e16d515d3b Merge pull request #90 from codecov/directory-and-debug
Add directory and file save
2020-07-13 13:21:09 -04:00
Thomas Hu
6b30325ebb Merge branch 'master' into directory-and-debug 2020-07-13 13:00:02 -04:00
Thomas Hu
95f699a0a9 Merge pull request #94 from codecov/update-readme
Add files to README
2020-07-10 17:53:16 -04:00
Thomas Hu
273443b325 Add files to README 2020-07-10 15:32:51 -04:00
Thomas Hu
a258ec8bb8 Merge pull request #93 from codecov/specify-files
Specify files and add testing
2020-07-10 15:31:03 -04:00
Thomas Hu
89692c91b7 Specify files and add testing 2020-07-09 23:07:34 -04:00
Thomas Hu
85ec2c8d83 Add directory and file save 2020-07-07 22:36:09 -04:00
Thomas Hu
f3570723ef Merge pull request #89 from codecov/fix-ependency
Fix dependencies
2020-07-01 16:43:21 -04:00
Thomas Hu
f40f110376 Try requestretry 2020-07-01 15:47:57 -04:00
Thomas Hu
4f81def87b Upgrade ncc 2020-07-01 15:35:39 -04:00
Thomas Hu
ddc46b3107 Fix dependencies 2020-07-01 14:58:11 -04:00
Thomas Hu
1b088680d5 Fix dependencies 2020-07-01 14:48:26 -04:00
13 changed files with 26432 additions and 959 deletions

View File

@@ -1,16 +1,24 @@
name: Example workflow for Codecov name: Workflow for Codecov Action
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
run: run:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@master - name: Checkout
uses: actions/checkout@master
- name: Install dependencies - name: Install dependencies
run: npm install run: npm install
- name: Run tests and collect coverage
run: yarn run test-all
- name: Echo env variables
run: |
echo $GITHUB_RUN_ID
echo $GITHUB_RUN_NUMBER
echo $GITHUB_ACTION
- name: Upload coverage to Codecov - name: Upload coverage to Codecov
uses: ./ uses: ./
with: with:
#commenting out token because tokenless uploads are now supported files: ./coverage/calculator/coverage-final.json,./coverage/index/coverage-final.json
#token: ${{secrets.CODECOV_TOKEN}} file: ./coverage/coverage-final.json
flags: unittest flags: unittest
name: codecov-1 name: codecov-1

View File

@@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2019 Codecov Copyright (c) 2019-2020 Codecov
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View File

@@ -20,6 +20,7 @@ steps:
with: with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
file: ./coverage.xml # optional file: ./coverage.xml # optional
files: ./coverage1.xml,./coverage2.xml # optional
flags: unittests # optional flags: unittests # optional
name: codecov-umbrella # optional name: codecov-umbrella # optional
fail_ci_if_error: true # optional (default = false) fail_ci_if_error: true # optional (default = false)
@@ -36,10 +37,13 @@ Codecov's Action currently supports five inputs from the user: `token`, `file`,
| :---: | :---: | :---: | | :---: | :---: | :---: |
| `token` | Used to authorize coverage report uploads | *Required for private repos* | | `token` | Used to authorize coverage report uploads | *Required for private repos* |
| `file` | Path to the coverage report(s) | Optional | `file` | Path to the coverage report(s) | Optional
| `files` | Comma-separated paths to the coverage report(s) | Optional
| `directory` | Directory to search for coverage reports. | Optional
| `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional | `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional
| `env_vars` | Environment variables to tag the upload with. Multiple env variables can be separated with commas (e.g. `OS,PYTHON`) | Optional | `env_vars` | Environment variables to tag the upload with. Multiple env variables can be separated with commas (e.g. `OS,PYTHON`) | Optional
| `name` | Custom defined name for the upload | Optional | `name` | Custom defined name for the upload | Optional
| `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional | `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional
| `path_to_write_report` | Write upload file to path before uploading | Optional
### Example `workflow.yml` with Codecov Action ### Example `workflow.yml` with Codecov Action
@@ -71,10 +75,13 @@ jobs:
with: with:
token: ${{ secrets.CODECOV_TOKEN }} token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.xml file: ./coverage.xml
files: ./coverage1.xml,./coverage2.xml
directory: ./coverage/reports/
flags: unittests flags: unittests
env_vars: OS,PYTHON env_vars: OS,PYTHON
name: codecov-umbrella name: codecov-umbrella
fail_ci_if_error: true fail_ci_if_error: true
path_to_write_report: ./coverage/codecov_report.gz
``` ```
## Contributing ## Contributing

View File

@@ -1,9 +1,9 @@
name: 'Codecov' name: 'Codecov'
description: 'GitHub Action that uploads coverage reports for your repository to codecov.io' description: 'GitHub Action that uploads coverage reports for your repository to codecov.io'
author: 'Ibrahim Ali <@ibrahim0814> | Codecov' author: 'Ibrahim Ali <@ibrahim0814> & Thomas Hu <@thomasrockhu> | Codecov'
inputs: inputs:
name: name:
description: 'User defined upload name. Visible in Codecov UI' description: 'User defined upload name. Visible in Codecov UI. Defaults to ${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}'
required: false required: false
token: token:
description: 'Repository upload token - get it from codecov.io. Required only for private repositories' description: 'Repository upload token - get it from codecov.io. Required only for private repositories'
@@ -11,9 +11,18 @@ inputs:
file: file:
description: 'Path to coverage file to upload' description: 'Path to coverage file to upload'
required: false required: false
files:
description: 'Comma-separated list of files to upload'
required: false
directory:
description: 'Directory to search for coverage reports.'
required: false
flags: flags:
description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)' description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)'
required: false required: false
path_to_write_report:
description: 'Write upload file to path before uploading'
required: false
env_vars: env_vars:
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)' description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
required: false required: false

22163
dist/index.js vendored

File diff suppressed because one or more lines are too long

220
index.js
View File

@@ -1,9 +1,7 @@
const core = require("@actions/core"); const core = require("@actions/core");
const exec = require("@actions/exec"); const exec = require("@actions/exec");
const fs = require("fs"); const fs = require("fs");
const request = require('retry-request', { const request = require('requestretry');
request: require('request')
});
let fail_ci; let fail_ci;
try { try {
@@ -11,7 +9,10 @@ try {
const token = core.getInput("token"); const token = core.getInput("token");
const flags = core.getInput("flags"); const flags = core.getInput("flags");
const file = core.getInput("file"); const file = core.getInput("file");
const files = core.getInput("files");
const env_vars = core.getInput("env_vars"); const env_vars = core.getInput("env_vars");
const dir = core.getInput("directory");
const write_path = core.getInput("path_to_write_report");
fail_ci = core.getInput("fail_ci_if_error").toLowerCase(); fail_ci = core.getInput("fail_ci_if_error").toLowerCase();
@@ -27,106 +28,143 @@ try {
fail_ci = false; fail_ci = false;
} }
const retryOpts = { request({
retries: 3 json: false,
}; maxAttempts: 10,
timeout: 3000,
request("https://codecov.io/bash", retryOpts, (error, response, body) => { url: "https://codecov.io/bash"
if (error && fail_ci) { }, (error, response, body) => {
throw error; try {
} else if (error) { if (error && fail_ci) {
core.warning(`Codecov warning: ${error.message}`); throw error;
} } else if (error) {
core.warning(`Codecov warning: ${error.message}`);
fs.writeFile("codecov.sh", body, err => {
if (err && fail_ci) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
} }
let output = ""; fs.writeFile("codecov.sh", body, err => {
let execError = ""; if (err && fail_ci) {
const options = {}; throw err;
options.listeners = { } else if (err) {
stdout: data => { core.warning(`Codecov warning: ${err.message}`);
output += data.toString();
},
stderr: data => {
execError += data.toString();
} }
};
options.env = Object.assign(process.env, { let output = "";
GITHUB_ACTION: process.env.GITHUB_ACTION, let execError = "";
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, const options = {};
GITHUB_REF: process.env.GITHUB_REF, options.listeners = {
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY, stdout: data => {
GITHUB_SHA: process.env.GITHUB_SHA, output += data.toString();
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '' },
}); stderr: data => {
execError += data.toString();
}
};
if(token){ options.env = Object.assign(process.env, {
options.env.CODECOV_TOKEN = token GITHUB_ACTION: process.env.GITHUB_ACTION,
} GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
GITHUB_RUN_NUMBER: process.env.GITHUB_RUN_NUMBER,
GITHUB_REF: process.env.GITHUB_REF,
GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY,
GITHUB_SHA: process.env.GITHUB_SHA,
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || ''
});
const env_vars_arg = [] if(token){
for (let env_var of env_vars.split(",")) { options.env.CODECOV_TOKEN = token
let env_var_clean = env_var.trim();
if (env_var_clean) {
options.env[env_var_clean] = process.env[env_var_clean];
env_vars_arg.push(env_var_clean)
} }
}
const execArgs = ["codecov.sh"]; const env_vars_arg = []
if (file) { for (let env_var of env_vars.split(",")) {
execArgs.push( let env_var_clean = env_var.trim();
"-f", `${file}` if (env_var_clean) {
); options.env[env_var_clean] = process.env[env_var_clean];
} env_vars_arg.push(env_var_clean)
}
}
execArgs.push( const execArgs = ["codecov.sh"];
"-n", `${name}`, if (file) {
"-F", `${flags}` execArgs.push(
); "-f", `${file}`
);
}
if (fail_ci) { if (files) {
execArgs.push( files.split(',').forEach(f => {
"-Z" execArgs.push(
); "-f", `${f}`
}
if (env_vars_arg.length) {
execArgs.push(
"-e", env_vars_arg.join(",")
);
}
exec.exec("bash", execArgs, options)
.catch(err => {
if (fail_ci) {
core.setFailed(
`Codecov failed with the following error: ${err.message}`
); );
} else { });
core.warning(`Codecov warning: ${err.message}`); }
}
})
.then(() => {
unlinkFile();
});
const unlinkFile = () => { if (dir) {
fs.unlink("codecov.sh", err => { execArgs.push(
if (err && fail_ci) { "-s", `${dir}`
throw err; );
} else if (err) { }
core.warning(`Codecov warning: ${err.message}`);
} if (name) {
}); execArgs.push(
}; "-n", `${name}`
}); );
} else {
execArgs.push(
"-n", `${GITHUB_RUN_ID}-${GITHUB_RUN_NUMBER}`
);
}
execArgs.push(
"-F", `${flags}`
);
if (fail_ci) {
execArgs.push(
"-Z"
);
}
if (env_vars_arg.length) {
execArgs.push(
"-e", env_vars_arg.join(",")
);
}
if (write_path) {
execArgs.push(
"-q", `${write_path}`
);
}
exec.exec("bash", execArgs, options)
.catch(err => {
if (fail_ci) {
core.setFailed(
`Codecov failed with the following error: ${err.message}`
);
} else {
core.warning(`Codecov warning: ${err.message}`);
}
})
.then(() => {
unlinkFile();
});
const unlinkFile = () => {
fs.unlink("codecov.sh", err => {
if (err && fail_ci) {
throw err;
} else if (err) {
core.warning(`Codecov warning: ${err.message}`);
}
});
};
});
} catch (error) {
core.setFailed(
`Codecov failed with the following error: ${error.message}`
);
}
}); });
} catch (error) { } catch (error) {
if (fail_ci) { if (fail_ci) {

4
jest.config.js Normal file
View File

@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
}

4896
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,13 @@
{ {
"name": "codecov-action", "name": "codecov-action",
"version": "1.0.9", "version": "1.0.14",
"description": "Upload coverage reports to Codecov from GitHub Actions", "description": "Upload coverage reports to Codecov from GitHub Actions",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "jest --coverage",
"test-calculator": "jest --testPathPattern=src/calculator/ --coverage --coverageDirectory=coverage/calculator",
"test-index": "jest --testPathPattern=src/index --coverage --coverageDirectory=coverage/index",
"test-all": "yarn run test && yarn run test-calculator && yarn run test-index",
"build": "ncc build index.js" "build": "ncc build index.js"
}, },
"repository": { "repository": {
@@ -21,10 +24,16 @@
"dependencies": { "dependencies": {
"@actions/core": "^1.2.0", "@actions/core": "^1.2.0",
"@actions/exec": "^1.0.1", "@actions/exec": "^1.0.1",
"@zeit/ncc": "^0.20.5", "@types/jest": "^26.0.4",
"@zeit/ncc": "^0.22.3",
"fs": "0.0.1-security", "fs": "0.0.1-security",
"jest": "^26.1.0",
"jest-junit": "^10.0.0",
"request": "^2.88.0", "request": "^2.88.0",
"retry-request": "^4.1.1" "requestretry": "^4.1.1",
"ts-jest": "^26.1.1",
"typescript": "^3.9.6",
"yarn": "^1.22.4"
}, },
"devDependencies": {} "devDependencies": {}
} }

View File

@@ -0,0 +1,11 @@
import Calculator from './calculator'
test('adds 2 + 3 to equal 5', () => {
const calc = new Calculator()
expect(calc.add(2, 3)).toBe(5);
});
test('subtracts 2 - 3 to equal -1', () => {
const calc = new Calculator()
expect(calc.subtract(2, 3)).toBe(-1);
});

View File

@@ -0,0 +1,10 @@
export default class Calculator {
add(x : number, y : number) : number {
return x + y;
}
subtract(x: number, y: number) : number {
return x - y;
}
}

11
src/index/index.test.ts Normal file
View File

@@ -0,0 +1,11 @@
import Index from "./index";
test('test uncovered if', () => {
const indexObj = new Index();
expect(indexObj.uncovered_if()).toEqual(false);
});
test('fully covered', () => {
const indexObj = new Index();
expect(indexObj.fully_covered()).toEqual(true);
});

21
src/index/index.ts Normal file
View File

@@ -0,0 +1,21 @@
export default class Index {
//This function is tested and part of it is uncovered
uncovered_if = (a = true) => {
if (a == true) {
return false
} else {
return true
}
}
//This function will be fully covered
fully_covered = () => {
return true
}
//This function will not be tested by unit tests
uncovered = () => {
return true
}
}