Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Argument to perform send-notifications #1574

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Codecov's Action supports inputs from the user. These inputs, along with their d
| `plugins` | Comma-separated list of plugins for use during upload. | Optional
| `report_code` | The code of the report. If unsure, do not include | Optional
| `root_dir` | Used to specify the location of your .git root to identify project root directory | Optional
| `send-notifications` | Send notifications (does not upload coverage, requires codecov.notify.manual_trigger to be true) | Optional
| `slug` | Specify the slug manually (Enterprise use) | Optional
| `url` | Specify the base url to upload (Enterprise use) | Optional
| `use_legacy_upload_endpoint` | Use the legacy upload endpoint | Optional
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ inputs:
working-directory:
description: 'Directory in which to execute codecov.sh'
required: false
send-notifications:
description: 'Manually trigger the sending of notifications (does not upload coverage, requires codecov.notify.manual_trigger to be true)'
required: false
branding:
color: 'red'
icon: 'umbrella'
Expand Down
70 changes: 69 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32340,7 +32340,7 @@ const getGitService = () => {
return 'github';
};
const isPullRequestFromFork = () => {
core.info(`evenName: ${context.eventName}`);
core.info(`eventName: ${context.eventName}`);
if (!['pull_request', 'pull_request_target'].includes(context.eventName)) {
return false;
}
Expand All @@ -32367,6 +32367,9 @@ const getToken = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
}
return token;
});
const getSendNotifications = () => {
return isTrue(core.getInput('send-notifications'));
};
const getOverrideBranch = (token) => {
let overrideBranch = core.getInput('override_branch');
if (!overrideBranch && !token && isPullRequestFromFork()) {
Expand Down Expand Up @@ -32497,6 +32500,54 @@ const buildReportExec = () => buildExec_awaiter(void 0, void 0, void 0, function
}
return { reportExecArgs, reportOptions, reportCommand };
});
const buildSendNotificationsExec = () => buildExec_awaiter(void 0, void 0, void 0, function* () {
const gitService = getGitService();
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
const token = yield getToken();
const failCi = isTrue(core.getInput('fail_ci_if_error'));
const workingDir = core.getInput('working-directory');
const sendNotificationsCommand = 'send-notifications';
const sendNotificationsExecArgs = [];
const sendNotificationsOptions = {};
sendNotificationsOptions.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) {
sendNotificationsOptions.env.CODECOV_TOKEN = token;
}
sendNotificationsExecArgs.push('--git-service', gitService);
if (overrideCommit) {
sendNotificationsExecArgs.push('-C', overrideCommit);
}
else if (['pull_request', 'pull_request_target'].includes(context.eventName)) {
const payload = context.payload;
sendNotificationsExecArgs.push('-C', payload.pull_request.head.sha);
}
if (overridePr) {
sendNotificationsExecArgs.push('-P', overridePr);
}
else if (context.eventName == 'pull_request_target') {
const payload = context.payload;
sendNotificationsExecArgs.push('-P', payload.number.toString());
}
if (slug) {
sendNotificationsExecArgs.push('--slug', slug);
}
if (failCi) {
sendNotificationsExecArgs.push('-Z');
}
if (workingDir) {
sendNotificationsOptions.cwd = workingDir;
}
return { sendNotificationsExecArgs, sendNotificationsOptions, sendNotificationsCommand };
});
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'));
Expand Down Expand Up @@ -32826,6 +32877,7 @@ 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 { sendNotificationsExecArgs, sendNotificationsOptions, sendNotificationsCommand, } = yield buildSendNotificationsExec();
const { uploadExecArgs, uploadOptions, disableSafeDirectory, failCi, os, uploaderVersion, uploadCommand, } = yield buildUploadExec();
const { args, verbose } = buildGeneralExec();
const platform = getPlatform(os);
Expand Down Expand Up @@ -32870,6 +32922,22 @@ const run = () => src_awaiter(void 0, void 0, void 0, function* () {
Failed to properly create report: ${err.message}`, failCi);
});
});
const sendNotifications = () => src_awaiter(void 0, void 0, void 0, function* () {
yield exec.exec(getCommand(filename, args, sendNotificationsCommand).join(' '), sendNotificationsExecArgs, sendNotificationsOptions)
.then((exitCode) => src_awaiter(void 0, void 0, void 0, function* () {
if (exitCode == 0) {
// notifications sent
}
})).catch((err) => {
setFailure(`Codecov:
Failed to send notifications: ${err.message}`, failCi);
});
});
if (getSendNotifications()) {
yield sendNotifications();
// don't perform an upload after sending notifications
return;
}
yield exec.exec(getCommand(filename, args, commitCommand).join(' '), commitExecArgs, commitOptions)
.then((exitCode) => src_awaiter(void 0, void 0, void 0, function* () {
if (exitCode == 0) {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions src/buildExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ const getToken = async (): Promise<string> => {
return token;
};

const getSendNotifications = (): boolean => {
return isTrue(
core.getInput('send-notifications'),
);
};

const getOverrideBranch = (token: string): string => {
let overrideBranch = core.getInput('override_branch');
if (!overrideBranch && !token && isPullRequestFromFork()) {
Expand Down Expand Up @@ -220,6 +226,64 @@ const buildReportExec = async (): Promise<{
return {reportExecArgs, reportOptions, reportCommand};
};

const buildSendNotificationsExec = async (): Promise<{
sendNotificationsExecArgs: any[];
sendNotificationsOptions: any;
sendNotificationsCommand: string;
}> => {
const gitService = getGitService();
const overrideCommit = core.getInput('override_commit');
const overridePr = core.getInput('override_pr');
const slug = core.getInput('slug');
const token = await getToken();
const failCi = isTrue(core.getInput('fail_ci_if_error'));
const workingDir = core.getInput('working-directory');

const sendNotificationsCommand = 'send-notifications';
const sendNotificationsExecArgs: string[] = [];

const sendNotificationsOptions: any = {};
sendNotificationsOptions.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) {
sendNotificationsOptions.env.CODECOV_TOKEN = token;
}
sendNotificationsExecArgs.push('--git-service', gitService);

if (overrideCommit) {
sendNotificationsExecArgs.push('-C', overrideCommit);
} else if (
['pull_request', 'pull_request_target'].includes(context.eventName)
) {
const payload = context.payload as PullRequestEvent;
sendNotificationsExecArgs.push('-C', payload.pull_request.head.sha);
}
if (overridePr) {
sendNotificationsExecArgs.push('-P', overridePr);
} else if (context.eventName == 'pull_request_target') {
const payload = context.payload as PullRequestEvent;
sendNotificationsExecArgs.push('-P', payload.number.toString());
}
if (slug) {
sendNotificationsExecArgs.push('--slug', slug);
}
if (failCi) {
sendNotificationsExecArgs.push('-Z');
}
if (workingDir) {
sendNotificationsOptions.cwd = workingDir;
}

return {sendNotificationsExecArgs, sendNotificationsOptions, sendNotificationsCommand};
};

const buildUploadExec = async (): Promise<{
uploadExecArgs: any[];
uploadOptions: any;
Expand Down Expand Up @@ -416,5 +480,7 @@ export {
buildGeneralExec,
buildReportExec,
buildUploadExec,
buildSendNotificationsExec,
getToken,
getSendNotifications,
};
31 changes: 31 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import {
buildCommitExec,
buildGeneralExec,
buildReportExec,
buildSendNotificationsExec,
buildUploadExec,
getSendNotifications,
} from './buildExec';
import {
getBaseUrl,
Expand All @@ -28,6 +30,11 @@ const run = async (): Promise<void> => {
try {
const {commitExecArgs, commitOptions, commitCommand} = await buildCommitExec();
const {reportExecArgs, reportOptions, reportCommand} = await buildReportExec();
const {
sendNotificationsExecArgs,
sendNotificationsOptions,
sendNotificationsCommand,
} = await buildSendNotificationsExec();
const {
uploadExecArgs,
uploadOptions,
Expand Down Expand Up @@ -101,6 +108,30 @@ const run = async (): Promise<void> => {
);
});
};
const sendNotifications = async (): Promise<void> => {
await exec.exec(
getCommand(filename, args, sendNotificationsCommand).join(' '),
sendNotificationsExecArgs,
sendNotificationsOptions)
.then(async (exitCode) => {
if (exitCode == 0) {
// notifications sent
}
}).catch((err) => {
setFailure(
`Codecov:
Failed to send notifications: ${err.message}`,
failCi,
);
});
};

if (getSendNotifications()) {
await sendNotifications();
// don't perform an upload after sending notifications
return;
}

await exec.exec(
getCommand(
filename,
Expand Down