mirror of
https://github.com/codecov/codecov-action.git
synced 2025-12-09 00:26:25 +00:00
feat: pass tokenless value as branch override (#1511)
* feat: pass tokenless value as branch override instead of only passing the tokenless branch value as an environment variable we want to pass it as the branch value to the CLI * refactor: change getToken to return nullable output * fix: quick fix to use Promise resolve in getToken * test: add test for tokenless build commit exec * fix: don't overwrite overrideBranch & add comments decribing getToken
This commit is contained in:
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -42,7 +42,7 @@ 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.6.0
|
version: v0.7.3
|
||||||
verbose: true
|
verbose: true
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
token: ${{ secrets.CODECOV_TOKEN }}
|
||||||
|
|
||||||
|
|||||||
139
dist/index.js
vendored
139
dist/index.js
vendored
@@ -32341,22 +32341,16 @@ const getGitService = () => {
|
|||||||
};
|
};
|
||||||
const isPullRequestFromFork = () => {
|
const isPullRequestFromFork = () => {
|
||||||
core.info(`evenName: ${context.eventName}`);
|
core.info(`evenName: ${context.eventName}`);
|
||||||
if (`${context.eventName}` !== 'pull_request' &&
|
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
|
||||||
`${context.eventName}` !== 'pull_request_target') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const baseLabel = context.payload.pull_request.base.label;
|
const baseLabel = context.payload.pull_request.base.label;
|
||||||
const headLabel = context.payload.pull_request.head.label;
|
const headLabel = context.payload.pull_request.head.label;
|
||||||
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
|
core.info(`baseRef: ${baseLabel} | headRef: ${headLabel}`);
|
||||||
return (baseLabel.split(':')[0] !== headLabel.split(':')[0]);
|
return baseLabel.split(':')[0] !== headLabel.split(':')[0];
|
||||||
};
|
};
|
||||||
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||||
let token = core.getInput('token');
|
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');
|
let url = core.getInput('url');
|
||||||
const useOIDC = isTrue(core.getInput('use_oidc'));
|
const useOIDC = isTrue(core.getInput('use_oidc'));
|
||||||
if (useOIDC) {
|
if (useOIDC) {
|
||||||
@@ -32365,7 +32359,7 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
token = yield core.getIDToken(url);
|
token = yield core.getIDToken(url);
|
||||||
return token;
|
return Promise.resolve(token);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
setFailure(`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`, true);
|
setFailure(`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`, true);
|
||||||
@@ -32373,14 +32367,24 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
|||||||
}
|
}
|
||||||
return token;
|
return token;
|
||||||
});
|
});
|
||||||
|
const getOverrideBranch = (token) => {
|
||||||
|
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 = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||||
const commitParent = core.getInput('commit_parent');
|
const commitParent = core.getInput('commit_parent');
|
||||||
const gitService = getGitService();
|
const gitService = getGitService();
|
||||||
const overrideBranch = core.getInput('override_branch');
|
|
||||||
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 slug = core.getInput('slug');
|
const slug = core.getInput('slug');
|
||||||
const token = yield getToken();
|
const token = yield getToken();
|
||||||
|
const overrideBranch = getOverrideBranch(token);
|
||||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||||
const workingDir = core.getInput('working-directory');
|
const workingDir = core.getInput('working-directory');
|
||||||
const commitCommand = 'create-commit';
|
const commitCommand = 'create-commit';
|
||||||
@@ -32398,27 +32402,28 @@ const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function
|
|||||||
commitOptions.env.CODECOV_TOKEN = token;
|
commitOptions.env.CODECOV_TOKEN = token;
|
||||||
}
|
}
|
||||||
if (commitParent) {
|
if (commitParent) {
|
||||||
commitExecArgs.push('--parent-sha', `${commitParent}`);
|
commitExecArgs.push('--parent-sha', commitParent);
|
||||||
}
|
}
|
||||||
commitExecArgs.push('--git-service', `${gitService}`);
|
commitExecArgs.push('--git-service', gitService);
|
||||||
if (overrideBranch) {
|
if (overrideBranch) {
|
||||||
commitExecArgs.push('-B', `${overrideBranch}`);
|
commitExecArgs.push('-B', overrideBranch);
|
||||||
}
|
}
|
||||||
if (overrideCommit) {
|
if (overrideCommit) {
|
||||||
commitExecArgs.push('-C', `${overrideCommit}`);
|
commitExecArgs.push('-C', overrideCommit);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request' ||
|
else if (['pull_request', 'pull_request_target'].includes(context.eventName)) {
|
||||||
`${context.eventName}` == 'pull_request_target') {
|
const payload = context.payload;
|
||||||
commitExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
commitExecArgs.push('-C', payload.pull_request.head.sha);
|
||||||
}
|
}
|
||||||
if (overridePr) {
|
if (overridePr) {
|
||||||
commitExecArgs.push('--pr', `${overridePr}`);
|
commitExecArgs.push('--pr', overridePr);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request_target') {
|
else if (context.eventName === 'pull_request_target') {
|
||||||
commitExecArgs.push('--pr', `${context.payload.number}`);
|
const payload = context.payload;
|
||||||
|
commitExecArgs.push('--pr', payload.number.toString());
|
||||||
}
|
}
|
||||||
if (slug) {
|
if (slug) {
|
||||||
commitExecArgs.push('--slug', `${slug}`);
|
commitExecArgs.push('--slug', slug);
|
||||||
}
|
}
|
||||||
if (failCi) {
|
if (failCi) {
|
||||||
commitExecArgs.push('-Z');
|
commitExecArgs.push('-Z');
|
||||||
@@ -32434,10 +32439,10 @@ const buildGeneralExec = () => {
|
|||||||
const verbose = isTrue(core.getInput('verbose'));
|
const verbose = isTrue(core.getInput('verbose'));
|
||||||
const args = [];
|
const args = [];
|
||||||
if (codecovYmlPath) {
|
if (codecovYmlPath) {
|
||||||
args.push('--codecov-yml-path', `${codecovYmlPath}`);
|
args.push('--codecov-yml-path', codecovYmlPath);
|
||||||
}
|
}
|
||||||
if (url) {
|
if (url) {
|
||||||
args.push('--enterprise-url', `${url}`);
|
args.push('--enterprise-url', url);
|
||||||
}
|
}
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
args.push('-v');
|
args.push('-v');
|
||||||
@@ -32466,22 +32471,23 @@ const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function
|
|||||||
if (token) {
|
if (token) {
|
||||||
reportOptions.env.CODECOV_TOKEN = token;
|
reportOptions.env.CODECOV_TOKEN = token;
|
||||||
}
|
}
|
||||||
reportExecArgs.push('--git-service', `${gitService}`);
|
reportExecArgs.push('--git-service', gitService);
|
||||||
if (overrideCommit) {
|
if (overrideCommit) {
|
||||||
reportExecArgs.push('-C', `${overrideCommit}`);
|
reportExecArgs.push('-C', overrideCommit);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request' ||
|
else if (['pull_request', 'pull_request_target'].includes(context.eventName)) {
|
||||||
`${context.eventName}` == 'pull_request_target') {
|
const payload = context.payload;
|
||||||
reportExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
reportExecArgs.push('-C', payload.pull_request.head.sha);
|
||||||
}
|
}
|
||||||
if (overridePr) {
|
if (overridePr) {
|
||||||
reportExecArgs.push('-P', `${overridePr}`);
|
reportExecArgs.push('-P', overridePr);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request_target') {
|
else if (context.eventName == 'pull_request_target') {
|
||||||
reportExecArgs.push('-P', `${context.payload.number}`);
|
const payload = context.payload;
|
||||||
|
reportExecArgs.push('-P', payload.number.toString());
|
||||||
}
|
}
|
||||||
if (slug) {
|
if (slug) {
|
||||||
reportExecArgs.push('--slug', `${slug}`);
|
reportExecArgs.push('--slug', slug);
|
||||||
}
|
}
|
||||||
if (failCi) {
|
if (failCi) {
|
||||||
reportExecArgs.push('-Z');
|
reportExecArgs.push('-Z');
|
||||||
@@ -32559,83 +32565,94 @@ const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function
|
|||||||
uploadExecArgs.push('-e', envVarsArg.join(','));
|
uploadExecArgs.push('-e', envVarsArg.join(','));
|
||||||
}
|
}
|
||||||
if (exclude) {
|
if (exclude) {
|
||||||
uploadExecArgs.push('--exclude', `${exclude}`);
|
uploadExecArgs.push('--exclude', exclude);
|
||||||
}
|
}
|
||||||
if (failCi) {
|
if (failCi) {
|
||||||
uploadExecArgs.push('-Z');
|
uploadExecArgs.push('-Z');
|
||||||
}
|
}
|
||||||
if (file) {
|
if (file) {
|
||||||
uploadExecArgs.push('-f', `${file}`);
|
uploadExecArgs.push('-f', file);
|
||||||
}
|
}
|
||||||
if (files) {
|
if (files) {
|
||||||
files.split(',').map((f) => f.trim()).forEach((f) => {
|
files
|
||||||
if (f.length > 0) { // this handles trailing commas
|
.split(',')
|
||||||
uploadExecArgs.push('-f', `${f}`);
|
.map((f) => f.trim())
|
||||||
|
.forEach((f) => {
|
||||||
|
if (f.length > 0) {
|
||||||
|
// this handles trailing commas
|
||||||
|
uploadExecArgs.push('-f', f);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (flags) {
|
if (flags) {
|
||||||
flags.split(',').map((f) => f.trim()).forEach((f) => {
|
flags
|
||||||
uploadExecArgs.push('-F', `${f}`);
|
.split(',')
|
||||||
|
.map((f) => f.trim())
|
||||||
|
.forEach((f) => {
|
||||||
|
uploadExecArgs.push('-F', f);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
uploadExecArgs.push('--git-service', `${gitService}`);
|
uploadExecArgs.push('--git-service', gitService);
|
||||||
if (handleNoReportsFound) {
|
if (handleNoReportsFound) {
|
||||||
uploadExecArgs.push('--handle-no-reports-found');
|
uploadExecArgs.push('--handle-no-reports-found');
|
||||||
}
|
}
|
||||||
if (jobCode) {
|
if (jobCode) {
|
||||||
uploadExecArgs.push('--job-code', `${jobCode}`);
|
uploadExecArgs.push('--job-code', jobCode);
|
||||||
}
|
}
|
||||||
if (name) {
|
if (name) {
|
||||||
uploadExecArgs.push('-n', `${name}`);
|
uploadExecArgs.push('-n', name);
|
||||||
}
|
}
|
||||||
if (networkFilter) {
|
if (networkFilter) {
|
||||||
uploadExecArgs.push('--network-filter', `${networkFilter}`);
|
uploadExecArgs.push('--network-filter', networkFilter);
|
||||||
}
|
}
|
||||||
if (networkPrefix) {
|
if (networkPrefix) {
|
||||||
uploadExecArgs.push('--network-prefix', `${networkPrefix}`);
|
uploadExecArgs.push('--network-prefix', networkPrefix);
|
||||||
}
|
}
|
||||||
if (overrideBranch) {
|
if (overrideBranch) {
|
||||||
uploadExecArgs.push('-B', `${overrideBranch}`);
|
uploadExecArgs.push('-B', overrideBranch);
|
||||||
}
|
}
|
||||||
if (overrideBuild) {
|
if (overrideBuild) {
|
||||||
uploadExecArgs.push('-b', `${overrideBuild}`);
|
uploadExecArgs.push('-b', overrideBuild);
|
||||||
}
|
}
|
||||||
if (overrideBuildUrl) {
|
if (overrideBuildUrl) {
|
||||||
uploadExecArgs.push('--build-url', `${overrideBuildUrl}`);
|
uploadExecArgs.push('--build-url', overrideBuildUrl);
|
||||||
}
|
}
|
||||||
if (overrideCommit) {
|
if (overrideCommit) {
|
||||||
uploadExecArgs.push('-C', `${overrideCommit}`);
|
uploadExecArgs.push('-C', overrideCommit);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request' ||
|
else if (['pull_request', 'pull_request_target'].includes(context.eventName)) {
|
||||||
`${context.eventName}` == 'pull_request_target') {
|
const payload = context.payload;
|
||||||
uploadExecArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
uploadExecArgs.push('-C', payload.pull_request.head.sha);
|
||||||
}
|
}
|
||||||
if (overridePr) {
|
if (overridePr) {
|
||||||
uploadExecArgs.push('-P', `${overridePr}`);
|
uploadExecArgs.push('-P', overridePr);
|
||||||
}
|
}
|
||||||
else if (`${context.eventName}` == 'pull_request_target') {
|
else if (context.eventName == 'pull_request_target') {
|
||||||
uploadExecArgs.push('-P', `${context.payload.number}`);
|
const payload = context.payload;
|
||||||
|
uploadExecArgs.push('-P', payload.number.toString());
|
||||||
}
|
}
|
||||||
if (plugin) {
|
if (plugin) {
|
||||||
uploadExecArgs.push('--plugin', `${plugin}`);
|
uploadExecArgs.push('--plugin', plugin);
|
||||||
}
|
}
|
||||||
if (plugins) {
|
if (plugins) {
|
||||||
plugins.split(',').map((p) => p.trim()).forEach((p) => {
|
plugins
|
||||||
uploadExecArgs.push('--plugin', `${p}`);
|
.split(',')
|
||||||
|
.map((p) => p.trim())
|
||||||
|
.forEach((p) => {
|
||||||
|
uploadExecArgs.push('--plugin', p);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (reportCode) {
|
if (reportCode) {
|
||||||
uploadExecArgs.push('--report-code', `${reportCode}`);
|
uploadExecArgs.push('--report-code', reportCode);
|
||||||
}
|
}
|
||||||
if (rootDir) {
|
if (rootDir) {
|
||||||
uploadExecArgs.push('--network-root-folder', `${rootDir}`);
|
uploadExecArgs.push('--network-root-folder', rootDir);
|
||||||
}
|
}
|
||||||
if (searchDir) {
|
if (searchDir) {
|
||||||
uploadExecArgs.push('-s', `${searchDir}`);
|
uploadExecArgs.push('-s', searchDir);
|
||||||
}
|
}
|
||||||
if (slug) {
|
if (slug) {
|
||||||
uploadExecArgs.push('-r', `${slug}`);
|
uploadExecArgs.push('-r', slug);
|
||||||
}
|
}
|
||||||
if (workingDir) {
|
if (workingDir) {
|
||||||
uploadOptions.cwd = workingDir;
|
uploadOptions.cwd = workingDir;
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
@@ -5,6 +5,7 @@ import {
|
|||||||
buildGeneralExec,
|
buildGeneralExec,
|
||||||
buildReportExec,
|
buildReportExec,
|
||||||
buildUploadExec,
|
buildUploadExec,
|
||||||
|
getToken,
|
||||||
} from './buildExec';
|
} from './buildExec';
|
||||||
|
|
||||||
const context = github.context;
|
const context = github.context;
|
||||||
@@ -213,7 +214,7 @@ test('report args using context', async () => {
|
|||||||
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 expectedArgs : string[] = [
|
const expectedArgs: string[] = [
|
||||||
'--git-service',
|
'--git-service',
|
||||||
'github',
|
'github',
|
||||||
];
|
];
|
||||||
@@ -271,12 +272,18 @@ test('commit args', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('commit args using context', async () => {
|
test('commit args using context', async () => {
|
||||||
const expectedArgs :string[] = [
|
const expectedArgs: string[] = [
|
||||||
'--git-service',
|
'--git-service',
|
||||||
'github',
|
'github',
|
||||||
];
|
];
|
||||||
|
|
||||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
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') {
|
if (context.eventName == 'pull_request') {
|
||||||
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
|
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 () => {
|
test('commit args using github server url', async () => {
|
||||||
const expectedArgs :string[] = [
|
const expectedArgs: string[] = [
|
||||||
'--git-service',
|
'--git-service',
|
||||||
'github_enterprise',
|
'github_enterprise',
|
||||||
];
|
];
|
||||||
@@ -297,13 +304,65 @@ test('commit args using github server url', async () => {
|
|||||||
process.env.GITHUB_SERVER_URL = 'https://example.com';
|
process.env.GITHUB_SERVER_URL = 'https://example.com';
|
||||||
|
|
||||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
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') {
|
if (context.eventName == 'pull_request') {
|
||||||
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
|
expectedArgs.push('-C', `${context.payload.pull_request?.head.sha}`);
|
||||||
}
|
}
|
||||||
if (context.eventName == 'pull_request_target') {
|
if (context.eventName == 'pull_request_target') {
|
||||||
expectedArgs.push('-P', `${context.payload.number}`);
|
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(commitExecArgs).toEqual(expectedArgs);
|
||||||
expect(commitCommand).toEqual('create-commit');
|
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('');
|
||||||
|
});
|
||||||
|
|||||||
@@ -45,11 +45,6 @@ const isPullRequestFromFork = (): boolean => {
|
|||||||
|
|
||||||
const getToken = async (): Promise<string> => {
|
const getToken = async (): Promise<string> => {
|
||||||
let token = core.getInput('token');
|
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');
|
let url = core.getInput('url');
|
||||||
const useOIDC = isTrue(core.getInput('use_oidc'));
|
const useOIDC = isTrue(core.getInput('use_oidc'));
|
||||||
if (useOIDC) {
|
if (useOIDC) {
|
||||||
@@ -58,7 +53,7 @@ const getToken = async (): Promise<string> => {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
token = await core.getIDToken(url);
|
token = await core.getIDToken(url);
|
||||||
return token;
|
return Promise.resolve(token);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setFailure(
|
setFailure(
|
||||||
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
|
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
|
||||||
@@ -69,6 +64,17 @@ const getToken = async (): Promise<string> => {
|
|||||||
return token;
|
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<{
|
const buildCommitExec = async (): Promise<{
|
||||||
commitExecArgs: any[];
|
commitExecArgs: any[];
|
||||||
commitOptions: any;
|
commitOptions: any;
|
||||||
@@ -76,11 +82,11 @@ const buildCommitExec = async (): Promise<{
|
|||||||
}> => {
|
}> => {
|
||||||
const commitParent = core.getInput('commit_parent');
|
const commitParent = core.getInput('commit_parent');
|
||||||
const gitService = getGitService();
|
const gitService = getGitService();
|
||||||
const overrideBranch = core.getInput('override_branch');
|
|
||||||
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 slug = core.getInput('slug');
|
const slug = core.getInput('slug');
|
||||||
const token = await getToken();
|
const token = await getToken();
|
||||||
|
const overrideBranch = getOverrideBranch(token);
|
||||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||||
const workingDir = core.getInput('working-directory');
|
const workingDir = core.getInput('working-directory');
|
||||||
|
|
||||||
@@ -404,4 +410,11 @@ const buildUploadExec = async (): Promise<{
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export {buildCommitExec, buildGeneralExec, buildReportExec, buildUploadExec};
|
|
||||||
|
export {
|
||||||
|
buildCommitExec,
|
||||||
|
buildGeneralExec,
|
||||||
|
buildReportExec,
|
||||||
|
buildUploadExec,
|
||||||
|
getToken,
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user