mirror of
https://github.com/codecov/codecov-action.git
synced 2025-12-08 16:16:24 +00:00
Compare commits
200 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07127fde53 | ||
|
|
9128542d5d | ||
|
|
6d208f5b52 | ||
|
|
8ddda09c14 | ||
|
|
e16d515d3b | ||
|
|
6b30325ebb | ||
|
|
95f699a0a9 | ||
|
|
273443b325 | ||
|
|
a258ec8bb8 | ||
|
|
89692c91b7 | ||
|
|
85ec2c8d83 | ||
|
|
f3570723ef | ||
|
|
f40f110376 | ||
|
|
4f81def87b | ||
|
|
ddc46b3107 | ||
|
|
1b088680d5 | ||
|
|
22f6ff10ac | ||
|
|
0ceca4b5d3 | ||
|
|
3658bafacb | ||
|
|
ef3b48314f | ||
|
|
dbf1ddee08 | ||
|
|
cc6b0c11d2 | ||
|
|
f532c3a145 | ||
|
|
143333ba90 | ||
|
|
a50851cfd8 | ||
|
|
6914527afb | ||
|
|
fff75f1901 | ||
|
|
1804a456ff | ||
|
|
d1b4c72fc5 | ||
|
|
6fd09f835d | ||
|
|
e866b3854d | ||
|
|
608816e426 | ||
|
|
2ce3b3807d | ||
|
|
0e6a911c9b | ||
|
|
d04135f7cf | ||
|
|
7938e79f4c | ||
|
|
a3a6becb2c | ||
|
|
bf0e754c09 | ||
|
|
daa5098552 | ||
|
|
71d5dea6af | ||
|
|
e34ee48524 | ||
|
|
d7c91c57ee | ||
|
|
d9faadf52a | ||
|
|
c70450d006 | ||
|
|
a6d365dd4c | ||
|
|
94278ffe1b | ||
|
|
ebea5cacdf | ||
|
|
6a65fa4d50 | ||
|
|
4623a4dc3d | ||
|
|
c98408608b | ||
|
|
49c86d6a5f | ||
|
|
6ec347819d | ||
|
|
44ca3d2c84 | ||
|
|
66879ff350 | ||
|
|
797e92895e | ||
|
|
a6337803aa | ||
|
|
2613f978c9 | ||
|
|
4c6a7296af | ||
|
|
4fec3dfa96 | ||
|
|
355d574b25 | ||
|
|
a497b16d77 | ||
|
|
ab46201142 | ||
|
|
ecf5f576a0 | ||
|
|
8c950ae5c5 | ||
|
|
3d303911df | ||
|
|
eb1ea256cb | ||
|
|
5f55456d46 | ||
|
|
ade1ebf812 | ||
|
|
31d7d88849 | ||
|
|
d608de8763 | ||
|
|
08a0ecb0f3 | ||
|
|
3dfea70b3f | ||
|
|
f291e7ca9d | ||
|
|
78d806df69 | ||
|
|
dd4242c61d | ||
|
|
fc0e9fde50 | ||
|
|
cf0e744e2c | ||
|
|
fd07c5fc0c | ||
|
|
3d11715b9e | ||
|
|
cec654a0a7 | ||
|
|
41a31f1ccf | ||
|
|
d073b23c28 | ||
|
|
11d69070bf | ||
|
|
dd2a59ac10 | ||
|
|
3ec2345d08 | ||
|
|
aea83764c6 | ||
|
|
e6cea4aaed | ||
|
|
70f2402e00 | ||
|
|
e6af53269a | ||
|
|
7ab923356b | ||
|
|
8676a5a946 | ||
|
|
6afe2e0d90 | ||
|
|
67a2282699 | ||
|
|
e1a57b8a47 | ||
|
|
1be0517b99 | ||
|
|
889584d6f9 | ||
|
|
c4ca0425e1 | ||
|
|
8d062b28e1 | ||
|
|
a3ae14ab33 | ||
|
|
1259587051 | ||
|
|
dd61d9f90b | ||
|
|
6e83ad2f33 | ||
|
|
747c905e39 | ||
|
|
29e36a5e71 | ||
|
|
f0ee262b3a | ||
|
|
bab0bf56a8 | ||
|
|
efc5cbe89b | ||
|
|
3d61f3d4c8 | ||
|
|
db0171f588 | ||
|
|
7ba41fc0d6 | ||
|
|
d5749ba79a | ||
|
|
b4c0b83601 | ||
|
|
3cde50f4f1 | ||
|
|
10e590a5de | ||
|
|
af19dcb193 | ||
|
|
77e74f257f | ||
|
|
1c4a4261fa | ||
|
|
cb218a0977 | ||
|
|
e78f79e460 | ||
|
|
899e5c913e | ||
|
|
886c7c8bc8 | ||
|
|
75d10d924b | ||
|
|
e61b738355 | ||
|
|
cbad155b75 | ||
|
|
9e1c456662 | ||
|
|
392e5b2711 | ||
|
|
bd5538d84a | ||
|
|
9d47efe7b9 | ||
|
|
6aa7ac1896 | ||
|
|
c2a68071b3 | ||
|
|
8273bebacc | ||
|
|
6728012add | ||
|
|
e3f7b8baf8 | ||
|
|
4af6f0743e | ||
|
|
5c880506b5 | ||
|
|
a3a7edcc61 | ||
|
|
f93f6bdcae | ||
|
|
35b9267ca9 | ||
|
|
39a99a4e84 | ||
|
|
e0cc6d49d9 | ||
|
|
96d1c9a15d | ||
|
|
ee0d391ad0 | ||
|
|
bd3230c275 | ||
|
|
c7a04fdde5 | ||
|
|
efe83d2996 | ||
|
|
db5a766c55 | ||
|
|
1f99174e83 | ||
|
|
93d126a749 | ||
|
|
4546e138ba | ||
|
|
125cedf806 | ||
|
|
6f489c7a78 | ||
|
|
fc175be7b5 | ||
|
|
a166a95c4a | ||
|
|
dd94ace224 | ||
|
|
a8f7ad31ff | ||
|
|
ed370e2ded | ||
|
|
dd098b2f6b | ||
|
|
d2c4464978 | ||
|
|
97fe500537 | ||
|
|
111c74ca11 | ||
|
|
edbb6f8e5d | ||
|
|
7d121a89c0 | ||
|
|
159fdf6e54 | ||
|
|
4fb042f123 | ||
|
|
0766dd1553 | ||
|
|
e0683efc0b | ||
|
|
1b38d5e8b4 | ||
|
|
2793f27b99 | ||
|
|
afda60d339 | ||
|
|
f21e0e6d14 | ||
|
|
55d06088fa | ||
|
|
7461079497 | ||
|
|
eda3e0f75c | ||
|
|
c7f04ba6f0 | ||
|
|
67896f6476 | ||
|
|
1e6057f6d0 | ||
|
|
25df614d11 | ||
|
|
3ee0aad0bf | ||
|
|
93ee40a7a2 | ||
|
|
d1914c14b8 | ||
|
|
c2703ce7b6 | ||
|
|
47224ae4e6 | ||
|
|
413e76629d | ||
|
|
6625b1305d | ||
|
|
77578a4d61 | ||
|
|
2ce8445bdf | ||
|
|
22e73b5938 | ||
|
|
f338553518 | ||
|
|
2ca1146dfd | ||
|
|
e49c256d4a | ||
|
|
baf6a7af4f | ||
|
|
d2db6055ff | ||
|
|
9aebf8f59e | ||
|
|
e74d307e33 | ||
|
|
55c9c61f7e | ||
|
|
e749576e48 | ||
|
|
4a87a38546 | ||
|
|
d7c531ac59 | ||
|
|
b8cc1b68aa | ||
|
|
1cb9bf4ff5 |
19
.github/workflows/main.yml
vendored
Normal file
19
.github/workflows/main.yml
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
name: Workflow for Codecov Action
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- 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
|
||||
95
.gitignore
vendored
Normal file
95
.gitignore
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
### Node ###
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
# Runtime data
|
||||
pids
|
||||
*.pid
|
||||
*.seed
|
||||
*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
coverage
|
||||
*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# TypeScript v1 declaration files
|
||||
typings/
|
||||
|
||||
# TypeScript cache
|
||||
*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
.eslintcache
|
||||
|
||||
# Optional REPL history
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variables file
|
||||
.env
|
||||
.env.test
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
.cache
|
||||
|
||||
# next.js build output
|
||||
.next
|
||||
|
||||
# nuxt.js build output
|
||||
.nuxt
|
||||
|
||||
# react / gatsby
|
||||
public/
|
||||
|
||||
# vuepress build output
|
||||
.vuepress/dist
|
||||
|
||||
# Serverless directories
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
.dynamodb/
|
||||
|
||||
# macOS Finder metadata
|
||||
.DS_Store
|
||||
@@ -6,8 +6,8 @@ The following is a set of guidelines for contributing to this repository, which
|
||||
|
||||
## What does this repo do?
|
||||
|
||||
This repo is a GitHub Action, meaning it integrates with the GitHub Actions CI/CD pipeline. It's meant to take formatted reports with code coverage stats and upload them to codecov.io. What's essentially happening in the background is that Actions is spinning up a Linux Docker container with the contents of this repository. Inside that container, we then call a shell scipt that runs Codecov's Bash uploader.
|
||||
This repo is a GitHub Action, meaning it integrates with the GitHub Actions CI/CD pipeline. It's meant to take formatted reports with code coverage stats and upload them to codecov.io. Our Node action uses the Actions toolkit to make system calls that allow us to run Codecov's bash uploader inside of Node. Essentially what we're doing in this action is downloading Codecov's bash uploader script from codecov.io/bash, saving it as a file in the current directory, executing the file via `exec` calls, then removing the script from the current directory.
|
||||
|
||||
## PRs and Support
|
||||
## PRs, Issues, and Support
|
||||
|
||||
Feel free to clone, modify code and request a PR to this repository. All PRs will be reviewed by the Codecov team. If your PR has been sitting for a while or if you have any questions, ping us at support@codecov.io
|
||||
Feel free to clone, modify code and request a PR to this repository. All PRs and issues will be reviewed by the Codecov team. If your PR/issue has been sitting for a while or if you have any questions, ping us at support@codecov.io
|
||||
|
||||
10
Dockerfile
10
Dockerfile
@@ -1,10 +0,0 @@
|
||||
FROM alpine:3.10
|
||||
|
||||
WORKDIR /app
|
||||
COPY . /app
|
||||
|
||||
RUN apk add --no-cache curl bash git
|
||||
|
||||
RUN chmod +x /app/entrypoint.sh
|
||||
|
||||
ENTRYPOINT [ "/app/entrypoint.sh" ]
|
||||
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
|
||||
|
||||
75
README.md
75
README.md
@@ -1,21 +1,49 @@
|
||||
<!-- <p align="center"><img src="./codecov-logo.png" /></p> -->
|
||||
|
||||
# Codecov GitHub Action
|
||||
|
||||
[](https://github.com/marketplace/actions/codecov)
|
||||
### Easily upload coverage reports to Codecov from GitHub Actions
|
||||
|
||||
>The latest release of this Action adds support for tokenless uploads from GitHub Actions!
|
||||
|
||||
## Usage
|
||||
|
||||
To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number (`@v1` is recommended) as a `step` within your `workflow.yml` file.
|
||||
|
||||
If you have a *private repository*, this Action also requires you to [provide an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) from [codecov.io](https://www.codecov.io) (tip: in order to avoid exposing your token, store it as a `secret`). Optionally, you can choose to include up to four additional inputs to customize the upload context. **For public repositories, no token is needed**
|
||||
|
||||
Inside your `.github/workflows/workflow.yml` file:
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
- uses: actions/codecov-action@v0.3
|
||||
- uses: codecov/codecov-action@v1
|
||||
with:
|
||||
token: ${{secrets.CODECOV_TOKEN}} #for private repos
|
||||
file: ./coverage.xml #optional
|
||||
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)
|
||||
```
|
||||
>**Note**: This assumes that you've set your Codecov token inside settings > secrets as `CODECOV_TOKEN`. If not, you can get an upload token for your specific repo on codecov.io. A token is *not* required for public repositories.
|
||||
>**Note**: This assumes that you've set your Codecov token inside *Settings > Secrets* as `CODECOV_TOKEN`. If not, you can [get an upload token](https://docs.codecov.io/docs/frequently-asked-questions#section-where-is-the-repository-upload-token-found-) for your specific repo on [codecov.io](https://www.codecov.io). Keep in mind that secrets are *not* available to forks of repositories.
|
||||
|
||||
## Arguments
|
||||
|
||||
Codecov's Action currently supports five inputs from the user: `token`, `file`, `flags`,`name`, and `fail_ci_if_error`. These inputs, along with their descriptions and usage contexts, are listed in the table below:
|
||||
|
||||
>**Update**: We've removed the `yml` parameter with the latest release of this action. Please put your custom codecov yaml file at the root of the repo because other locations will no longer be supported in the future.
|
||||
|
||||
| Input | Description | Usage |
|
||||
| :---: | :---: | :---: |
|
||||
| `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
|
||||
|
||||
@@ -24,36 +52,41 @@ name: Example workflow for Codecov
|
||||
on: [push]
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
env:
|
||||
OS: ${{ matrix.os }}
|
||||
PYTHON: '3.7'
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@master
|
||||
with:
|
||||
version: 3.7
|
||||
|
||||
python-version: 3.7
|
||||
- name: Generate coverage report
|
||||
run: |
|
||||
pip install pytest
|
||||
pip install pytest-cov
|
||||
pytest --cov=./ --cov-report=xml
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v0.2
|
||||
uses: codecov/codecov-action@v1
|
||||
with:
|
||||
token: ${{secrets.CODECOV_TOKEN}}
|
||||
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
|
||||
|
||||
## Arguments
|
||||
|
||||
| Argument | Description |
|
||||
| :---: | :---: |
|
||||
| `token` | Used to authorize coverage report uploads |
|
||||
| `file` | Location of the coverage report |
|
||||
|
||||
Contributions are welcome! Check out the [Contribution Guide](CONTRIBUTING.md).
|
||||
|
||||
## License
|
||||
|
||||
The code in this project is released under the [MIT License](LICENSE)
|
||||
The code in this project is released under the [MIT License](LICENSE).
|
||||
|
||||
34
action.yml
34
action.yml
@@ -1,19 +1,37 @@
|
||||
name: 'Codecov'
|
||||
description: 'GitHub action that uploads coverage reports for your repository to codecov.io'
|
||||
author: 'Ibrahim Ali @ Codecov'
|
||||
description: 'GitHub Action that uploads coverage reports for your repository to codecov.io'
|
||||
author: 'Ibrahim Ali <@ibrahim0814> | Codecov'
|
||||
inputs:
|
||||
name:
|
||||
description: 'User defined upload name. Visible in Codecov UI'
|
||||
required: false
|
||||
token:
|
||||
description: 'Set the repository token'
|
||||
description: 'Repository upload token - get it from codecov.io. Required only for private repositories'
|
||||
required: false
|
||||
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
|
||||
fail_ci_if_error:
|
||||
description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload'
|
||||
required: false
|
||||
branding:
|
||||
color: 'red'
|
||||
icon: 'umbrella'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
args:
|
||||
- ${{ inputs.token }}
|
||||
- ${{ inputs.file }}
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
||||
54232
dist/index.js
vendored
Normal file
54232
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
if [ $# -eq 0 ]
|
||||
then
|
||||
bash <(curl -s https://codecov.io/bash)
|
||||
elif [ "x$INPUT_TOKEN" != "x" ] && [ "x$INPUT_FILE" != "x" ]
|
||||
then
|
||||
bash <(curl -s https://codecov.io/bash) -t $INPUT_TOKEN -f $INPUT_FILE
|
||||
elif [ "x$INPUT_TOKEN" != "x" ]
|
||||
then
|
||||
bash <(curl -s https://codecov.io/bash) -t $INPUT_TOKEN
|
||||
elif [ "x$INPUT_FILE" != "x" ]
|
||||
then
|
||||
bash <(curl -s https://codecov.io/bash) -f $INPUT_FILE
|
||||
fi
|
||||
|
||||
163
index.js
Normal file
163
index.js
Normal file
@@ -0,0 +1,163 @@
|
||||
const core = require("@actions/core");
|
||||
const exec = require("@actions/exec");
|
||||
const fs = require("fs");
|
||||
const request = require('requestretry');
|
||||
|
||||
let fail_ci;
|
||||
try {
|
||||
const name = core.getInput("name");
|
||||
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();
|
||||
|
||||
if (
|
||||
fail_ci === "yes" ||
|
||||
fail_ci === "y" ||
|
||||
fail_ci === "true" ||
|
||||
fail_ci === "t" ||
|
||||
fail_ci === "1"
|
||||
) {
|
||||
fail_ci = true;
|
||||
} else {
|
||||
fail_ci = false;
|
||||
}
|
||||
|
||||
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}`);
|
||||
}
|
||||
|
||||
fs.writeFile("codecov.sh", body, err => {
|
||||
if (err && fail_ci) {
|
||||
throw err;
|
||||
} else if (err) {
|
||||
core.warning(`Codecov warning: ${err.message}`);
|
||||
}
|
||||
|
||||
let output = "";
|
||||
let execError = "";
|
||||
const options = {};
|
||||
options.listeners = {
|
||||
stdout: data => {
|
||||
output += data.toString();
|
||||
},
|
||||
stderr: data => {
|
||||
execError += data.toString();
|
||||
}
|
||||
};
|
||||
|
||||
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 || ''
|
||||
});
|
||||
|
||||
if(token){
|
||||
options.env.CODECOV_TOKEN = token
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
const execArgs = ["codecov.sh"];
|
||||
if (file) {
|
||||
execArgs.push(
|
||||
"-f", `${file}`
|
||||
);
|
||||
}
|
||||
|
||||
if (files) {
|
||||
files.split(',').forEach(f => {
|
||||
execArgs.push(
|
||||
"-f", `${f}`
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
core.setFailed(`Codecov failed with the following error: ${error.message}`);
|
||||
} else {
|
||||
core.warning(`Codecov warning: ${error.message}`);
|
||||
}
|
||||
}
|
||||
4
jest.config.js
Normal file
4
jest.config.js
Normal file
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
preset: 'ts-jest',
|
||||
testEnvironment: 'node',
|
||||
}
|
||||
5257
package-lock.json
generated
Normal file
5257
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
39
package.json
Normal file
39
package.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "codecov-action",
|
||||
"version": "1.0.12",
|
||||
"description": "Upload coverage reports to Codecov from GitHub Actions",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"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": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/codecov/codecov-action.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "Ibrahim Ali",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/codecov/codecov-action/issues"
|
||||
},
|
||||
"homepage": "https://github.com/codecov/codecov-action#readme",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/exec": "^1.0.1",
|
||||
"@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",
|
||||
"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