-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.'; | ||
|
||
|
@@ -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", | ||
} | ||
|
||
export interface GithubStatusEvent { | ||
|
@@ -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> { | ||
|
@@ -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({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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...