mirror of
https://github.com/codecov/codecov-action.git
synced 2026-02-09 12:37:26 +00:00
fix: allow for oidc token
This commit is contained in:
parent
3a20752bdd
commit
9f3268e2da
7 changed files with 304 additions and 244 deletions
|
|
@ -17,6 +17,7 @@
|
|||
"@typescript-eslint"
|
||||
],
|
||||
"rules": {
|
||||
"max-len": ["error", { "code": 120 }],
|
||||
"linebreak-style": 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,9 @@ inputs:
|
|||
use_legacy_upload_endpoint:
|
||||
description: 'Use the legacy upload endpoint'
|
||||
required: false
|
||||
use_oidc:
|
||||
description: 'Use OIDC instead of token. This will ignore any token supplied'
|
||||
required: false
|
||||
verbose:
|
||||
description: 'Specify whether the Codecov output should be verbose'
|
||||
required: false
|
||||
|
|
|
|||
309
dist/index.js
vendored
309
dist/index.js
vendored
|
|
@ -32452,8 +32452,94 @@ var exec = __nccwpck_require__(1514);
|
|||
var core = __nccwpck_require__(2186);
|
||||
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
|
||||
var github = __nccwpck_require__(5438);
|
||||
;// CONCATENATED MODULE: ./src/helpers.ts
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const PLATFORMS = [
|
||||
'linux',
|
||||
'macos',
|
||||
'windows',
|
||||
'alpine',
|
||||
'linux-arm64',
|
||||
'alpine-arm64',
|
||||
];
|
||||
const setFailure = (message, failCi) => {
|
||||
failCi ? core.setFailed(message) : core.warning(message);
|
||||
if (failCi) {
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
const getUploaderName = (platform) => {
|
||||
if (isWindows(platform)) {
|
||||
return 'codecov.exe';
|
||||
}
|
||||
else {
|
||||
return 'codecov';
|
||||
}
|
||||
};
|
||||
const isValidPlatform = (platform) => {
|
||||
return PLATFORMS.includes(platform);
|
||||
};
|
||||
const isWindows = (platform) => {
|
||||
return platform === 'windows';
|
||||
};
|
||||
const getPlatform = (os) => {
|
||||
var _a;
|
||||
if (isValidPlatform(os)) {
|
||||
core.info(`==> ${os} OS provided`);
|
||||
return os;
|
||||
}
|
||||
const platform = (_a = process.env.RUNNER_OS) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
||||
if (isValidPlatform(platform)) {
|
||||
core.info(`==> ${platform} OS detected`);
|
||||
return platform;
|
||||
}
|
||||
core.info('==> Could not detect OS or provided OS is invalid. Defaulting to linux');
|
||||
return 'linux';
|
||||
};
|
||||
const getBaseUrl = (platform, version) => {
|
||||
return `https://cli.codecov.io/${version}/${platform}/${getUploaderName(platform)}`;
|
||||
};
|
||||
const getCommand = (filename, generalArgs, command) => {
|
||||
const fullCommand = [filename, ...generalArgs, command];
|
||||
core.info(`==> Running command '${fullCommand.join(' ')}'`);
|
||||
return fullCommand;
|
||||
};
|
||||
const setSafeDirectory = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const command = ([
|
||||
'git',
|
||||
'config',
|
||||
'--global',
|
||||
'--add',
|
||||
'safe.directory',
|
||||
`${process.env['GITHUB_WORKSPACE']}`,
|
||||
].join(' '));
|
||||
core.info(`==> Running ${command}`);
|
||||
yield exec.exec(command);
|
||||
});
|
||||
|
||||
|
||||
;// CONCATENATED MODULE: ./src/buildExec.ts
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
var buildExec_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
const context = github.context;
|
||||
|
|
@ -32465,14 +32551,32 @@ const isTrue = (variable) => {
|
|||
lowercase === 'y' ||
|
||||
lowercase === 'yes');
|
||||
};
|
||||
const buildCommitExec = () => {
|
||||
const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||
let token = core.getInput('token');
|
||||
let url = core.getInput('url');
|
||||
const useOIDC = isTrue(core.getInput('use_oidc'));
|
||||
if (useOIDC) {
|
||||
if (!url) {
|
||||
url = 'https://codecov.io';
|
||||
}
|
||||
try {
|
||||
token = yield core.getIDToken(url);
|
||||
return token;
|
||||
}
|
||||
catch (err) {
|
||||
setFailure(`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`, true);
|
||||
}
|
||||
}
|
||||
return token;
|
||||
});
|
||||
const buildCommitExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||
const commitParent = core.getInput('commit_parent');
|
||||
const gitService = core.getInput('git_service');
|
||||
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 token = yield getToken();
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
const commitCommand = 'create-commit';
|
||||
|
|
@ -32519,7 +32623,7 @@ const buildCommitExec = () => {
|
|||
commitOptions.cwd = workingDir;
|
||||
}
|
||||
return { commitExecArgs, commitOptions, commitCommand };
|
||||
};
|
||||
});
|
||||
const buildGeneralExec = () => {
|
||||
const codecovYmlPath = core.getInput('codecov_yml_path');
|
||||
const url = core.getInput('url');
|
||||
|
|
@ -32536,12 +32640,12 @@ const buildGeneralExec = () => {
|
|||
}
|
||||
return { args, verbose };
|
||||
};
|
||||
const buildReportExec = () => {
|
||||
const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||
const gitService = core.getInput('git_service');
|
||||
const overrideCommit = core.getInput('override_commit');
|
||||
const overridePr = core.getInput('override_pr');
|
||||
const slug = core.getInput('slug');
|
||||
const token = core.getInput('token');
|
||||
const token = yield getToken();
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
const reportCommand = 'create-report';
|
||||
|
|
@ -32582,8 +32686,8 @@ const buildReportExec = () => {
|
|||
reportOptions.cwd = workingDir;
|
||||
}
|
||||
return { reportExecArgs, reportOptions, reportCommand };
|
||||
};
|
||||
const buildUploadExec = () => {
|
||||
});
|
||||
const buildUploadExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
|
||||
const disableFileFixes = isTrue(core.getInput('disable_file_fixes'));
|
||||
const disableSafeDirectory = isTrue(core.getInput('disable_safe_directory'));
|
||||
const disableSearch = isTrue(core.getInput('disable_search'));
|
||||
|
|
@ -32610,7 +32714,7 @@ const buildUploadExec = () => {
|
|||
const rootDir = core.getInput('root_dir');
|
||||
const searchDir = core.getInput('directory');
|
||||
const slug = core.getInput('slug');
|
||||
const token = core.getInput('token');
|
||||
const token = yield getToken();
|
||||
let uploaderVersion = core.getInput('version');
|
||||
const useLegacyUploadEndpoint = isTrue(core.getInput('use_legacy_upload_endpoint'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
|
@ -32737,82 +32841,6 @@ const buildUploadExec = () => {
|
|||
uploaderVersion,
|
||||
uploadCommand,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
;// CONCATENATED MODULE: ./src/helpers.ts
|
||||
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
const PLATFORMS = [
|
||||
'linux',
|
||||
'macos',
|
||||
'windows',
|
||||
'alpine',
|
||||
'linux-arm64',
|
||||
'alpine-arm64',
|
||||
];
|
||||
const setFailure = (message, failCi) => {
|
||||
failCi ? core.setFailed(message) : core.warning(message);
|
||||
if (failCi) {
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
const getUploaderName = (platform) => {
|
||||
if (isWindows(platform)) {
|
||||
return 'codecov.exe';
|
||||
}
|
||||
else {
|
||||
return 'codecov';
|
||||
}
|
||||
};
|
||||
const isValidPlatform = (platform) => {
|
||||
return PLATFORMS.includes(platform);
|
||||
};
|
||||
const isWindows = (platform) => {
|
||||
return platform === 'windows';
|
||||
};
|
||||
const getPlatform = (os) => {
|
||||
var _a;
|
||||
if (isValidPlatform(os)) {
|
||||
core.info(`==> ${os} OS provided`);
|
||||
return os;
|
||||
}
|
||||
const platform = (_a = process.env.RUNNER_OS) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
||||
if (isValidPlatform(platform)) {
|
||||
core.info(`==> ${platform} OS detected`);
|
||||
return platform;
|
||||
}
|
||||
core.info('==> Could not detect OS or provided OS is invalid. Defaulting to linux');
|
||||
return 'linux';
|
||||
};
|
||||
const getBaseUrl = (platform, version) => {
|
||||
return `https://cli.codecov.io/${version}/${platform}/${getUploaderName(platform)}`;
|
||||
};
|
||||
const getCommand = (filename, generalArgs, command) => {
|
||||
const fullCommand = [filename, ...generalArgs, command];
|
||||
core.info(`==> Running command '${fullCommand.join(' ')}'`);
|
||||
return fullCommand;
|
||||
};
|
||||
const setSafeDirectory = () => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const command = ([
|
||||
'git',
|
||||
'config',
|
||||
'--global',
|
||||
'--add',
|
||||
'safe.directory',
|
||||
`${process.env['GITHUB_WORKSPACE']}`,
|
||||
].join(' '));
|
||||
core.info(`==> Running ${command}`);
|
||||
yield exec.exec(command);
|
||||
});
|
||||
|
||||
|
||||
|
|
@ -32957,68 +32985,71 @@ var src_awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|||
|
||||
|
||||
let failCi;
|
||||
try {
|
||||
const { commitExecArgs, commitOptions, commitCommand } = buildCommitExec();
|
||||
const { reportExecArgs, reportOptions, reportCommand } = buildReportExec();
|
||||
const { uploadExecArgs, uploadOptions, disableSafeDirectory, failCi, os, uploaderVersion, uploadCommand, } = buildUploadExec();
|
||||
const { args, verbose } = buildGeneralExec();
|
||||
const platform = getPlatform(os);
|
||||
const filename = external_path_.join(__dirname, getUploaderName(platform));
|
||||
external_https_.get(getBaseUrl(platform, uploaderVersion), (res) => {
|
||||
// Image will be stored at this path
|
||||
const filePath = external_fs_.createWriteStream(filename);
|
||||
res.pipe(filePath);
|
||||
filePath
|
||||
.on('error', (err) => {
|
||||
setFailure(`Codecov: Failed to write uploader binary: ${err.message}`, true);
|
||||
}).on('finish', () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
filePath.close();
|
||||
yield validate(filename, platform, uploaderVersion, verbose, failCi);
|
||||
yield version(platform, uploaderVersion);
|
||||
yield external_fs_.chmodSync(filename, '777');
|
||||
if (!disableSafeDirectory) {
|
||||
yield setSafeDirectory();
|
||||
}
|
||||
const unlink = () => {
|
||||
external_fs_.unlink(filename, (err) => {
|
||||
if (err) {
|
||||
setFailure(`Codecov: Could not unlink uploader: ${err.message}`, failCi);
|
||||
}
|
||||
const run = () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
try {
|
||||
const { commitExecArgs, commitOptions, commitCommand } = yield buildCommitExec();
|
||||
const { reportExecArgs, reportOptions, reportCommand } = yield buildReportExec();
|
||||
const { uploadExecArgs, uploadOptions, disableSafeDirectory, failCi, os, uploaderVersion, uploadCommand, } = yield buildUploadExec();
|
||||
const { args, verbose } = buildGeneralExec();
|
||||
const platform = getPlatform(os);
|
||||
const filename = external_path_.join(__dirname, getUploaderName(platform));
|
||||
external_https_.get(getBaseUrl(platform, uploaderVersion), (res) => {
|
||||
// Image will be stored at this path
|
||||
const filePath = external_fs_.createWriteStream(filename);
|
||||
res.pipe(filePath);
|
||||
filePath
|
||||
.on('error', (err) => {
|
||||
setFailure(`Codecov: Failed to write uploader binary: ${err.message}`, true);
|
||||
}).on('finish', () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
filePath.close();
|
||||
yield validate(filename, platform, uploaderVersion, verbose, failCi);
|
||||
yield version(platform, uploaderVersion);
|
||||
yield external_fs_.chmodSync(filename, '777');
|
||||
if (!disableSafeDirectory) {
|
||||
yield setSafeDirectory();
|
||||
}
|
||||
const unlink = () => {
|
||||
external_fs_.unlink(filename, (err) => {
|
||||
if (err) {
|
||||
setFailure(`Codecov: Could not unlink uploader: ${err.message}`, failCi);
|
||||
}
|
||||
});
|
||||
};
|
||||
const doUpload = () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
yield exec.exec(getCommand(filename, args, uploadCommand).join(' '), uploadExecArgs, uploadOptions)
|
||||
.catch((err) => {
|
||||
setFailure(`Codecov:
|
||||
Failed to properly upload report: ${err.message}`, failCi);
|
||||
});
|
||||
});
|
||||
};
|
||||
const doUpload = () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
yield exec.exec(getCommand(filename, args, uploadCommand).join(' '), uploadExecArgs, uploadOptions)
|
||||
.catch((err) => {
|
||||
setFailure(`Codecov:
|
||||
Failed to properly upload report: ${err.message}`, failCi);
|
||||
const createReport = () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
yield exec.exec(getCommand(filename, args, reportCommand).join(' '), reportExecArgs, reportOptions)
|
||||
.then((exitCode) => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
if (exitCode == 0) {
|
||||
yield doUpload();
|
||||
}
|
||||
})).catch((err) => {
|
||||
setFailure(`Codecov:
|
||||
Failed to properly create report: ${err.message}`, failCi);
|
||||
});
|
||||
});
|
||||
});
|
||||
const createReport = () => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
yield exec.exec(getCommand(filename, args, reportCommand).join(' '), reportExecArgs, reportOptions)
|
||||
yield exec.exec(getCommand(filename, args, commitCommand).join(' '), commitExecArgs, commitOptions)
|
||||
.then((exitCode) => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
if (exitCode == 0) {
|
||||
yield doUpload();
|
||||
yield createReport();
|
||||
}
|
||||
unlink();
|
||||
})).catch((err) => {
|
||||
setFailure(`Codecov:
|
||||
Failed to properly create report: ${err.message}`, failCi);
|
||||
setFailure(`Codecov: Failed to properly create commit: ${err.message}`, failCi);
|
||||
});
|
||||
});
|
||||
yield exec.exec(getCommand(filename, args, commitCommand).join(' '), commitExecArgs, commitOptions)
|
||||
.then((exitCode) => src_awaiter(void 0, void 0, void 0, function* () {
|
||||
if (exitCode == 0) {
|
||||
yield createReport();
|
||||
}
|
||||
unlink();
|
||||
})).catch((err) => {
|
||||
setFailure(`Codecov: Failed to properly create commit: ${err.message}`, failCi);
|
||||
});
|
||||
}));
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
setFailure(`Codecov: Encountered an unexpected error ${err.message}`, failCi);
|
||||
}
|
||||
}));
|
||||
});
|
||||
}
|
||||
catch (err) {
|
||||
setFailure(`Codecov: Encountered an unexpected error ${err.message}`, failCi);
|
||||
}
|
||||
});
|
||||
run();
|
||||
|
||||
})();
|
||||
|
||||
|
|
|
|||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
|
@ -10,7 +10,7 @@ import {
|
|||
|
||||
const context = github.context;
|
||||
|
||||
test('general args', () => {
|
||||
test('general args', async () => {
|
||||
const envs = {
|
||||
codecov_yml_path: 'dev/codecov.yml',
|
||||
url: 'https://codecov.enterprise.com',
|
||||
|
|
@ -20,7 +20,7 @@ test('general args', () => {
|
|||
process.env['INPUT_' + env.toUpperCase()] = envs[env];
|
||||
}
|
||||
|
||||
const {args, verbose} = buildGeneralExec();
|
||||
const {args, verbose} = await buildGeneralExec();
|
||||
|
||||
expect(args).toEqual(
|
||||
expect.arrayContaining([
|
||||
|
|
@ -36,13 +36,12 @@ test('general args', () => {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
test('upload args using context', () => {
|
||||
test('upload args using context', async () => {
|
||||
const expectedArgs = [
|
||||
'--git-service',
|
||||
'github',
|
||||
];
|
||||
const {uploadExecArgs, uploadCommand} = buildUploadExec();
|
||||
const {uploadExecArgs, uploadCommand} = await buildUploadExec();
|
||||
if (context.eventName == 'pull_request') {
|
||||
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
}
|
||||
|
|
@ -54,7 +53,7 @@ test('upload args using context', () => {
|
|||
expect(uploadCommand).toEqual('do-upload');
|
||||
});
|
||||
|
||||
test('upload args', () => {
|
||||
test('upload args', async () => {
|
||||
const envs = {
|
||||
'codecov_yml_path': 'dev/codecov.yml',
|
||||
'commit_parent': 'fakeparentcommit',
|
||||
|
|
@ -94,7 +93,7 @@ test('upload args', () => {
|
|||
process.env['INPUT_' + env.toUpperCase()] = envs[env];
|
||||
}
|
||||
|
||||
const {uploadExecArgs, uploadCommand} = buildUploadExec();
|
||||
const {uploadExecArgs, uploadCommand} = await buildUploadExec();
|
||||
const expectedArgs = [
|
||||
'--disable-file-fixes',
|
||||
'--disable-search',
|
||||
|
|
@ -156,7 +155,7 @@ test('upload args', () => {
|
|||
});
|
||||
|
||||
|
||||
test('report args', () => {
|
||||
test('report args', async () => {
|
||||
const envs = {
|
||||
git_service: 'github_enterprise',
|
||||
override_commit: '9caabca5474b49de74ef5667deabaf74cdacc244',
|
||||
|
|
@ -169,7 +168,7 @@ test('report args', () => {
|
|||
process.env['INPUT_' + env.toUpperCase()] = envs[env];
|
||||
}
|
||||
|
||||
const {reportExecArgs, reportCommand} = buildReportExec();
|
||||
const {reportExecArgs, reportCommand} = await buildReportExec();
|
||||
|
||||
const expectedArgs = [
|
||||
'--git-service',
|
||||
|
|
@ -191,7 +190,7 @@ test('report args', () => {
|
|||
});
|
||||
|
||||
|
||||
test('report args using context', () => {
|
||||
test('report args using context', async () => {
|
||||
const envs = {
|
||||
token: 'd3859757-ab80-4664-924d-aef22fa7557b',
|
||||
};
|
||||
|
|
@ -206,7 +205,7 @@ test('report args using context', () => {
|
|||
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
}
|
||||
|
||||
const {reportExecArgs, reportCommand} = buildReportExec();
|
||||
const {reportExecArgs, reportCommand} = await buildReportExec();
|
||||
|
||||
expect(reportExecArgs).toEqual(expectedArgs);
|
||||
expect(reportCommand).toEqual('create-report');
|
||||
|
|
@ -216,7 +215,7 @@ test('report args using context', () => {
|
|||
});
|
||||
|
||||
|
||||
test('commit args', () => {
|
||||
test('commit args', async () => {
|
||||
const envs = {
|
||||
git_service: 'github_enterprise',
|
||||
commit_parent: '83231650328f11695dfb754ca0f540516f188d27',
|
||||
|
|
@ -231,7 +230,7 @@ test('commit args', () => {
|
|||
process.env['INPUT_' + env.toUpperCase()] = envs[env];
|
||||
}
|
||||
|
||||
const {commitExecArgs, commitCommand} = buildCommitExec();
|
||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
||||
const expectedArgs = [
|
||||
'--parent-sha',
|
||||
'83231650328f11695dfb754ca0f540516f188d27',
|
||||
|
|
@ -255,13 +254,13 @@ test('commit args', () => {
|
|||
}
|
||||
});
|
||||
|
||||
test('commit args using context', () => {
|
||||
test('commit args using context', async () => {
|
||||
const expectedArgs :string[] = [
|
||||
'--git-service',
|
||||
'github',
|
||||
];
|
||||
|
||||
const {commitExecArgs, commitCommand} = buildCommitExec();
|
||||
const {commitExecArgs, commitCommand} = await buildCommitExec();
|
||||
if (context.eventName == 'pull_request') {
|
||||
expectedArgs.push('-C', `${context.payload.pull_request.head.sha}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
|
||||
import {setFailure} from './helpers';
|
||||
|
||||
const context = github.context;
|
||||
|
||||
|
|
@ -17,15 +18,36 @@ const isTrue = (variable) => {
|
|||
);
|
||||
};
|
||||
|
||||
const getToken = async () => {
|
||||
let token = core.getInput('token');
|
||||
let url = core.getInput('url');
|
||||
const useOIDC = isTrue(core.getInput('use_oidc'));
|
||||
|
||||
const buildCommitExec = () => {
|
||||
if (useOIDC) {
|
||||
if (!url) {
|
||||
url = 'https://codecov.io';
|
||||
}
|
||||
try {
|
||||
token = await core.getIDToken(url);
|
||||
return token;
|
||||
} catch (err) {
|
||||
setFailure(
|
||||
`Codecov: Failed to get OIDC token with url: ${url}. ${err.message}`,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
return token;
|
||||
};
|
||||
|
||||
const buildCommitExec = async () => {
|
||||
const commitParent = core.getInput('commit_parent');
|
||||
const gitService = core.getInput('git_service');
|
||||
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 token = await getToken();
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
||||
|
|
@ -101,12 +123,12 @@ const buildGeneralExec = () => {
|
|||
return {args, verbose};
|
||||
};
|
||||
|
||||
const buildReportExec = () => {
|
||||
const buildReportExec = async () => {
|
||||
const gitService = core.getInput('git_service');
|
||||
const overrideCommit = core.getInput('override_commit');
|
||||
const overridePr = core.getInput('override_pr');
|
||||
const slug = core.getInput('slug');
|
||||
const token = core.getInput('token');
|
||||
const token = await getToken();
|
||||
const failCi = isTrue(core.getInput('fail_ci_if_error'));
|
||||
const workingDir = core.getInput('working-directory');
|
||||
|
||||
|
|
@ -158,7 +180,7 @@ const buildReportExec = () => {
|
|||
return {reportExecArgs, reportOptions, reportCommand};
|
||||
};
|
||||
|
||||
const buildUploadExec = () => {
|
||||
const buildUploadExec = async () => {
|
||||
const disableFileFixes = isTrue(core.getInput('disable_file_fixes'));
|
||||
const disableSafeDirectory = isTrue(core.getInput('disable_safe_directory'));
|
||||
const disableSearch = isTrue(core.getInput('disable_search'));
|
||||
|
|
@ -185,7 +207,7 @@ const buildUploadExec = () => {
|
|||
const rootDir = core.getInput('root_dir');
|
||||
const searchDir = core.getInput('directory');
|
||||
const slug = core.getInput('slug');
|
||||
const token = core.getInput('token');
|
||||
const token = await getToken();
|
||||
let uploaderVersion = core.getInput('version');
|
||||
const useLegacyUploadEndpoint = isTrue(
|
||||
core.getInput('use_legacy_upload_endpoint'),
|
||||
|
|
|
|||
170
src/index.ts
170
src/index.ts
|
|
@ -24,102 +24,106 @@ import versionInfo from './version';
|
|||
|
||||
let failCi;
|
||||
|
||||
try {
|
||||
const {commitExecArgs, commitOptions, commitCommand} = buildCommitExec();
|
||||
const {reportExecArgs, reportOptions, reportCommand} = buildReportExec();
|
||||
const {
|
||||
uploadExecArgs,
|
||||
uploadOptions,
|
||||
disableSafeDirectory,
|
||||
failCi,
|
||||
os,
|
||||
uploaderVersion,
|
||||
uploadCommand,
|
||||
} = buildUploadExec();
|
||||
const {args, verbose} = buildGeneralExec();
|
||||
const run = async () => {
|
||||
try {
|
||||
const {commitExecArgs, commitOptions, commitCommand} = await buildCommitExec();
|
||||
const {reportExecArgs, reportOptions, reportCommand} = await buildReportExec();
|
||||
const {
|
||||
uploadExecArgs,
|
||||
uploadOptions,
|
||||
disableSafeDirectory,
|
||||
failCi,
|
||||
os,
|
||||
uploaderVersion,
|
||||
uploadCommand,
|
||||
} = await buildUploadExec();
|
||||
const {args, verbose} = buildGeneralExec();
|
||||
|
||||
const platform = getPlatform(os);
|
||||
const platform = getPlatform(os);
|
||||
|
||||
const filename = path.join( __dirname, getUploaderName(platform));
|
||||
https.get(getBaseUrl(platform, uploaderVersion), (res) => {
|
||||
// Image will be stored at this path
|
||||
const filePath = fs.createWriteStream(filename);
|
||||
res.pipe(filePath);
|
||||
filePath
|
||||
.on('error', (err) => {
|
||||
setFailure(
|
||||
`Codecov: Failed to write uploader binary: ${err.message}`,
|
||||
true,
|
||||
);
|
||||
}).on('finish', async () => {
|
||||
filePath.close();
|
||||
const filename = path.join( __dirname, getUploaderName(platform));
|
||||
https.get(getBaseUrl(platform, uploaderVersion), (res) => {
|
||||
// Image will be stored at this path
|
||||
const filePath = fs.createWriteStream(filename);
|
||||
res.pipe(filePath);
|
||||
filePath
|
||||
.on('error', (err) => {
|
||||
setFailure(
|
||||
`Codecov: Failed to write uploader binary: ${err.message}`,
|
||||
true,
|
||||
);
|
||||
}).on('finish', async () => {
|
||||
filePath.close();
|
||||
|
||||
await verify(filename, platform, uploaderVersion, verbose, failCi);
|
||||
await versionInfo(platform, uploaderVersion);
|
||||
await fs.chmodSync(filename, '777');
|
||||
if (!disableSafeDirectory) {
|
||||
await setSafeDirectory();
|
||||
}
|
||||
await verify(filename, platform, uploaderVersion, verbose, failCi);
|
||||
await versionInfo(platform, uploaderVersion);
|
||||
await fs.chmodSync(filename, '777');
|
||||
if (!disableSafeDirectory) {
|
||||
await setSafeDirectory();
|
||||
}
|
||||
|
||||
const unlink = () => {
|
||||
fs.unlink(filename, (err) => {
|
||||
if (err) {
|
||||
setFailure(
|
||||
`Codecov: Could not unlink uploader: ${err.message}`,
|
||||
failCi,
|
||||
);
|
||||
}
|
||||
});
|
||||
};
|
||||
const doUpload = async () => {
|
||||
await exec.exec(getCommand(filename, args, uploadCommand).join(' '),
|
||||
uploadExecArgs,
|
||||
uploadOptions)
|
||||
.catch((err) => {
|
||||
const unlink = () => {
|
||||
fs.unlink(filename, (err) => {
|
||||
if (err) {
|
||||
setFailure(
|
||||
`Codecov:
|
||||
Failed to properly upload report: ${err.message}`,
|
||||
`Codecov: Could not unlink uploader: ${err.message}`,
|
||||
failCi,
|
||||
);
|
||||
});
|
||||
};
|
||||
const createReport = async () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
const doUpload = async () => {
|
||||
await exec.exec(getCommand(filename, args, uploadCommand).join(' '),
|
||||
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, reportCommand).join(' '),
|
||||
reportExecArgs,
|
||||
reportOptions)
|
||||
getCommand(
|
||||
filename,
|
||||
args,
|
||||
commitCommand,
|
||||
).join(' '),
|
||||
commitExecArgs, commitOptions)
|
||||
.then(async (exitCode) => {
|
||||
if (exitCode == 0) {
|
||||
await doUpload();
|
||||
await createReport();
|
||||
}
|
||||
unlink();
|
||||
}).catch((err) => {
|
||||
setFailure(
|
||||
`Codecov:
|
||||
Failed to properly create report: ${err.message}`,
|
||||
`Codecov: Failed to properly create commit: ${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(
|
||||
`Codecov: Failed to properly create commit: ${err.message}`,
|
||||
failCi,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
setFailure(`Codecov: Encountered an unexpected error ${err.message}`, failCi);
|
||||
}
|
||||
});
|
||||
});
|
||||
} catch (err) {
|
||||
setFailure(`Codecov: Encountered an unexpected error ${err.message}`, failCi);
|
||||
}
|
||||
};
|
||||
|
||||
run();
|
||||
|
|
|
|||
Loading…
Reference in a new issue