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

chore(prlint): fail prlinter on codecov failures, with exemption label #32674

Merged
merged 6 commits into from
Jan 12, 2025
Merged
Changes from 3 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
92 changes: 88 additions & 4 deletions tools/@aws-cdk/prlint/lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type GitHubPr =
Endpoints['GET /repos/{owner}/{repo}/pulls/{pull_number}']['response']['data'];

export const CODE_BUILD_CONTEXT = 'AWS CodeBuild us-east-1 (AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv)';
export const CODECOV_PREFIX = 'codecov/';

const PR_FROM_MAIN_ERROR = 'Pull requests from `main` branch of a fork cannot be accepted. Please reopen this contribution from another branch on your fork. For more information, see https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md#step-4-pull-request.';

Expand All @@ -24,6 +25,7 @@ enum Exemption {
CLI_INTEG_TESTED = 'pr-linter/cli-integ-tested',
REQUEST_CLARIFICATION = 'pr/reviewer-clarification-requested',
REQUEST_EXEMPTION = 'pr-linter/exemption-requested',
CODECOV = "pr-linter/exempt-codecov",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one exemption for all 4 codecovs should be fine for now...

}

export interface GithubStatusEvent {
Expand Down Expand Up @@ -336,14 +338,59 @@ export class PullRequestLinter {
* @param sha the commit sha to evaluate
*/
private async codeBuildJobSucceeded(sha: string): Promise<boolean> {
const statuses = await this.client.repos.listCommitStatusesForRef({
return this.checkStatusSucceeded(sha, CODE_BUILD_CONTEXT);
}

/**
* Whether or not the codecov/patch job for the given commit is successful
*
* @param sha the commit sha to evaluate
*/
private async codecovPatchSucceeded(sha: string): Promise<boolean> {
return this.checkStatusSucceeded(sha, `${CODECOV_PREFIX}patch`);
}

/**
* Whether or not the codecov/patch/packages/aws-cdk job for the given commit is successful
*
* @param sha the commit sha to evaluate
*/
private async codecovPatchPackagesAwsCdkSucceeded(sha: string): Promise<boolean> {
return this.checkStatusSucceeded(sha, `${CODECOV_PREFIX}patch/packages/aws-cdk`);
}

/**
* Whether or not the codecov/project job for the given commit is successful
*
* @param sha the commit sha to evaluate
*/
private async codecovProjectSucceeded(sha: string): Promise<boolean> {
return this.checkStatusSucceeded(sha, `${CODECOV_PREFIX}project`);
}

/**
* Whether or not the codecov/project/packages/aws-cdk job for the given commit is successful
*
* @param sha the commit sha to evaluate
*/
private async codecovProjectPackagesAwsCdkSucceeded(sha: string): Promise<boolean> {
return this.checkStatusSucceeded(sha, `${CODECOV_PREFIX}project/packages/aws-cdk`);
}

/**
* Check a specific status check to see if it is successful for the given commit
*
* @param sha the commit sha to evaluate
*/
private async checkStatusSucceeded(sha: string, context: string): Promise<boolean> {
const statuses = await this.client.paginate(this.client.repos.listCommitStatusesForRef, {
owner: this.prParams.owner,
repo: this.prParams.repo,
ref: sha,
});
let status = statuses.data.filter(status => status.context === CODE_BUILD_CONTEXT).map(status => status.state);
console.log("CodeBuild Commit Statuses: ", status);
return statuses.data.some(status => status.context === CODE_BUILD_CONTEXT && status.state === 'success');
let status = statuses.filter(status => status.context === context).map(status => status.state);
console.log(`${context} statuses: ${status}`);
return statuses.some(status => status.context === context && status.state === 'success');
}

public async validateStatusEvent(pr: GitHubPr, status: StatusEvent): Promise<void> {
Expand Down Expand Up @@ -575,6 +622,39 @@ export class PullRequestLinter {
],
});

const codecovResults = {
patch: await this.codecovPatchSucceeded(sha),
patchPackages: await this.codecovPatchPackagesAwsCdkSucceeded(sha),
project: await this.codecovProjectSucceeded(sha),
projectPackages: await this.codecovProjectPackagesAwsCdkSucceeded(sha),
};

validationCollector.validateRuleSet({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will always fail at the start because the codecov reports take time to be generated. not sure how bad that is yet.

exemption: shouldExemptCodecov,
testRuleSet: [
{ test: () => {
const result = new TestResult();
result.assessFailure(codecovResults.patch, 'codecov/patch job is not succeeding');
return result;
}},
{ test: () => {
const result = new TestResult();
result.assessFailure(codecovResults.patchPackages, 'codecov/patch/packages/aws-cdk job is not succeeding');
return result;
}},
{ test: () => {
const result = new TestResult();
result.assessFailure(codecovResults.project, 'codecov/project job is not succeeding');
return result;
}},
{ test: () => {
const result = new TestResult();
result.assessFailure(codecovResults.projectPackages, 'codecov/project/packages/aws-cdk job is not succeeding');
return result;
}},
],
});

console.log("Deleting PR Linter Comment now");
await this.deletePRLinterComment();
try {
Expand Down Expand Up @@ -656,6 +736,10 @@ function fixContainsIntegTest(pr: GitHubPr, files: GitHubFile[]): TestResult {
return result;
}

function shouldExemptCodecov(pr: GitHubPr): boolean {
return hasLabel(pr, Exemption.CODECOV);
}

function shouldExemptReadme(pr: GitHubPr): boolean {
return hasLabel(pr, Exemption.README);
}
Expand Down
Loading