Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add in all the extra arguments for uploader #955

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ steps:
- uses: actions/checkout@master
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change? Is it now required for public repos?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@3flex this is not a breaking change, but we do suggest using the token when possible to prevent flakiness when hitting the GitHub API

token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage1.xml,./coverage2.xml # optional
flags: unittests # optional
name: codecov-umbrella # optional
Expand All @@ -50,35 +50,43 @@ Codecov's Action supports inputs from the user. These inputs, along with their d

| Input | Description | Usage |
| :---: | :---: | :---: |
| `token` | Used to authorize coverage report uploads | *Required for private repos* |
| `files` | Comma-separated paths to the coverage report(s). Negated paths are supported by starting with `!` | Optional
| `directory` | Directory to search for coverage reports. | Optional
| `dry_run` | Don't upload files to Codecov | Optional
| `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional
| `token` | Used to authorize coverage report uploads | *Required |
| `move_coverage_to_trash` | Move discovered coverage reports to the trash | Optional
| `commit_parent` | The commit SHA of the parent for which you are uploading coverage. If not present, the parent will be determined using the API of your repository provider. When using the repository provider's API, the parent is determined via finding the closest ancestor to the commit. | Optional
| `dry_run` | Don't upload files to Codecov | Optional
| `env_vars` | Environment variables to tag the upload with. Multiple env variables can be separated with commas (e.g. `OS,PYTHON`) | Optional
| `fail_ci_if_error` | Specify if CI pipeline should fail when Codecov runs into errors during upload. *Defaults to **false*** | Optional
| `files` | Comma-separated paths to the coverage report(s). Negated paths are supported by starting with `!` | Optional
| `flags` | Flag the upload to group coverage metrics (unittests, uitests, etc.). Multiple flags are separated by a comma (ui,chrome) | Optional
| `full_report` | Specify the path of a full Codecov report to re-upload | Optional
| `functionalities` | Toggle functionalities | Optional
| `network` | Disable uploading the file network | Optional
| -- `network` | Disable uploading the file network | Optional
| -- `fixes` | Enable file fixes to ignore common lines from coverage | Optional
| -- `search` | Disable searching for coverage files | Optional
| `gcov` | Run with gcov support | Optional
| `gcov_args` | Extra arguments to pass to gcov | Optional
| `gcov_ignore` | Paths to ignore during gcov gathering | Optional
| `gcov_include` | Paths to include during gcov gathering | Optional
| `move_coverage_to_trash` | Move discovered coverage reports to the trash | Optional
| `gcov_executable` | gcov executable to run. Defaults to gcov. | Optional
| `name` | Custom defined name for the upload | Optional
| `network_filer` | Specify a filter on the files listed in the network section of the Codecov report. Useful for upload-specific path fixing | Optional
| `network_prefix` | Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing | Optional
| `os` | Specify the OS (linux, macos, windows, alpine) | Optional
| `override_branch` | Specify the branch name | Optional
| `override_build` | Specify the build number | Optional
| `override_commit` | Specify the commit SHA | Optional
| `override_pr` | Specify the pull request number | Optional
| `override_tag` | Specify the git tag | Optional
| `root_dir` | Used when not in git/hg project to identify project root directory | Optional
| `directory` | Directory to search for coverage reports. | Optional
| `slug` | Specify the slug manually (Enterprise use) | Optional
| `swift` | Run with swift coverage support | Optional
| -- `swift_project` | Specify the swift project to speed up coverage conversion | Optional
| `upstream_proxy` | The upstream http proxy server to connect through | Optional
| `url` | Change the upload host (Enterprise use) | Optional
| `verbose` | Specify whether the Codecov output should be verbose | Optional
| `version` | Specify which version of the Codecov Uploader should be used. Defaults to `latest` | Optional
| `working-directory` | Directory in which to execute `codecov.sh` | Optional
| `xcode` | Run with xcode support | Optional
| `xcode_archive_path` | Specify the xcode archive path. Likely specified as the -resultBundlePath and should end in .xcresult | Optional
| `xtra_args` | Add additional uploader args that may be missing in the Action | Optional


### Example `workflow.yml` with Codecov Action
Expand All @@ -94,13 +102,13 @@ jobs:
os: [ubuntu-latest, macos-latest, windows-latest]
env:
OS: ${{ matrix.os }}
PYTHON: '3.7'
PYTHON: '3.10'
steps:
- uses: actions/checkout@master
- name: Setup Python
uses: actions/setup-python@master
with:
python-version: 3.7
python-version: 3.10
- name: Generate coverage report
run: |
pip install pytest
Expand Down
5,823 changes: 2,950 additions & 2,873 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

33 changes: 27 additions & 6 deletions src/buildExec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,32 @@ test('all arguments', () => {
'flags': 'test,test2',
'functionalities':
'network',
'full_report': 'oldDir/oldReport.json',
'gcov': 'true',
'gcov_args': '-v',
'gcov_ignore': '*.fake',
'gcov_include': 'real_file',
'gcov_executable': 'gcov2',
'move_coverage_to_trash': 'true',
'name': 'codecov',
'network_filter': 'src/',
'network_prefix': 'build/',
'override_branch': 'thomasrockhu/test',
'override_build': '1',
'override_commit': '9caabca5474b49de74ef5667deabaf74cdacc244',
'override_pr': '2',
'override_tag': 'v1.2',
'root_dir': 'root/',
'swift': 'true',
'swift_project': 'MyApp',
'slug': 'fakeOwner/fakeRepo',
'token': 'd3859757-ab80-4664-924d-aef22fa7557b',
'upstream_proxy': 'https://codecov.example.com',
'url': 'https://codecov.enterprise.com',
'verbose': 't',
'working-directory': 'src',
'xcode': 'true',
'xcode_archive_path': '/test.xcresult',
'xtra_args': '-some -other -args',
};

for (const env of Object.keys(envs)) {
Expand Down Expand Up @@ -81,17 +88,25 @@ test('all arguments', () => {
'dir1/coverage.xml',
'-f',
'dir2/coverage.xml',
'-full',
'oldDir/oldReport.json',
'-F',
'test',
'-F',
'test2',
'-g',
'--gcovArgs',
'-gcovArgs',
'-v',
'--gcovIgnore',
'-gcovIgnore',
'*.fake',
'--gcovInclude',
'-gcovInclude',
'real_file',
'-gcovExecutable',
'gcov2',
'-networkFilter',
'src/',
'-networkPrefix',
'build/',
'-B',
'thomasrockhu/test',
'-b',
Expand All @@ -108,12 +123,18 @@ test('all arguments', () => {
'coverage/',
'-r',
'fakeOwner/fakeRepo',
'-xs',
'-xsp',
'MyApp',
'-U',
'https://codecov.example.com',
'-u',
'https://codecov.enterprise.com',
'-v',
'--xc',
'--xp',
'-xc',
'-xp',
'/test.xcresult',
'-some -other -args',
]);
expect(failCi).toBeTruthy();

Expand Down
54 changes: 42 additions & 12 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ const isTrue = (variable) => {
const buildExec = () => {
const clean = core.getInput('move_coverage_to_trash');
const commitParent = core.getInput('commit_parent');
const envVars = core.getInput('env_vars');
const dryRun = isTrue(core.getInput('dry_run'));
const envVars = core.getInput('env_vars');
const failCi = isTrue(core.getInput('fail_ci_if_error'));
const file = core.getInput('file');
const files = core.getInput('files');
const flags = core.getInput('flags');
const fullReport = core.getInput('full_report');
const functionalities = core.getInput('functionalities');
const gcov = core.getInput('gcov');
const gcovArgs = core.getInput('gcov_args');
const gcovExecutable = core.getInput('gcov_executable');
const gcovIgnore = core.getInput('gcov_ignore');
const gcovInclude = core.getInput('gcov_include');
const functionalities = core.getInput('functionalities');
const name = core.getInput('name');
const networkFilter = core.getInput('network_filter');
const networkPrefix = core.getInput('network_prefix');
const os = core.getInput('os');
const overrideBranch = core.getInput('override_branch');
const overrideBuild = core.getInput('override_build');
Expand All @@ -40,13 +44,16 @@ const buildExec = () => {
const rootDir = core.getInput('root_dir');
const searchDir = core.getInput('directory');
const slug = core.getInput('slug');
const swift = core.getInput('swift');
const swiftProject = core.getInput('swift_project');
const token = core.getInput('token');
let uploaderVersion = core.getInput('version');
const upstream = core.getInput('upstream_proxy');
const url = core.getInput('url');
const verbose = isTrue(core.getInput('verbose'));
const workingDir = core.getInput('working-directory');
const xcode = core.getInput('xcode');
const xcodeArchivePath = core.getInput('xcode_archive_path');
const xtraArgs = core.getInput('xtra_args');
let uploaderVersion = core.getInput('version');

const execArgs = [];
execArgs.push(
Expand Down Expand Up @@ -106,6 +113,9 @@ const buildExec = () => {
execArgs.push('-f', `${f}`);
});
}
if (fullReport) {
execArgs.push('-full', `${fullReport}`);
}
if (flags) {
flags.split(',').map((f) => f.trim()).forEach((f) => {
execArgs.push('-F', `${f}`);
Expand All @@ -116,13 +126,23 @@ const buildExec = () => {
execArgs.push('-g');
}
if (gcovArgs) {
execArgs.push('--gcovArgs', `${gcovArgs}`);
execArgs.push('-gcovArgs', `${gcovArgs}`);
}
if (gcovIgnore) {
execArgs.push('--gcovIgnore', `${gcovIgnore}`);
execArgs.push('-gcovIgnore', `${gcovIgnore}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is incorrect and causes files/directories listed in gcov_ignore to be included (i.e. the whole option is ignored since version 3.1.2).

Only short CLI option names can be specified with a single dash (-) instead of 2 (--), see:
https://github.com/codecov/uploader/blob/cb97e5f75b4bba3afed0b07380d5ab29c34d66be/HELPFILE#L40-L42
https://github.com/codecov/uploader/blob/cb97e5f75b4bba3afed0b07380d5ab29c34d66be/src/helpers/cli.ts#L80-L97

So to fix this, one must specify -gi or --gcovIgnore here.

FWIW, -gcovArgs, -gcovInclude, -gcovExecutable, -networkFilter, -networkPrefix are probably having the same issue.

Copy link
Contributor

@kleisauke kleisauke Apr 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So to fix this, one must specify -gi or --gcovIgnore here.

Ah, -gi is also invalid, a single dash is only valid for single character aliases, see:
yargs/yargs#1781 (comment)

So, this issue affects the following settings:

  • full_report, uses -full, needs to be changed to --full or --fullReport;
  • gcov_args, uses -gcovArgs, needs to be changed to --ga or --gcovArgs;
  • gcov_ignore, uses -gcovIgnore, needs to be changed to --gi or --gcovIgnore;
  • gcov_include, uses -gcovInclude, needs to be changed to --gI or --gcovInclude;
  • gcov_executable, uses -gcovExecutable, needs to be changed to --gx or --gcovExecutable;
  • network_filter, uses -networkFilter, needs to be changed to -i or --networkFilter;
  • networkPrefix, uses -networkPrefix, needs to be changed to -k or --networkPrefix;
  • swift, uses -xs, needs to be changed to --xs or --swift;
  • swift_project, uses -xsp, needs to be changed to --xsp or --swiftProject;
  • xcode, uses -xc, needs to be changed to --xc or --xcode;
  • xcode, uses -xp, needs to be changed to --xp or --xcodeArchivePath.

I just opened PR #969 for this.

}
if (gcovInclude) {
execArgs.push('--gcovInclude', `${gcovInclude}`);
execArgs.push('-gcovInclude', `${gcovInclude}`);
}
if (gcovExecutable) {
execArgs.push('-gcovExecutable', `${gcovExecutable}`);
}

if (networkFilter) {
execArgs.push('-networkFilter', `${networkFilter}`);
}
if (networkPrefix) {
execArgs.push('-networkPrefix', `${networkPrefix}`);
}

if (overrideBranch) {
Expand Down Expand Up @@ -158,18 +178,24 @@ const buildExec = () => {
if (slug) {
execArgs.push('-r', `${slug}`);
}
if (swift) {
execArgs.push('-xs');
}
if (swift && swiftProject) {
execArgs.push('-xsp', `${swiftProject}`);
}
if (upstream) {
execArgs.push('-U', `${upstream}`);
}
if (url) {
execArgs.push('-u', `${url}`);
}
if (verbose) {
execArgs.push('-v');
}
if (workingDir) {
options.cwd = workingDir;
}
if (xcode && xcodeArchivePath) {
execArgs.push('--xc');
execArgs.push('--xp', `${xcodeArchivePath}`);
execArgs.push('-xc');
execArgs.push('-xp', `${xcodeArchivePath}`);
}

if (uploaderVersion == '') {
Expand All @@ -180,6 +206,10 @@ const buildExec = () => {
console.debug({execArgs});
}

if (xtraArgs) {
execArgs.push(`${xtraArgs}`);
}

return {execArgs, options, failCi, os, uploaderVersion, verbose};
};

Expand Down