mirror of
https://github.com/codecov/codecov-action.git
synced 2025-12-08 16:16:24 +00:00
Compare commits
19 Commits
retry-bash
...
v1.0.11
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6d208f5b52 | ||
|
|
8ddda09c14 | ||
|
|
e16d515d3b | ||
|
|
6b30325ebb | ||
|
|
95f699a0a9 | ||
|
|
273443b325 | ||
|
|
a258ec8bb8 | ||
|
|
89692c91b7 | ||
|
|
85ec2c8d83 | ||
|
|
f3570723ef | ||
|
|
f40f110376 | ||
|
|
4f81def87b | ||
|
|
ddc46b3107 | ||
|
|
1b088680d5 | ||
|
|
22f6ff10ac | ||
|
|
0ceca4b5d3 | ||
|
|
3658bafacb | ||
|
|
ef3b48314f | ||
|
|
dbf1ddee08 |
23
.github/workflows/main.yml
vendored
23
.github/workflows/main.yml
vendored
@@ -1,14 +1,19 @@
|
||||
name: Example workflow for Codecov
|
||||
name: Workflow for Codecov Action
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- name: Upload coverage to Codecov
|
||||
uses: ./
|
||||
with:
|
||||
#commenting out token because tokenless uploads are now supported
|
||||
#token: ${{secrets.CODECOV_TOKEN}}
|
||||
flags: unittest
|
||||
name: codecov-1
|
||||
- name: Checkout
|
||||
uses: actions/checkout@master
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Run tests and collect coverage
|
||||
run: yarn run test-all
|
||||
- name: Upload coverage to Codecov
|
||||
uses: ./
|
||||
with:
|
||||
files: ./coverage/calculator/coverage-final.json,./coverage/index/coverage-final.json
|
||||
file: ./coverage/coverage-final.json
|
||||
flags: unittest
|
||||
name: codecov-1
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 Codecov
|
||||
Copyright (c) 2019-2020 Codecov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -20,6 +20,7 @@ steps:
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
|
||||
file: ./coverage.xml # optional
|
||||
files: ./coverage1.xml,./coverage2.xml # optional
|
||||
flags: unittests # optional
|
||||
name: codecov-umbrella # optional
|
||||
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* |
|
||||
| `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
|
||||
| `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
|
||||
| `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
|
||||
|
||||
@@ -71,10 +75,13 @@ jobs:
|
||||
with:
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
file: ./coverage.xml
|
||||
files: ./coverage1.xml,./coverage2.xml
|
||||
directory: ./coverage/reports/
|
||||
flags: unittests
|
||||
env_vars: OS,PYTHON
|
||||
name: codecov-umbrella
|
||||
fail_ci_if_error: true
|
||||
path_to_write_report: ./coverage/codecov_report.gz
|
||||
```
|
||||
## Contributing
|
||||
|
||||
|
||||
@@ -11,9 +11,18 @@ inputs:
|
||||
file:
|
||||
description: 'Path to coverage file to upload'
|
||||
required: false
|
||||
files:
|
||||
description: 'Comma-separated list of files to upload'
|
||||
required: false
|
||||
directory:
|
||||
description: 'Directory to search for coverage reports.'
|
||||
required: false
|
||||
flags:
|
||||
description: 'Flag upload to group coverage metrics (e.g. unittests | integration | ui,chrome)'
|
||||
required: false
|
||||
path_to_write_report:
|
||||
description: 'Write upload file to path before uploading'
|
||||
required: false
|
||||
env_vars:
|
||||
description: 'Environment variables to tag the upload with (e.g. PYTHON | OS,PYTHON)'
|
||||
required: false
|
||||
|
||||
23169
dist/index.js
vendored
23169
dist/index.js
vendored
File diff suppressed because one or more lines are too long
208
index.js
208
index.js
@@ -1,9 +1,7 @@
|
||||
const core = require("@actions/core");
|
||||
const exec = require("@actions/exec");
|
||||
const fs = require("fs");
|
||||
const request = require('retry-request', {
|
||||
request: require('request')
|
||||
});
|
||||
const request = require('requestretry');
|
||||
|
||||
let fail_ci;
|
||||
try {
|
||||
@@ -11,7 +9,10 @@ try {
|
||||
const token = core.getInput("token");
|
||||
const flags = core.getInput("flags");
|
||||
const file = core.getInput("file");
|
||||
const files = core.getInput("files");
|
||||
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();
|
||||
|
||||
@@ -27,106 +28,131 @@ try {
|
||||
fail_ci = false;
|
||||
}
|
||||
|
||||
const retryOpts = {
|
||||
retries: 3
|
||||
};
|
||||
|
||||
request("https://codecov.io/bash", retryOpts, (error, response, body) => {
|
||||
if (error && fail_ci) {
|
||||
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}`);
|
||||
request({
|
||||
url: "https://codecov.io/bash",
|
||||
json: false
|
||||
}, (error, response, body) => {
|
||||
try {
|
||||
if (error && fail_ci) {
|
||||
throw error;
|
||||
} else if (error) {
|
||||
core.warning(`Codecov warning: ${error.message}`);
|
||||
}
|
||||
|
||||
let output = "";
|
||||
let execError = "";
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: data => {
|
||||
output += data.toString();
|
||||
},
|
||||
stderr: data => {
|
||||
execError += data.toString();
|
||||
fs.writeFile("codecov.sh", body, err => {
|
||||
if (err && fail_ci) {
|
||||
throw err;
|
||||
} else if (err) {
|
||||
core.warning(`Codecov warning: ${err.message}`);
|
||||
}
|
||||
};
|
||||
|
||||
options.env = Object.assign(process.env, {
|
||||
GITHUB_ACTION: process.env.GITHUB_ACTION,
|
||||
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
|
||||
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 || ''
|
||||
});
|
||||
let output = "";
|
||||
let execError = "";
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: data => {
|
||||
output += data.toString();
|
||||
},
|
||||
stderr: data => {
|
||||
execError += data.toString();
|
||||
}
|
||||
};
|
||||
|
||||
if(token){
|
||||
options.env.CODECOV_TOKEN = token
|
||||
}
|
||||
options.env = Object.assign(process.env, {
|
||||
GITHUB_ACTION: process.env.GITHUB_ACTION,
|
||||
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
|
||||
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 = []
|
||||
for (let env_var of env_vars.split(",")) {
|
||||
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)
|
||||
if(token){
|
||||
options.env.CODECOV_TOKEN = token
|
||||
}
|
||||
}
|
||||
|
||||
const execArgs = ["codecov.sh"];
|
||||
if (file) {
|
||||
execArgs.push(
|
||||
"-f", `${file}`
|
||||
);
|
||||
}
|
||||
const env_vars_arg = []
|
||||
for (let env_var of env_vars.split(",")) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
execArgs.push(
|
||||
"-n", `${name}`,
|
||||
"-F", `${flags}`
|
||||
);
|
||||
const execArgs = ["codecov.sh"];
|
||||
if (file) {
|
||||
execArgs.push(
|
||||
"-f", `${file}`
|
||||
);
|
||||
}
|
||||
|
||||
if (fail_ci) {
|
||||
execArgs.push(
|
||||
"-Z"
|
||||
);
|
||||
}
|
||||
|
||||
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}`
|
||||
if (files) {
|
||||
files.split(',').forEach(f => {
|
||||
execArgs.push(
|
||||
"-f", `${f}`
|
||||
);
|
||||
} 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}`);
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
if (dir) {
|
||||
execArgs.push(
|
||||
"-s", `${dir}`
|
||||
);
|
||||
}
|
||||
|
||||
execArgs.push(
|
||||
"-n", `${name}`,
|
||||
"-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) {
|
||||
if (fail_ci) {
|
||||
|
||||
4
jest.config.js
Normal file
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
}
|
||||
4896
package-lock.json
generated
4896
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -1,10 +1,13 @@
|
||||
{
|
||||
"name": "codecov-action",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.12",
|
||||
"description": "Upload coverage reports to Codecov from GitHub Actions",
|
||||
"main": "index.js",
|
||||
"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"
|
||||
},
|
||||
"repository": {
|
||||
@@ -21,10 +24,16 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0",
|
||||
"@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",
|
||||
"jest": "^26.1.0",
|
||||
"jest-junit": "^10.0.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": {}
|
||||
}
|
||||
|
||||
11
src/calculator/calculator.test.ts
Normal file
11
src/calculator/calculator.test.ts
Normal 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);
|
||||
});
|
||||
10
src/calculator/calculator.ts
Normal file
10
src/calculator/calculator.ts
Normal 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
11
src/index/index.test.ts
Normal 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
21
src/index/index.ts
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user