Compare commits

..

4 Commits

Author SHA1 Message Date
Tom Hu
ab904c41d6 chore(release): bump to 3.1.6 2024-01-30 11:17:54 -08:00
Tom Hu
a8c374ae46 Revert "action.yml: Update to Node.js 20 (#1228)"
This reverts commit 9140fdcf54.
2024-01-30 11:17:26 -08:00
Tom Hu
4fe8c5f003 chore(release): bump to 3.1.5 2024-01-25 10:44:09 -08:00
Robin Hallabro-Kokko
9140fdcf54 action.yml: Update to Node.js 20 (#1228)
Node.js 16 actions are deprecated.

This should suppress the deprecation notice: Please update the following actions to use Node.js 20: codecov/codecov-action@v3
2024-01-25 10:41:05 -08:00
15 changed files with 8313 additions and 3630 deletions

View File

@@ -37,11 +37,11 @@ jobs:
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4.0.0 uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning. # Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v2.21.7 uses: github/codeql-action/init@v2
with: with:
languages: ${{ matrix.language }} languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file. # If you wish to specify custom queries, you can do so here or in a config file.
@@ -52,7 +52,7 @@ jobs:
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below) # If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v2.21.7 uses: github/codeql-action/autobuild@v2
# Command-line programs to run using the OS shell. # Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl # 📚 https://git.io/JvXDl
@@ -66,4 +66,4 @@ jobs:
# make release # make release
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2.21.7 uses: github/codeql-action/analyze@v2

View File

@@ -8,7 +8,7 @@ jobs:
os: [macos-latest, windows-latest, ubuntu-latest] os: [macos-latest, windows-latest, ubuntu-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4.0.0 uses: actions/checkout@v3
- name: Upload coverage to Codecov (script) - name: Upload coverage to Codecov (script)
uses: ./ uses: ./
with: with:
@@ -16,7 +16,6 @@ jobs:
flags: script,${{ matrix.os }} flags: script,${{ matrix.os }}
name: codecov-script name: codecov-script
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov (demo) - name: Upload coverage to Codecov (demo)
uses: ./ uses: ./
with: with:
@@ -25,7 +24,6 @@ jobs:
flags: demo,${{ matrix.os }} flags: demo,${{ matrix.os }}
name: codecov-demo name: codecov-demo
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov (version) - name: Upload coverage to Codecov (version)
uses: ./ uses: ./
with: with:
@@ -33,9 +31,8 @@ jobs:
file: ./coverage/coverage-final.json file: ./coverage/coverage-final.json
flags: version,${{ matrix.os }} flags: version,${{ matrix.os }}
name: codecov-version name: codecov-version
version: v0.2.0 version: v0.1.0_8880
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
run: run:
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
strategy: strategy:
@@ -43,7 +40,7 @@ jobs:
os: [macos-latest, windows-latest, ubuntu-latest] os: [macos-latest, windows-latest, ubuntu-latest]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4.0.0 uses: actions/checkout@v3
- name: Install dependencies - name: Install dependencies
run: npm install run: npm install
- name: Lint - name: Lint
@@ -57,7 +54,6 @@ jobs:
flags: script,${{ matrix.os }} flags: script,${{ matrix.os }}
name: codecov-script name: codecov-script
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov (demo) - name: Upload coverage to Codecov (demo)
uses: ./ uses: ./
with: with:
@@ -66,7 +62,6 @@ jobs:
flags: demo,${{ matrix.os }} flags: demo,${{ matrix.os }}
name: codecov-demo name: codecov-demo
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload coverage to Codecov (version) - name: Upload coverage to Codecov (version)
uses: ./ uses: ./
with: with:
@@ -74,6 +69,5 @@ jobs:
file: ./coverage/coverage-final.json file: ./coverage/coverage-final.json
flags: version,${{ matrix.os }} flags: version,${{ matrix.os }}
name: codecov-version name: codecov-version
version: v0.2.0 version: v0.1.0_8880
verbose: true verbose: true
token: ${{ secrets.CODECOV_TOKEN }}

View File

@@ -24,12 +24,12 @@ jobs:
steps: steps:
- name: "Checkout code" - name: "Checkout code"
uses: actions/checkout@v4.0.0 # v3.0.0 uses: actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # v3.0.0
with: with:
persist-credentials: false persist-credentials: false
- name: "Run analysis" - name: "Run analysis"
uses: ossf/scorecard-action@08b4669551908b1024bb425080c797723083c031 # v2.2.0 uses: ossf/scorecard-action@80e868c13c90f172d68d1f4501dee99e2479f7af # v2.1.3
with: with:
results_file: results.sarif results_file: results.sarif
results_format: sarif results_format: sarif
@@ -48,7 +48,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF # Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab. # format to the repository Actions tab.
- name: "Upload artifact" - name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3 uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with: with:
name: SARIF file name: SARIF file
path: results.sarif path: results.sarif
@@ -56,6 +56,6 @@ jobs:
# Upload the results to GitHub's code scanning dashboard. # Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning" - name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@v2.21.7 # v1.0.26 uses: github/codeql-action/upload-sarif@5f532563584d71fdef14ee64d17bafb34f751ce5 # v1.0.26
with: with:
sarif_file: results.sarif sarif_file: results.sarif

View File

@@ -1,16 +1,3 @@
## 4.0.0-beta.2
### Fixes
- #1085 not adding -n if empty to do-upload command
## 4.0.0-beta.1
`v4` represents a move from the [universal uploader](https://github.com/codecov/uploader) to the [Codecov CLI](https://github.com/codecov/codecov-cli). Although this will unlock new features for our users, the CLI is not yet at feature parity with the universal uploader.
### Breaking Changes
- No current support for `aarch64` and `alpine` architectures.
- Tokenless uploading is unsuported
- Various arguments to the Action have been removed
## 3.1.4 ## 3.1.4
### Fixes ### Fixes
- #967 Fix typo in README.md - #967 Fix typo in README.md

View File

@@ -5,15 +5,7 @@
[![Workflow for Codecov Action](https://github.com/codecov/codecov-action/actions/workflows/main.yml/badge.svg)](https://github.com/codecov/codecov-action/actions/workflows/main.yml) [![Workflow for Codecov Action](https://github.com/codecov/codecov-action/actions/workflows/main.yml/badge.svg)](https://github.com/codecov/codecov-action/actions/workflows/main.yml)
### Easily upload coverage reports to Codecov from GitHub Actions ### Easily upload coverage reports to Codecov from GitHub Actions
## v4 Beta Release >The latest release of this Action adds support for tokenless uploads from GitHub Actions!
`v4` of the Codecov GitHub Action will use the [Codecov CLI](https://github.com/codecov/codecov-cli) to upload coverage reports to Codecov. Currently, `v4` is in beta.
Breaking Changes
- No current support for `aarch64` and `alpine` architectures.
- Tokenless uploading is unsupported
- Various arguments to the Action have been removed
`v3` versions and below will not have access to CLI features (e.g. global upload token).
## ⚠️ Deprecation of v1 ## ⚠️ Deprecation of v1
**As of February 1, 2022, v1 has been fully sunset and no longer functions** **As of February 1, 2022, v1 has been fully sunset and no longer functions**
@@ -24,6 +16,12 @@ more about our deprecation plan and the new uploader on our [blog](https://about
We will be restricting any updates to the `v1` Action to security updates and hotfixes. We will be restricting any updates to the `v1` Action to security updates and hotfixes.
### Migration from `v1` to `v3`
The `v3` uploader has a few breaking changes for users
- Multiple fields have not been transferred from the bash uploader or have been deprecated. Notably
many of the `functionalities` and `gcov_` arguments have been removed. Please check the documentation
below for the full list.
## Usage ## Usage
To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number (`@v3` is recommended) as a `step` within your `workflow.yml` file. To integrate Codecov with your Actions pipeline, specify the name of this repository with a tag number (`@v3` is recommended) as a `step` within your `workflow.yml` file.

View File

@@ -17,6 +17,12 @@ inputs:
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
full_report:
description: Specify the path of a full Codecov report to re-upload
required: false
commit_parent:
description: '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 providers API, the parent is determined via finding the closest ancestor to the commit.'
required: false
dry_run: dry_run:
description: "Don't upload files to Codecov" description: "Don't upload files to Codecov"
required: false required: false
@@ -26,14 +32,38 @@ inputs:
fail_ci_if_error: fail_ci_if_error:
description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload' description: 'Specify whether or not CI build should fail if Codecov runs into an error during upload'
required: false required: false
functionalities:
description: 'Comma-separated list, see the README for options and their usage. Options include `network`, `fixes`, `search`.'
required: false
gcov: gcov:
description: 'Run with gcov support' description: 'Run with gcov support'
required: false required: false
gcov_args:
description: 'Extra arguments to pass to gcov'
required: false
gcov_executable:
description: 'gcov executable to run. Defaults to gcov'
required: false
gcov_ignore:
description: 'Paths to ignore during gcov gathering'
required: false
gcov_include:
description: 'Paths to include during gcov gathering'
required: false
move_coverage_to_trash:
description: 'Move discovered coverage reports to the trash'
required: false
name: name:
description: 'User defined upload name. Visible in Codecov UI' description: 'User defined upload name. Visible in Codecov UI'
required: false required: false
network_filter:
description: 'Specify a filter on the files listed in the network section of the Codecov report. Useful for upload-specific path fixing'
required: false
network_prefix:
description: 'Specify a prefix on files listed in the network section of the Codecov report. Useful to help resolve path fixing'
required: false
os: os:
description: 'Override the assumed OS. Options are linux | macos | windows.' description: 'Override the assumed OS. Options are aarch64 | alpine | linux | macos | windows.'
required: false required: false
override_branch: override_branch:
description: 'Specify the branch name' description: 'Specify the branch name'
@@ -47,8 +77,8 @@ inputs:
override_pr: override_pr:
description: 'Specify the pull request number' description: 'Specify the pull request number'
required: false required: false
plugins: override_tag:
description: 'Comma-separated list of plugins for use during upload.' description: 'Specify the git tag'
required: false required: false
root_dir: root_dir:
description: 'Used when not in git/hg project to identify project root directory' description: 'Used when not in git/hg project to identify project root directory'
@@ -56,15 +86,36 @@ inputs:
slug: slug:
description: 'Specify the slug manually (Enterprise use)' description: 'Specify the slug manually (Enterprise use)'
required: false required: false
swift:
description: 'Run with swift coverage support'
required: false
swift_project:
description: 'Specify the swift project to speed up coverage conversion'
required: false
upstream_proxy:
description: 'The upstream http proxy server to connect through'
required: false
url:
description: 'Change the upload host (Enterprise use)'
required: false
verbose: verbose:
description: 'Specify whether the Codecov output should be verbose' description: 'Specify whether the Codecov output should be verbose'
required: false required: false
version: version:
description: 'Specify which version of the Codecov CLI should be used. Defaults to `latest`' description: 'Specify which version of the Codecov Uploader should be used. Defaults to `latest`'
required: false required: false
working-directory: working-directory:
description: 'Directory in which to execute codecov.sh' description: 'Directory in which to execute codecov.sh'
required: false required: false
xcode:
description: 'Run with xcode support'
required: false
xcode_archive_path:
description: 'Specify the xcode archive path. Likely specified as the -resultBundlePath and should end in .xcresult'
required: false
xtra_args:
description: 'Add additional uploader args that may be missing in the Action'
required: false
branding: branding:
color: 'red' color: 'red'
icon: 'umbrella' icon: 'umbrella'

301
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

10779
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "codecov-action", "name": "codecov-action",
"version": "4.0.0-beta.3", "version": "3.1.6",
"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": {
@@ -23,23 +23,23 @@
}, },
"homepage": "https://github.com/codecov/codecov-action#readme", "homepage": "https://github.com/codecov/codecov-action#readme",
"dependencies": { "dependencies": {
"@actions/core": "^1.10.1", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.1", "@actions/exec": "^1.1.1",
"@actions/github": "^5.1.1", "@actions/github": "^5.1.1",
"node-fetch": "^3.3.2", "node-fetch": "^3.3.1",
"openpgp": "5.10" "openpgp": "5.8"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^29.5.5", "@types/jest": "^27.5.0",
"@types/node": "^20.6.3", "@types/node": "^20.1.4",
"@typescript-eslint/eslint-plugin": "^6.7.2", "@typescript-eslint/eslint-plugin": "^4.29.2",
"@typescript-eslint/parser": "^6.7.2", "@typescript-eslint/parser": "^4.29.2",
"@vercel/ncc": "^0.38.0", "@vercel/ncc": "^0.36.1",
"eslint": "^8.49.0", "eslint": "^7.32.0",
"eslint-config-google": "^0.14.0", "eslint-config-google": "^0.14.0",
"jest": "^29.7.0", "jest": "^26.6.3",
"jest-junit": "^16.0.0", "jest-junit": "^16.0.0",
"ts-jest": "^29.1.1", "ts-jest": "^26.5.6",
"typescript": "^5.2.0" "typescript": "^4.9.5"
} }
} }

View File

@@ -1,55 +1,31 @@
import * as github from '@actions/github'; import * as github from '@actions/github';
import { import buildExec from './buildExec';
buildCommitExec,
buildGeneralExec,
buildReportExec,
buildUploadExec,
} from './buildExec';
/* eslint-disable @typescript-eslint/no-var-requires */
const {version} = require('../package.json');
const context = github.context; const context = github.context;
test('general args', () => { test('no arguments', () => {
const envs = { const {execArgs, failCi} = buildExec();
url: 'https://codecov.enterprise.com',
verbose: 't',
};
for (const env of Object.keys(envs)) {
process.env['INPUT_' + env.toUpperCase()] = envs[env];
}
const {args, verbose} = buildGeneralExec(); const args = [
'-n',
expect(args).toEqual( '',
expect.arrayContaining([ '-Q',
'--enterprise-url', `github-action-${version}`,
'https://codecov.enterprise.com', ];
'-v',
]));
expect(verbose).toBeTruthy();
for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()];
}
});
test('upload args using context', () => {
const expectedArgs = [];
const {uploadExecArgs, uploadCommand} = buildUploadExec();
if (context.eventName == 'pull_request') { if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`); args.push('-C', `${context.payload.pull_request.head.sha}`);
} }
if (context.eventName == 'pull_request_target') { expect(execArgs).toEqual(args);
expectedArgs.push('-P', `${context.payload.number}`); expect(failCi).toBeFalsy();
}
expect(uploadExecArgs).toEqual(expectedArgs);
expect(uploadCommand).toEqual('do-upload');
}); });
test('upload args', () => { test('all arguments', () => {
const envs = { const envs = {
'commit_parent': '83231650328f11695dfb754ca0f540516f188d27',
'directory': 'coverage/', 'directory': 'coverage/',
'dry_run': 'true', 'dry_run': 'true',
'env_vars': 'OS,PYTHON', 'env_vars': 'OS,PYTHON',
@@ -57,30 +33,53 @@ test('upload args', () => {
'file': 'coverage.xml', 'file': 'coverage.xml',
'files': 'dir1/coverage.xml,dir2/coverage.xml', 'files': 'dir1/coverage.xml,dir2/coverage.xml',
'flags': 'test,test2', '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', 'name': 'codecov',
'network_filter': 'src/',
'network_prefix': 'build/',
'override_branch': 'thomasrockhu/test', 'override_branch': 'thomasrockhu/test',
'override_build': '1', 'override_build': '1',
'override_commit': '9caabca5474b49de74ef5667deabaf74cdacc244', 'override_commit': '9caabca5474b49de74ef5667deabaf74cdacc244',
'override_pr': '2', 'override_pr': '2',
'plugins': 'pycoverage,compress-pycoverage', 'override_tag': 'v1.2',
'root_dir': 'root/', 'root_dir': 'root/',
'swift': 'true',
'swift_project': 'MyApp',
'slug': 'fakeOwner/fakeRepo', 'slug': 'fakeOwner/fakeRepo',
'token': 'd3859757-ab80-4664-924d-aef22fa7557b', 'token': 'd3859757-ab80-4664-924d-aef22fa7557b',
'working-directory': 'src', 'upstream_proxy': 'https://codecov.example.com',
'plugin': 'xcode', 'url': 'https://codecov.enterprise.com',
'exclude': 'src', 'verbose': 't',
'xcode': 'true',
'xcode_archive_path': '/test.xcresult',
'xtra_args': '--some --other --args',
}; };
for (const env of Object.keys(envs)) { for (const env of Object.keys(envs)) {
process.env['INPUT_' + env.toUpperCase()] = envs[env]; process.env['INPUT_' + env.toUpperCase()] = envs[env];
} }
const {uploadExecArgs, uploadCommand} = buildUploadExec(); const {execArgs, failCi} = buildExec();
const expectedArgs = [ expect(execArgs).toEqual([
'-n', '-n',
'codecov', 'codecov',
'-Q',
`github-action-${version}`,
'-c',
'-N',
'83231650328f11695dfb754ca0f540516f188d27',
'-d', '-d',
'-e', '-e',
'OS,PYTHON', 'OS,PYTHON',
'-X',
'network',
'-Z', '-Z',
'-f', '-f',
'coverage.xml', 'coverage.xml',
@@ -88,10 +87,25 @@ test('upload args', () => {
'dir1/coverage.xml', 'dir1/coverage.xml',
'-f', '-f',
'dir2/coverage.xml', 'dir2/coverage.xml',
'--full',
'oldDir/oldReport.json',
'-F', '-F',
'test', 'test',
'-F', '-F',
'test2', 'test2',
'-g',
'--ga',
'-v',
'--gi',
'*.fake',
'--gI',
'real_file',
'--gx',
'gcov2',
'-i',
'src/',
'-k',
'build/',
'-B', '-B',
'thomasrockhu/test', 'thomasrockhu/test',
'-b', '-b',
@@ -100,123 +114,111 @@ test('upload args', () => {
'9caabca5474b49de74ef5667deabaf74cdacc244', '9caabca5474b49de74ef5667deabaf74cdacc244',
'-P', '-P',
'2', '2',
'--plugin', '-T',
'pycoverage', 'v1.2',
'--plugin', '-R',
'compress-pycoverage',
'--network-root-folder',
'root/', 'root/',
'-s', '-s',
'coverage/', 'coverage/',
'-r', '-r',
'fakeOwner/fakeRepo', 'fakeOwner/fakeRepo',
'--plugin', '--xs',
'xcode', '--xsp',
'--exclude', 'MyApp',
'src', '-U',
'https://codecov.example.com',
'-u',
'https://codecov.enterprise.com',
'-v',
'--xc',
'--xp',
'/test.xcresult',
'--some --other --args',
]);
expect(failCi).toBeTruthy();
for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()];
}
});
describe('trim arguments after splitting them', () => {
const baseExpectation = [
'-n',
expect.stringContaining(''),
'-Q',
expect.stringContaining('github-action'),
]; ];
expect(uploadExecArgs).toEqual(expectedArgs); test('files', () => {
expect(uploadCommand).toEqual('do-upload'); const envs = {'files': './client-coverage.txt, ./lcov.info'};
for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()]; for (const [name, value] of Object.entries(envs)) {
} process.env['INPUT_' + name.toUpperCase()] = value;
}); }
const {execArgs} = buildExec();
test('report args', () => {
const envs = { expect(execArgs).toEqual(
override_commit: '9caabca5474b49de74ef5667deabaf74cdacc244', expect.arrayContaining([
slug: 'fakeOwner/fakeRepo', ...baseExpectation,
token: 'd3859757-ab80-4664-924d-aef22fa7557b', '-f',
}; './client-coverage.txt',
for (const env of Object.keys(envs)) { '-f',
process.env['INPUT_' + env.toUpperCase()] = envs[env]; './lcov.info',
} ]),
);
const {reportExecArgs, reportCommand} = buildReportExec();
for (const env of Object.keys(envs)) {
expect(reportExecArgs).toEqual( delete process.env['INPUT_' + env.toUpperCase()];
expect.arrayContaining([ }
'-C', });
'9caabca5474b49de74ef5667deabaf74cdacc244',
'--slug', test('flags', () => {
'fakeOwner/fakeRepo', const envs = {'flags': 'ios, mobile'};
]));
expect(reportCommand).toEqual('create-report'); for (const [name, value] of Object.entries(envs)) {
for (const env of Object.keys(envs)) { process.env['INPUT_' + name.toUpperCase()] = value;
delete process.env['INPUT_' + env.toUpperCase()]; }
}
}); const {execArgs} = buildExec();
expect(execArgs).toEqual(
test('report args using context', () => { expect.arrayContaining([
const envs = { ...baseExpectation,
token: 'd3859757-ab80-4664-924d-aef22fa7557b', '-F',
}; 'ios',
for (const env of Object.keys(envs)) { '-F',
process.env['INPUT_' + env.toUpperCase()] = envs[env]; 'mobile',
} ]),
const expectedArgs : string[] = []; );
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`); for (const env of Object.keys(envs)) {
} delete process.env['INPUT_' + env.toUpperCase()];
}
const {reportExecArgs, reportCommand} = buildReportExec(); });
expect(reportExecArgs).toEqual(expectedArgs); test('functionalities', () => {
expect(reportCommand).toEqual('create-report'); const envs = {'functionalities': 'network, gcov'};
for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()]; for (const [name, value] of Object.entries(envs)) {
} process.env['INPUT_' + name.toUpperCase()] = value;
}); }
const {execArgs} = buildExec();
test('commit args', () => {
const envs = { expect(execArgs).toEqual(
override_commit: '9caabca5474b49de74ef5667deabaf74cdacc244', expect.arrayContaining([
slug: 'fakeOwner/fakeRepo', ...baseExpectation,
token: 'd3859757-ab80-4664-924d-aef22fa7557b', '-X',
override_branch: 'thomasrockhu/test', 'network',
override_pr: '2', '-X',
commit_parent: '83231650328f11695dfb754ca0f540516f188d27', 'gcov',
}; ]),
for (const env of Object.keys(envs)) { );
process.env['INPUT_' + env.toUpperCase()] = envs[env];
} for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()];
const {commitExecArgs, commitCommand} = buildCommitExec(); }
});
expect(commitExecArgs).toEqual(
expect.arrayContaining([
'-C',
'9caabca5474b49de74ef5667deabaf74cdacc244',
'--slug',
'fakeOwner/fakeRepo',
'-B',
'thomasrockhu/test',
'--pr',
'2',
'--parent-sha',
'83231650328f11695dfb754ca0f540516f188d27',
]));
expect(commitCommand).toEqual('create-commit');
for (const env of Object.keys(envs)) {
delete process.env['INPUT_' + env.toUpperCase()];
}
});
test('commit args using context', () => {
const expectedArgs :string[] = [];
const {commitExecArgs, commitCommand} = buildCommitExec();
if (context.eventName == 'pull_request') {
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
}
if (context.eventName == 'pull_request_target') {
expectedArgs.push('-P', `${context.payload.number}`);
}
expect(commitExecArgs).toEqual(expectedArgs);
expect(commitCommand).toEqual('create-commit');
}); });

View File

@@ -1,8 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as github from '@actions/github'; import * as github from '@actions/github';
import {version} from '../package.json';
const context = github.context; const context = github.context;
@@ -17,142 +16,56 @@ const isTrue = (variable) => {
); );
}; };
const buildExec = () => {
const buildCommitExec = () => { const clean = core.getInput('move_coverage_to_trash');
const commitParent = core.getInput('commit_parent'); const commitParent = core.getInput('commit_parent');
const overrideBranch = core.getInput('override_branch');
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
const token = core.getInput('token');
const commitCommand = 'create-commit';
const commitExecArgs = [];
const commitOptions:any = {};
commitOptions.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) {
commitOptions.env.CODECOV_TOKEN = token;
}
if (commitParent) {
commitExecArgs.push('--parent-sha', `${commitParent}`);
}
if (overrideBranch) {
commitExecArgs.push('-B', `${overrideBranch}`);
}
if (overrideCommit) {
commitExecArgs.push('-C', `${overrideCommit}`);
} else if (
`${context.eventName}` == 'pull_request' ||
`${context.eventName}` == 'pull_request_target'
) {
commitExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
}
if (overridePr) {
commitExecArgs.push('--pr', `${overridePr}`);
} else if (
`${context.eventName}` == 'pull_request_target'
) {
commitExecArgs.push('--pr', `${context.payload.number}`);
}
if (slug) {
commitExecArgs.push('--slug', `${slug}`);
}
return {commitExecArgs, commitOptions, commitCommand};
};
const buildGeneralExec = () => {
const url = core.getInput('url');
const verbose = isTrue(core.getInput('verbose'));
const args = [];
if (url) {
args.push('--enterprise-url', `${url}`);
}
if (verbose) {
args.push('-v');
}
return {args, verbose};
};
const buildReportExec = () => {
const overrideCommit = core.getInput('override_commit');
const slug = core.getInput('slug');
const token = core.getInput('token');
const reportCommand = 'create-report';
const reportExecArgs = [];
const reportOptions:any = {};
reportOptions.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) {
reportOptions.env.CODECOV_TOKEN = token;
}
if (overrideCommit) {
reportExecArgs.push('-C', `${overrideCommit}`);
} else if (
`${context.eventName}` == 'pull_request' ||
`${context.eventName}` == 'pull_request_target'
) {
reportExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
}
if (slug) {
reportExecArgs.push('--slug', `${slug}`);
}
return {reportExecArgs, reportOptions, reportCommand};
};
const buildUploadExec = () => {
const envVars = core.getInput('env_vars');
const dryRun = isTrue(core.getInput('dry_run')); const dryRun = isTrue(core.getInput('dry_run'));
const envVars = core.getInput('env_vars');
const failCi = isTrue(core.getInput('fail_ci_if_error')); const failCi = isTrue(core.getInput('fail_ci_if_error'));
const file = core.getInput('file'); const file = core.getInput('file');
const files = core.getInput('files'); const files = core.getInput('files');
const flags = core.getInput('flags'); 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 name = core.getInput('name'); const name = core.getInput('name');
const networkFilter = core.getInput('network_filter');
const networkPrefix = core.getInput('network_prefix');
const os = core.getInput('os'); const os = core.getInput('os');
const overrideBranch = core.getInput('override_branch'); const overrideBranch = core.getInput('override_branch');
const overrideBuild = core.getInput('override_build'); const overrideBuild = core.getInput('override_build');
const overrideCommit = core.getInput('override_commit'); const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr'); const overridePr = core.getInput('override_pr');
const plugins = core.getInput('plugins'); const overrideTag = core.getInput('override_tag');
const rootDir = core.getInput('root_dir'); const rootDir = core.getInput('root_dir');
const searchDir = core.getInput('directory'); const searchDir = core.getInput('directory');
const slug = core.getInput('slug'); const slug = core.getInput('slug');
const swift = core.getInput('swift');
const swiftProject = core.getInput('swift_project');
const token = core.getInput('token'); 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 workingDir = core.getInput('working-directory');
const plugin = core.getInput('plugin'); const xcode = core.getInput('xcode');
const exclude = core.getInput('exclude'); const xcodeArchivePath = core.getInput('xcode_archive_path');
const xtraArgs = core.getInput('xtra_args');
let uploaderVersion = core.getInput('version');
const uploadExecArgs = []; const execArgs = [];
const uploadCommand = 'do-upload'; execArgs.push(
const uploadOptions:any = {}; '-n',
uploadOptions.env = Object.assign(process.env, { `${name}`,
'-Q',
`github-action-${version}`,
);
const options:any = {};
options.env = Object.assign(process.env, {
GITHUB_ACTION: process.env.GITHUB_ACTION, GITHUB_ACTION: process.env.GITHUB_ACTION,
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
GITHUB_REF: process.env.GITHUB_REF, GITHUB_REF: process.env.GITHUB_REF,
@@ -165,104 +78,144 @@ const buildUploadExec = () => {
for (const envVar of envVars.split(',')) { for (const envVar of envVars.split(',')) {
const envVarClean = envVar.trim(); const envVarClean = envVar.trim();
if (envVarClean) { if (envVarClean) {
uploadOptions.env[envVarClean] = process.env[envVarClean]; options.env[envVarClean] = process.env[envVarClean];
envVarsArg.push(envVarClean); envVarsArg.push(envVarClean);
} }
} }
if (name) {
uploadExecArgs.push(
'-n',
`${name}`,
);
}
if (token) { if (token) {
uploadOptions.env.CODECOV_TOKEN = token; options.env.CODECOV_TOKEN = token;
}
if (clean) {
execArgs.push('-c');
}
if (commitParent) {
execArgs.push('-N', `${commitParent}`);
} }
if (dryRun) { if (dryRun) {
uploadExecArgs.push('-d'); execArgs.push('-d');
} }
if (envVarsArg.length) { if (envVarsArg.length) {
uploadExecArgs.push('-e', envVarsArg.join(',')); execArgs.push('-e', envVarsArg.join(','));
}
if (functionalities) {
functionalities.split(',').map((f) => f.trim()).forEach((f) => {
execArgs.push('-X', `${f}`);
});
} }
if (failCi) { if (failCi) {
uploadExecArgs.push('-Z'); execArgs.push('-Z');
} }
if (file) { if (file) {
uploadExecArgs.push('-f', `${file}`); execArgs.push('-f', `${file}`);
} }
if (files) { if (files) {
files.split(',').map((f) => f.trim()).forEach((f) => { files.split(',').map((f) => f.trim()).forEach((f) => {
uploadExecArgs.push('-f', `${f}`); execArgs.push('-f', `${f}`);
}); });
} }
if (fullReport) {
execArgs.push('--full', `${fullReport}`);
}
if (flags) { if (flags) {
flags.split(',').map((f) => f.trim()).forEach((f) => { flags.split(',').map((f) => f.trim()).forEach((f) => {
uploadExecArgs.push('-F', `${f}`); execArgs.push('-F', `${f}`);
}); });
} }
if (gcov) {
execArgs.push('-g');
}
if (gcovArgs) {
execArgs.push('--ga', `${gcovArgs}`);
}
if (gcovIgnore) {
execArgs.push('--gi', `${gcovIgnore}`);
}
if (gcovInclude) {
execArgs.push('--gI', `${gcovInclude}`);
}
if (gcovExecutable) {
execArgs.push('--gx', `${gcovExecutable}`);
}
if (networkFilter) {
execArgs.push('-i', `${networkFilter}`);
}
if (networkPrefix) {
execArgs.push('-k', `${networkPrefix}`);
}
if (overrideBranch) { if (overrideBranch) {
uploadExecArgs.push('-B', `${overrideBranch}`); execArgs.push('-B', `${overrideBranch}`);
} }
if (overrideBuild) { if (overrideBuild) {
uploadExecArgs.push('-b', `${overrideBuild}`); execArgs.push('-b', `${overrideBuild}`);
} }
if (overrideCommit) { if (overrideCommit) {
uploadExecArgs.push('-C', `${overrideCommit}`); execArgs.push('-C', `${overrideCommit}`);
} else if ( } else if (
`${context.eventName}` == 'pull_request' || `${context.eventName}` == 'pull_request' ||
`${context.eventName}` == 'pull_request_target' `${context.eventName}` == 'pull_request_target'
) { ) {
uploadExecArgs.push('-C', `${context.payload.pull_request.head.sha}`); execArgs.push('-C', `${context.payload.pull_request.head.sha}`);
} }
if (overridePr) { if (overridePr) {
uploadExecArgs.push('-P', `${overridePr}`); execArgs.push('-P', `${overridePr}`);
} else if ( } else if (
`${context.eventName}` == 'pull_request_target' `${context.eventName}` == 'pull_request_target'
) { ) {
uploadExecArgs.push('-P', `${context.payload.number}`); execArgs.push('-P', `${context.payload.number}`);
} }
if (plugins) { if (overrideTag) {
plugins.split(',').map((p) => p.trim()).forEach((p) => { execArgs.push('-T', `${overrideTag}`);
uploadExecArgs.push('--plugin', `${p}`);
});
} }
if (rootDir) { if (rootDir) {
uploadExecArgs.push('--network-root-folder', `${rootDir}`); execArgs.push('-R', `${rootDir}`);
} }
if (searchDir) { if (searchDir) {
uploadExecArgs.push('-s', `${searchDir}`); execArgs.push('-s', `${searchDir}`);
} }
if (slug) { if (slug) {
uploadExecArgs.push('-r', `${slug}`); execArgs.push('-r', `${slug}`);
} }
if (workingDir) { if (swift) {
uploadOptions.cwd = workingDir; execArgs.push('--xs');
} }
if (plugin) { if (swift && swiftProject) {
uploadExecArgs.push('--plugin', `${plugin}`); execArgs.push('--xsp', `${swiftProject}`);
} }
if (exclude) { if (upstream) {
uploadExecArgs.push('--exclude', `${exclude}`); execArgs.push('-U', `${upstream}`);
}
if (url) {
execArgs.push('-u', `${url}`);
}
if (verbose) {
execArgs.push('-v');
}
if (xcode && xcodeArchivePath) {
execArgs.push('--xc');
execArgs.push('--xp', `${xcodeArchivePath}`);
} }
if (uploaderVersion == '') { if (uploaderVersion == '') {
uploaderVersion = 'latest'; uploaderVersion = 'latest';
} }
return { if (verbose) {
uploadExecArgs, console.debug({execArgs});
uploadOptions, }
failCi,
os, if (workingDir) {
uploaderVersion, options.cwd = workingDir;
uploadCommand, }
};
if (xtraArgs) {
execArgs.push(`${xtraArgs}`);
}
return {execArgs, options, failCi, os, uploaderVersion, verbose};
}; };
export default buildExec;
export {
buildCommitExec,
buildGeneralExec,
buildReportExec,
buildUploadExec,
};

View File

@@ -4,7 +4,6 @@ import {
isValidPlatform, isValidPlatform,
isWindows, isWindows,
PLATFORMS, PLATFORMS,
getCommand,
} from './helpers'; } from './helpers';
let OLDOS = process.env.RUNNER_OS; let OLDOS = process.env.RUNNER_OS;
@@ -40,35 +39,34 @@ test('getBaseUrl', () => {
expect(PLATFORMS.map((platform) => { expect(PLATFORMS.map((platform) => {
return getBaseUrl(platform, 'latest'); return getBaseUrl(platform, 'latest');
})).toEqual([ })).toEqual([
'https://cli.codecov.io/latest/linux/codecov', 'https://uploader.codecov.io/latest/aarch64/codecov',
'https://cli.codecov.io/latest/macos/codecov', 'https://uploader.codecov.io/latest/alpine/codecov',
'https://cli.codecov.io/latest/windows/codecov.exe', 'https://uploader.codecov.io/latest/linux/codecov',
'https://uploader.codecov.io/latest/macos/codecov',
'https://uploader.codecov.io/latest/windows/codecov.exe',
]); ]);
expect(PLATFORMS.map((platform) => { expect(PLATFORMS.map((platform) => {
return getBaseUrl(platform, 'v0.1.0_8880'); return getBaseUrl(platform, 'v0.1.0_8880');
})).toEqual([ })).toEqual([
'https://cli.codecov.io/v0.1.0_8880/linux/codecov', 'https://uploader.codecov.io/v0.1.0_8880/aarch64/codecov',
'https://cli.codecov.io/v0.1.0_8880/macos/codecov', 'https://uploader.codecov.io/v0.1.0_8880/alpine/codecov',
'https://cli.codecov.io/v0.1.0_8880/windows/codecov.exe', 'https://uploader.codecov.io/v0.1.0_8880/linux/codecov',
'https://uploader.codecov.io/v0.1.0_8880/macos/codecov',
'https://uploader.codecov.io/v0.1.0_8880/windows/codecov.exe',
]); ]);
}); });
test('isWindows', () => { test('isWindows', () => {
expect(PLATFORMS.map((platform) => { expect(PLATFORMS.map((platform) => {
return isWindows(platform); return isWindows(platform);
})).toEqual([false, false, true]); })).toEqual([false, false, false, false, true]);
}); });
test('isValidPlatform', () => { test('isValidPlatform', () => {
expect(PLATFORMS.map((platform) => { expect(PLATFORMS.map((platform) => {
return isValidPlatform(platform); return isValidPlatform(platform);
})).toEqual([true, true, true]); })).toEqual([true, true, true, true, true]);
expect(isValidPlatform('fakeos')).toBeFalsy(); expect(isValidPlatform('fakeos')).toBeFalsy();
}); });
test('getCommand', () => {
expect(getCommand('path', ['-v', '-x'], 'do-upload'))
.toEqual(['path', '-v', '-x', 'do-upload']);
});

View File

@@ -1,6 +1,8 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
const PLATFORMS = [ const PLATFORMS = [
'aarch64',
'alpine',
'linux', 'linux',
'macos', 'macos',
'windows', 'windows',
@@ -48,17 +50,7 @@ const getPlatform = (os?: string): string => {
}; };
const getBaseUrl = (platform: string, version: string): string => { const getBaseUrl = (platform: string, version: string): string => {
return `https://cli.codecov.io/${version}/${platform}/${getUploaderName(platform)}`; return `https://uploader.codecov.io/${version}/${platform}/${getUploaderName(platform)}`;
};
const getCommand = (
filename: string,
generalArgs:string[],
command: string,
): string[] => {
const fullCommand = [filename, ...generalArgs, command];
core.info(`==> Running command '${fullCommand.join(' ')}'`);
return fullCommand;
}; };
export { export {
@@ -69,5 +61,4 @@ export {
isValidPlatform, isValidPlatform,
isWindows, isWindows,
setFailure, setFailure,
getCommand,
}; };

View File

@@ -4,18 +4,12 @@ import * as path from 'path';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
import { import buildExec from './buildExec';
buildCommitExec,
buildGeneralExec,
buildReportExec,
buildUploadExec,
} from './buildExec';
import { import {
getBaseUrl, getBaseUrl,
getPlatform, getPlatform,
getUploaderName, getUploaderName,
setFailure, setFailure,
getCommand,
} from './helpers'; } from './helpers';
import verify from './validate'; import verify from './validate';
@@ -24,18 +18,7 @@ import versionInfo from './version';
let failCi; let failCi;
try { try {
const {commitExecArgs, commitOptions, commitCommand} = buildCommitExec(); const {execArgs, options, failCi, os, uploaderVersion, verbose} = buildExec();
const {reportExecArgs, reportOptions, reportCommand} = buildReportExec();
const {
uploadExecArgs,
uploadOptions,
failCi,
os,
uploaderVersion,
uploadCommand,
} = buildUploadExec();
const {args, verbose} = buildGeneralExec();
const platform = getPlatform(os); const platform = getPlatform(os);
const filename = path.join( __dirname, getUploaderName(platform)); const filename = path.join( __dirname, getUploaderName(platform));
@@ -66,52 +49,14 @@ try {
} }
}); });
}; };
const doUpload = async () => { await exec.exec(filename, execArgs, options)
await exec.exec(getCommand(filename, args, uploadCommand).join(' '), .catch((err) => {
uploadExecArgs,
uploadOptions)
.catch((err) => {
setFailure(
`Codecov:
Failed to properly upload report: ${err.message}`,
failCi,
);
});
};
const createReport = async () => {
await exec.exec(
getCommand(filename, args, reportCommand).join(' '),
reportExecArgs,
reportOptions)
.then(async (exitCode) => {
if (exitCode == 0) {
await doUpload();
}
}).catch((err) => {
setFailure(
`Codecov:
Failed to properly create report: ${err.message}`,
failCi,
);
});
};
await exec.exec(
getCommand(
filename,
args,
commitCommand,
).join(' '),
commitExecArgs, commitOptions)
.then(async (exitCode) => {
if (exitCode == 0) {
await createReport();
}
unlink();
}).catch((err) => {
setFailure( setFailure(
`Codecov: Failed to properly create commit: ${err.message}`, `Codecov: Failed to properly upload: ${err.message}`,
failCi, failCi,
); );
}).then(() => {
unlink();
}); });
}); });
}); });