mirror of
https://github.com/codecov/codecov-action.git
synced 2025-12-08 16:16:24 +00:00
Compare commits
52 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b9fd7d16f6 | ||
|
|
6f7612c64d | ||
|
|
26c7e28d7e | ||
|
|
6f744f78de | ||
|
|
543c3d42fc | ||
|
|
e379426d37 | ||
|
|
42656e4cb1 | ||
|
|
2296b6ba9e | ||
|
|
bd77bc323c | ||
|
|
180b964407 | ||
|
|
4beef3e59f | ||
|
|
8bacbcdafc | ||
|
|
0036103d21 | ||
|
|
f9253eb652 | ||
|
|
135f82e412 | ||
|
|
4b21c320b5 | ||
|
|
2439dfc05c | ||
|
|
bb813333f9 | ||
|
|
d2bac1a14c | ||
|
|
9f15ff6db1 | ||
|
|
60a33a541b | ||
|
|
943cea186c | ||
|
|
955f1f08ad | ||
|
|
922d8d7b31 | ||
|
|
764e2e4bac | ||
|
|
dd5d48487d | ||
|
|
6f75c27045 | ||
|
|
4168d1398b | ||
|
|
abe5d5a96b | ||
|
|
cdaae0e243 | ||
|
|
a06c39c510 | ||
|
|
a87fadc201 | ||
|
|
4ef269f796 | ||
|
|
992fc4eb1f | ||
|
|
9e145151be | ||
|
|
e1b169f283 | ||
|
|
4809d8a8f6 | ||
|
|
543b309c01 | ||
|
|
621cd670ee | ||
|
|
e4dbd7e64b | ||
|
|
893cfea3da | ||
|
|
e12e94d346 | ||
|
|
8cf010f6e4 | ||
|
|
0cbef546c8 | ||
|
|
af2ee03a4e | ||
|
|
3d7297c4a2 | ||
|
|
ca3e2d9612 | ||
|
|
f5469482a3 | ||
|
|
76ee96d868 | ||
|
|
9a146cf9d5 | ||
|
|
d3911e8ec2 | ||
|
|
d81eade746 |
8
.github/workflows/codeql-analysis.yml
vendored
8
.github/workflows/codeql-analysis.yml
vendored
@@ -37,11 +37,11 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4.1.6
|
||||
uses: actions/checkout@v4.2.0
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3.25.8
|
||||
uses: github/codeql-action/init@v3.26.9
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# 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).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3.25.8
|
||||
uses: github/codeql-action/autobuild@v3.26.9
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
@@ -66,4 +66,4 @@ jobs:
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3.25.8
|
||||
uses: github/codeql-action/analyze@v3.26.9
|
||||
|
||||
8
.github/workflows/main.yml
vendored
8
.github/workflows/main.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
||||
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.6
|
||||
uses: actions/checkout@v4.2.0
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Lint
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
file: ./coverage/coverage-final.json
|
||||
flags: version,${{ matrix.os }}
|
||||
name: codecov-version
|
||||
version: v0.6.0
|
||||
version: v0.7.3
|
||||
verbose: true
|
||||
token: ${{ secrets.CODECOV_TOKEN }}
|
||||
|
||||
@@ -51,7 +51,7 @@ jobs:
|
||||
runs-on: macos-latest-xlarge
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.6
|
||||
uses: actions/checkout@v4.2.0
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Lint
|
||||
@@ -94,7 +94,7 @@ jobs:
|
||||
container: node:18
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4.1.6
|
||||
uses: actions/checkout@v4.2.0
|
||||
- name: Install dependencies
|
||||
run: npm install
|
||||
- name: Lint
|
||||
|
||||
9
.github/workflows/scorecards-analysis.yml
vendored
9
.github/workflows/scorecards-analysis.yml
vendored
@@ -12,6 +12,7 @@ permissions: read-all
|
||||
|
||||
jobs:
|
||||
analysis:
|
||||
if: github.repository == 'codecov/codecov-action'
|
||||
name: Scorecards analysis
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
@@ -24,12 +25,12 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: "Checkout code"
|
||||
uses: actions/checkout@v4.1.6 # v3.0.0
|
||||
uses: actions/checkout@v4.2.0 # v3.0.0
|
||||
with:
|
||||
persist-credentials: false
|
||||
|
||||
- name: "Run analysis"
|
||||
uses: ossf/scorecard-action@dc50aa9510b46c811795eb24b2f1ba02a914e534 # v2.3.3
|
||||
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
|
||||
with:
|
||||
results_file: results.sarif
|
||||
results_format: sarif
|
||||
@@ -48,7 +49,7 @@ jobs:
|
||||
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
|
||||
# format to the repository Actions tab.
|
||||
- name: "Upload artifact"
|
||||
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
|
||||
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
|
||||
with:
|
||||
name: SARIF file
|
||||
path: results.sarif
|
||||
@@ -56,6 +57,6 @@ jobs:
|
||||
|
||||
# Upload the results to GitHub's code scanning dashboard.
|
||||
- name: "Upload to code-scanning"
|
||||
uses: github/codeql-action/upload-sarif@v3.25.8 # v1.0.26
|
||||
uses: github/codeql-action/upload-sarif@v3.26.9 # v1.0.26
|
||||
with:
|
||||
sarif_file: results.sarif
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
`v4` of the Codecov GitHub Action will use the [Codecov CLI](https://github.com/codecov/codecov-cli) to upload coverage reports to Codecov.
|
||||
|
||||
### Breaking Changes
|
||||
- Tokenless uploading is unsupported. However, PRs made from forks to the upstream public repos will support tokenless (e.g. contributors to OS projects do not need the upstream repo's Codecov token). For details, [see our docs](https://docs.codecov.com/docs/codecov-uploader#supporting-token-less-uploads-for-forks-of-open-source-repos-using-codecov)
|
||||
- Tokenless uploading is unsupported. However, PRs made from forks to the upstream public repos will support tokenless (e.g. contributors to OSS projects do not need the upstream repo's Codecov token). For details, [see our docs](https://docs.codecov.com/docs/codecov-uploader#supporting-token-less-uploads-for-forks-of-open-source-repos-using-codecov)
|
||||
- Various arguments to the Action have been removed
|
||||
|
||||
### Dependabot
|
||||
|
||||
1549
dist/index.js
vendored
Executable file → Normal file
1549
dist/index.js
vendored
Executable file → Normal file
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/sourcemap-register.js
vendored
2
dist/sourcemap-register.js
vendored
File diff suppressed because one or more lines are too long
4101
package-lock.json
generated
4101
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "codecov-action",
|
||||
"version": "4.5.0",
|
||||
"version": "4.6.0",
|
||||
"description": "Upload coverage reports to Codecov from GitHub Actions",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -29,15 +29,16 @@
|
||||
"undici": "5.28.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^29.5.12",
|
||||
"@typescript-eslint/eslint-plugin": "^7.13.0",
|
||||
"@typescript-eslint/parser": "^7.13.0",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.57.0",
|
||||
"@octokit/webhooks-types": "^7.5.1",
|
||||
"@types/jest": "^29.5.13",
|
||||
"@typescript-eslint/eslint-plugin": "^8.8.0",
|
||||
"@typescript-eslint/parser": "^8.8.0",
|
||||
"@vercel/ncc": "^0.38.2",
|
||||
"eslint": "^8.57.1",
|
||||
"eslint-config-google": "^0.14.0",
|
||||
"jest": "^29.7.0",
|
||||
"jest-junit": "^16.0.0",
|
||||
"ts-jest": "^29.1.4",
|
||||
"typescript": "^5.4.5"
|
||||
"ts-jest": "^29.2.5",
|
||||
"typescript": "^5.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
buildGeneralExec,
|
||||
buildReportExec,
|
||||
buildUploadExec,
|
||||
getToken,
|
||||
} from './buildExec';
|
||||
|
||||
const context = github.context;
|
||||
@@ -213,7 +214,7 @@ test('report args using context', async () => {
|
||||
for (const env of Object.keys(envs)) {
|
||||
process.env['INPUT_' + env.toUpperCase()] = envs[env];
|
||||
}
|
||||
const expectedArgs : string[] = [
|
||||
const expectedArgs: string[] = [
|
||||
'--git-service',
|
||||
'github',
|
||||
];
|
||||
@@ -271,12 +272,18 @@ test('commit args', async () => {
|
||||
});
|
||||
|
||||
test('commit args using context', async () => {
|
||||
const expectedArgs :string[] = [
|
||||
const expectedArgs: string[] = [
|
||||
'--git-service',
|
||||
'github',
|
||||
];
|
||||
|
||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
||||
if (
|
||||
(context.eventName == 'pull_request' || context.eventName == 'pull_request_target') &&
|
||||
context.payload.pull_request?.base.label.split(':')[0] != context.payload.pull_request?.head.label.split(':')[0]
|
||||
) {
|
||||
expectedArgs.push('-B', `${context.payload.pull_request?.head.label}`);
|
||||
}
|
||||
if (context.eventName == 'pull_request') {
|
||||
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
|
||||
}
|
||||
@@ -289,7 +296,7 @@ test('commit args using context', async () => {
|
||||
});
|
||||
|
||||
test('commit args using github server url', async () => {
|
||||
const expectedArgs :string[] = [
|
||||
const expectedArgs: string[] = [
|
||||
'--git-service',
|
||||
'github_enterprise',
|
||||
];
|
||||
@@ -297,13 +304,65 @@ test('commit args using github server url', async () => {
|
||||
process.env.GITHUB_SERVER_URL = 'https://example.com';
|
||||
|
||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
||||
if (
|
||||
(context.eventName == 'pull_request' || context.eventName == 'pull_request_target') &&
|
||||
context.payload.pull_request?.base.label.split(':')[0] != context.payload.pull_request?.head.label.split(':')[0]
|
||||
) {
|
||||
expectedArgs.push('-B', `${context.payload.pull_request?.head.label}`);
|
||||
}
|
||||
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');
|
||||
});
|
||||
|
||||
test('build commit args when token arg is unset and from fork', async () => {
|
||||
context.eventName = 'pull_request';
|
||||
context.payload.pull_request = {
|
||||
'number': 1,
|
||||
'base': {
|
||||
'label': 'hello:main',
|
||||
},
|
||||
'head': {
|
||||
'label': 'world:feat',
|
||||
'sha': 'aaaaaa',
|
||||
},
|
||||
};
|
||||
|
||||
const expectedArgs: string[] = [
|
||||
'--git-service',
|
||||
'github_enterprise',
|
||||
'-B',
|
||||
'world:feat',
|
||||
'-C',
|
||||
`${context.payload.pull_request?.head.sha}`,
|
||||
];
|
||||
|
||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
||||
|
||||
expect(commitExecArgs).toEqual(expectedArgs);
|
||||
expect(commitCommand).toEqual('create-commit');
|
||||
});
|
||||
|
||||
test('get token when token arg is unset and from fork', async () => {
|
||||
context.eventName = 'pull_request';
|
||||
context.payload.pull_request = {
|
||||
'number': 1,
|
||||
'base': {
|
||||
'label': 'hello:main',
|
||||
},
|
||||
'head': {
|
||||
'label': 'world:feat',
|
||||
'sha': 'aaaaaa',
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
const token = await getToken();
|
||||
|
||||
expect(token).toEqual('');
|
||||
});
|
||||
|
||||
168
src/buildExec.ts
168
src/buildExec.ts
@@ -2,6 +2,7 @@
|
||||
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import {type PullRequestEvent} from '@octokit/webhooks-types';
|
||||
|
||||
import {setFailure} from './helpers';
|
||||
|
||||
@@ -30,11 +31,8 @@ const getGitService = (): string => {
|
||||
};
|
||||
|
||||
const isPullRequestFromFork = (): boolean => {
|
||||
core.info(`evenName: ${context.eventName}`);
|
||||
if (
|
||||
`${context.eventName}` !== 'pull_request' &&
|
||||
`${context.eventName}` !== 'pull_request_target'
|
||||
) {
|
||||
core.info(`eventName: ${context.eventName}`);
|
||||
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -42,16 +40,11 @@ const isPullRequestFromFork = (): boolean => {
|
||||
const headLabel = context.payload.pull_request.head.label;
|
||||
|
||||
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
|
||||
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
|
||||
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
|
||||
};
|
||||
|
||||
const getToken = async (): Promise<string> => {
|
||||
let token = core.getInput('token');
|
||||
if (!token && isPullRequestFromFork()) {
|
||||
core.info('==> Fork detected, tokenless uploading used');
|
||||
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
|
||||
return Promise.resolve('');
|
||||
}
|
||||
let url = core.getInput('url');
|
||||
const useOIDC = isTrue(core.getInput('use_oidc'));
|
||||
if (useOIDC) {
|
||||
@@ -60,7 +53,7 @@ const getToken = async (): Promise<string> => {
|
||||
}
|
||||
try {
|
||||
token = await core.getIDToken(url);
|
||||
return token;
|
||||
return Promise.resolve(token);
|
||||
} catch (err) {
|
||||
setFailure(
|
||||
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
|
||||
@@ -71,6 +64,17 @@ const getToken = async (): Promise<string> => {
|
||||
return token;
|
||||
};
|
||||
|
||||
const getOverrideBranch = (token: string): string => {
|
||||
let overrideBranch = core.getInput('override_branch');
|
||||
if (!overrideBranch && !token && isPullRequestFromFork()) {
|
||||
core.info('==> Fork detected, tokenless uploading used');
|
||||
// backwards compatibility with certain versions of the CLI that expect this
|
||||
process.env['TOKENLESS'] = context.payload.pull_request.head.label;
|
||||
overrideBranch =context.payload.pull_request.head.label;
|
||||
}
|
||||
return overrideBranch;
|
||||
};
|
||||
|
||||
const buildCommitExec = async (): Promise<{
|
||||
commitExecArgs: any[];
|
||||
commitOptions: any;
|
||||
@@ -78,18 +82,18 @@ const buildCommitExec = async (): Promise<{
|
||||
}> => {
|
||||
const commitParent = core.getInput('commit_parent');
|
||||
const gitService = getGitService();
|
||||
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 = await getToken();
|
||||
const overrideBranch = getOverrideBranch(token);
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
||||
const commitCommand = 'create-commit';
|
||||
const commitExecArgs = [];
|
||||
const commitExecArgs: string[] = [];
|
||||
|
||||
const commitOptions:any = {};
|
||||
const commitOptions: any = {};
|
||||
commitOptions.env = Object.assign(process.env, {
|
||||
GITHUB_ACTION: process.env.GITHUB_ACTION,
|
||||
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
|
||||
@@ -99,35 +103,33 @@ const buildCommitExec = async (): Promise<{
|
||||
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '',
|
||||
});
|
||||
|
||||
|
||||
if (token) {
|
||||
commitOptions.env.CODECOV_TOKEN = token;
|
||||
}
|
||||
if (commitParent) {
|
||||
commitExecArgs.push('--parent-sha', `${commitParent}`);
|
||||
commitExecArgs.push('--parent-sha', commitParent);
|
||||
}
|
||||
commitExecArgs.push('--git-service', `${gitService}`);
|
||||
commitExecArgs.push('--git-service', gitService);
|
||||
|
||||
if (overrideBranch) {
|
||||
commitExecArgs.push('-B', `${overrideBranch}`);
|
||||
commitExecArgs.push('-B', overrideBranch);
|
||||
}
|
||||
if (overrideCommit) {
|
||||
commitExecArgs.push('-C', `${overrideCommit}`);
|
||||
commitExecArgs.push('-C', overrideCommit);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request' ||
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
['pull_request', 'pull_request_target'].includes(context.eventName)
|
||||
) {
|
||||
commitExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
commitExecArgs.push('-C', payload.pull_request.head.sha);
|
||||
}
|
||||
if (overridePr) {
|
||||
commitExecArgs.push('--pr', `${overridePr}`);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
) {
|
||||
commitExecArgs.push('--pr', `${context.payload.number}`);
|
||||
commitExecArgs.push('--pr', overridePr);
|
||||
} else if (context.eventName === 'pull_request_target') {
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
commitExecArgs.push('--pr', payload.number.toString());
|
||||
}
|
||||
if (slug) {
|
||||
commitExecArgs.push('--slug', `${slug}`);
|
||||
commitExecArgs.push('--slug', slug);
|
||||
}
|
||||
if (failCi) {
|
||||
commitExecArgs.push('-Z');
|
||||
@@ -136,7 +138,6 @@ const buildCommitExec = async (): Promise<{
|
||||
commitOptions.cwd = workingDir;
|
||||
}
|
||||
|
||||
|
||||
return {commitExecArgs, commitOptions, commitCommand};
|
||||
};
|
||||
|
||||
@@ -150,10 +151,10 @@ const buildGeneralExec = (): {
|
||||
const args = [];
|
||||
|
||||
if (codecovYmlPath) {
|
||||
args.push('--codecov-yml-path', `${codecovYmlPath}`);
|
||||
args.push('--codecov-yml-path', codecovYmlPath);
|
||||
}
|
||||
if (url) {
|
||||
args.push('--enterprise-url', `${url}`);
|
||||
args.push('--enterprise-url', url);
|
||||
}
|
||||
if (verbose) {
|
||||
args.push('-v');
|
||||
@@ -174,11 +175,10 @@ const buildReportExec = async (): Promise<{
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
||||
|
||||
const reportCommand = 'create-report';
|
||||
const reportExecArgs = [];
|
||||
const reportExecArgs: string[] = [];
|
||||
|
||||
const reportOptions:any = {};
|
||||
const reportOptions: any = {};
|
||||
reportOptions.env = Object.assign(process.env, {
|
||||
GITHUB_ACTION: process.env.GITHUB_ACTION,
|
||||
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
|
||||
@@ -188,29 +188,27 @@ const buildReportExec = async (): Promise<{
|
||||
GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '',
|
||||
});
|
||||
|
||||
|
||||
if (token) {
|
||||
reportOptions.env.CODECOV_TOKEN = token;
|
||||
}
|
||||
reportExecArgs.push('--git-service', `${gitService}`);
|
||||
reportExecArgs.push('--git-service', gitService);
|
||||
|
||||
if (overrideCommit) {
|
||||
reportExecArgs.push('-C', `${overrideCommit}`);
|
||||
reportExecArgs.push('-C', overrideCommit);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request' ||
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
['pull_request', 'pull_request_target'].includes(context.eventName)
|
||||
) {
|
||||
reportExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
reportExecArgs.push('-C', payload.pull_request.head.sha);
|
||||
}
|
||||
if (overridePr) {
|
||||
reportExecArgs.push('-P', `${overridePr}`);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
) {
|
||||
reportExecArgs.push('-P', `${context.payload.number}`);
|
||||
reportExecArgs.push('-P', overridePr);
|
||||
} else if (context.eventName == 'pull_request_target') {
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
reportExecArgs.push('-P', payload.number.toString());
|
||||
}
|
||||
if (slug) {
|
||||
reportExecArgs.push('--slug', `${slug}`);
|
||||
reportExecArgs.push('--slug', slug);
|
||||
}
|
||||
if (failCi) {
|
||||
reportExecArgs.push('-Z');
|
||||
@@ -266,9 +264,9 @@ const buildUploadExec = async (): Promise<{
|
||||
);
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
||||
const uploadExecArgs = [];
|
||||
const uploadExecArgs: string[] = [];
|
||||
const uploadCommand = 'do-upload';
|
||||
const uploadOptions:any = {};
|
||||
const uploadOptions: any = {};
|
||||
uploadOptions.env = Object.assign(process.env, {
|
||||
GITHUB_ACTION: process.env.GITHUB_ACTION,
|
||||
GITHUB_RUN_ID: process.env.GITHUB_RUN_ID,
|
||||
@@ -302,85 +300,94 @@ const buildUploadExec = async (): Promise<{
|
||||
uploadExecArgs.push('-e', envVarsArg.join(','));
|
||||
}
|
||||
if (exclude) {
|
||||
uploadExecArgs.push('--exclude', `${exclude}`);
|
||||
uploadExecArgs.push('--exclude', exclude);
|
||||
}
|
||||
if (failCi) {
|
||||
uploadExecArgs.push('-Z');
|
||||
}
|
||||
if (file) {
|
||||
uploadExecArgs.push('-f', `${file}`);
|
||||
uploadExecArgs.push('-f', file);
|
||||
}
|
||||
if (files) {
|
||||
files.split(',').map((f) => f.trim()).forEach((f) => {
|
||||
if (f.length > 0) { // this handles trailing commas
|
||||
uploadExecArgs.push('-f', `${f}`);
|
||||
files
|
||||
.split(',')
|
||||
.map((f) => f.trim())
|
||||
.forEach((f) => {
|
||||
if (f.length > 0) {
|
||||
// this handles trailing commas
|
||||
uploadExecArgs.push('-f', f);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (flags) {
|
||||
flags.split(',').map((f) => f.trim()).forEach((f) => {
|
||||
uploadExecArgs.push('-F', `${f}`);
|
||||
flags
|
||||
.split(',')
|
||||
.map((f) => f.trim())
|
||||
.forEach((f) => {
|
||||
uploadExecArgs.push('-F', f);
|
||||
});
|
||||
}
|
||||
uploadExecArgs.push('--git-service', `${gitService}`);
|
||||
uploadExecArgs.push('--git-service', gitService);
|
||||
if (handleNoReportsFound) {
|
||||
uploadExecArgs.push('--handle-no-reports-found');
|
||||
}
|
||||
if (jobCode) {
|
||||
uploadExecArgs.push('--job-code', `${jobCode}`);
|
||||
uploadExecArgs.push('--job-code', jobCode);
|
||||
}
|
||||
if (name) {
|
||||
uploadExecArgs.push('-n', `${name}`);
|
||||
uploadExecArgs.push('-n', name);
|
||||
}
|
||||
if (networkFilter) {
|
||||
uploadExecArgs.push('--network-filter', `${networkFilter}`);
|
||||
uploadExecArgs.push('--network-filter', networkFilter);
|
||||
}
|
||||
if (networkPrefix) {
|
||||
uploadExecArgs.push('--network-prefix', `${networkPrefix}`);
|
||||
uploadExecArgs.push('--network-prefix', networkPrefix);
|
||||
}
|
||||
if (overrideBranch) {
|
||||
uploadExecArgs.push('-B', `${overrideBranch}`);
|
||||
uploadExecArgs.push('-B', overrideBranch);
|
||||
}
|
||||
if (overrideBuild) {
|
||||
uploadExecArgs.push('-b', `${overrideBuild}`);
|
||||
uploadExecArgs.push('-b', overrideBuild);
|
||||
}
|
||||
if (overrideBuildUrl) {
|
||||
uploadExecArgs.push('--build-url', `${overrideBuildUrl}`);
|
||||
uploadExecArgs.push('--build-url', overrideBuildUrl);
|
||||
}
|
||||
if (overrideCommit) {
|
||||
uploadExecArgs.push('-C', `${overrideCommit}`);
|
||||
uploadExecArgs.push('-C', overrideCommit);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request' ||
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
['pull_request', 'pull_request_target'].includes(context.eventName)
|
||||
) {
|
||||
uploadExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
uploadExecArgs.push('-C', payload.pull_request.head.sha);
|
||||
}
|
||||
if (overridePr) {
|
||||
uploadExecArgs.push('-P', `${overridePr}`);
|
||||
} else if (
|
||||
`${context.eventName}` == 'pull_request_target'
|
||||
) {
|
||||
uploadExecArgs.push('-P', `${context.payload.number}`);
|
||||
uploadExecArgs.push('-P', overridePr);
|
||||
} else if (context.eventName == 'pull_request_target') {
|
||||
const payload = context.payload as PullRequestEvent;
|
||||
uploadExecArgs.push('-P', payload.number.toString());
|
||||
}
|
||||
if (plugin) {
|
||||
uploadExecArgs.push('--plugin', `${plugin}`);
|
||||
uploadExecArgs.push('--plugin', plugin);
|
||||
}
|
||||
if (plugins) {
|
||||
plugins.split(',').map((p) => p.trim()).forEach((p) => {
|
||||
uploadExecArgs.push('--plugin', `${p}`);
|
||||
plugins
|
||||
.split(',')
|
||||
.map((p) => p.trim())
|
||||
.forEach((p) => {
|
||||
uploadExecArgs.push('--plugin', p);
|
||||
});
|
||||
}
|
||||
if (reportCode) {
|
||||
uploadExecArgs.push('--report-code', `${reportCode}`);
|
||||
uploadExecArgs.push('--report-code', reportCode);
|
||||
}
|
||||
if (rootDir) {
|
||||
uploadExecArgs.push('--network-root-folder', `${rootDir}`);
|
||||
uploadExecArgs.push('--network-root-folder', rootDir);
|
||||
}
|
||||
if (searchDir) {
|
||||
uploadExecArgs.push('-s', `${searchDir}`);
|
||||
uploadExecArgs.push('-s', searchDir);
|
||||
}
|
||||
if (slug) {
|
||||
uploadExecArgs.push('-r', `${slug}`);
|
||||
uploadExecArgs.push('-r', slug);
|
||||
}
|
||||
if (workingDir) {
|
||||
uploadOptions.cwd = workingDir;
|
||||
@@ -409,4 +416,5 @@ export {
|
||||
buildGeneralExec,
|
||||
buildReportExec,
|
||||
buildUploadExec,
|
||||
getToken,
|
||||
};
|
||||
|
||||
@@ -12,7 +12,12 @@ const PLATFORMS = [
|
||||
type Platform = typeof PLATFORMS[number];
|
||||
|
||||
const setFailure = (message: string, failCi: boolean): void => {
|
||||
failCi ? core.setFailed(message) : core.warning(message);
|
||||
if (failCi) {
|
||||
core.setFailed(message);
|
||||
} else {
|
||||
core.warning(message);
|
||||
}
|
||||
|
||||
if (failCi) {
|
||||
process.exit();
|
||||
}
|
||||
|
||||
62
src/version.test.ts
Normal file
62
src/version.test.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import * as core from '@actions/core';
|
||||
import {Agent, MockAgent, setGlobalDispatcher} from 'undici';
|
||||
|
||||
import versionInfo from './version';
|
||||
|
||||
const mockAgent = new MockAgent();
|
||||
|
||||
beforeAll(() => {
|
||||
setGlobalDispatcher(mockAgent);
|
||||
mockAgent.disableNetConnect();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await mockAgent.close();
|
||||
setGlobalDispatcher(new Agent());
|
||||
});
|
||||
|
||||
describe('versionInfo', () => {
|
||||
const platform = 'linux';
|
||||
|
||||
test('should resolve requested version info', async () => {
|
||||
const version = 'latest';
|
||||
const coreInfoSpy = jest.spyOn(core, 'info');
|
||||
|
||||
mockAgent
|
||||
.get('https://cli.codecov.io')
|
||||
.intercept({
|
||||
path: `/${platform}/${version}`,
|
||||
})
|
||||
.reply(200, {
|
||||
version: 'v0.5.2',
|
||||
});
|
||||
|
||||
await versionInfo(platform, version);
|
||||
|
||||
expect(coreInfoSpy).toHaveBeenCalledTimes(2);
|
||||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version latest');
|
||||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version v0.5.2');
|
||||
});
|
||||
|
||||
test('should handle unsupported version', async () => {
|
||||
const version = 'unsupported';
|
||||
const coreInfoSpy = jest.spyOn(core, 'info');
|
||||
|
||||
mockAgent
|
||||
.get('https://cli.codecov.io')
|
||||
.intercept({
|
||||
path: `/${platform}/${version}`,
|
||||
})
|
||||
.reply(404, 'MESSAGE');
|
||||
|
||||
await versionInfo(platform, version);
|
||||
|
||||
expect(coreInfoSpy).toHaveBeenCalledTimes(2);
|
||||
expect(coreInfoSpy).toHaveBeenCalledWith('==> Running version unsupported');
|
||||
expect(coreInfoSpy).toHaveBeenCalledWith(expect.stringContaining('Could not pull latest version information'));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user