-
Notifications
You must be signed in to change notification settings - Fork 180
Set up AI PR review #3122
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
base: main
Are you sure you want to change the base?
Set up AI PR review #3122
Changes from all commits
6c99b07
1bc8126
3870dc1
ffc4c1e
3231339
0385840
a3c41ce
c31d5b7
e9b7f8e
e0fdfb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,3 +8,5 @@ __pycache__ | |
| # CDK asset staging directory | ||
| .cdk.staging | ||
| cdk.out | ||
|
|
||
| cr/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR ISC | ||
| import typing | ||
|
|
||
| from aws_cdk import ( | ||
| Duration, | ||
| Tags, | ||
| aws_codebuild as codebuild, | ||
| aws_iam as iam, | ||
| aws_s3 as s3, | ||
| RemovalPolicy, | ||
| Environment, | ||
| ) | ||
| from constructs import Construct | ||
|
|
||
| from util.metadata import ( | ||
| GITHUB_REPO_OWNER, | ||
| GITHUB_REPO_NAME | ||
| ) | ||
|
|
||
| from cdk.aws_lc_base_ci_stack import AwsLcBaseCiStack | ||
| from cdk.components import PruneStaleGitHubBuilds | ||
| from util.iam_policies import ( | ||
| bedrock_policy_in_json | ||
| ) | ||
| from util.build_spec_loader import BuildSpecLoader | ||
|
|
||
| class AwsLcAiCodeReviewStack(AwsLcBaseCiStack): | ||
| """Define a stack used to batch execute AWS-LC tests in GitHub.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| scope: Construct, | ||
| id: str, | ||
| spec_file_path: str, | ||
| env: typing.Union[Environment, typing.Dict[str, typing.Any]], | ||
| **kwargs | ||
| ) -> None: | ||
| super().__init__(scope, id, env=env, timeout=180, **kwargs) | ||
|
|
||
| # Create S3 bucket for AI code review files with versioning | ||
| bucket = s3.Bucket( | ||
| self, | ||
| "aws-lc-ai-code-review-files", | ||
| versioned=True, | ||
| removal_policy=RemovalPolicy.RETAIN, | ||
| block_public_access=s3.BlockPublicAccess.BLOCK_ALL, | ||
| ) | ||
|
|
||
| # Tag the bucket for easy discovery | ||
| Tags.of(bucket).add("aws-lc", "aws-lc-ai-code-review-files") | ||
|
|
||
| self.git_hub_source = codebuild.Source.git_hub( | ||
| owner=self.github_repo_owner, | ||
| repo=self.github_repo_name, | ||
| webhook=True, | ||
| webhook_filters=[ | ||
| codebuild.FilterGroup.in_event_of( | ||
| codebuild.EventAction.PULL_REQUEST_CREATED, | ||
| codebuild.EventAction.PULL_REQUEST_UPDATED, | ||
| codebuild.EventAction.PULL_REQUEST_REOPENED, | ||
| ) | ||
| ], | ||
| webhook_triggers_batch_build=False, | ||
| ) | ||
|
|
||
| # Define a IAM role for this stack. | ||
| bedrock_policy = iam.PolicyDocument.from_json( | ||
| bedrock_policy_in_json() | ||
| ) | ||
|
|
||
| inline_policies = { | ||
| "bedrock_policy": bedrock_policy, | ||
| } | ||
| role = iam.Role( | ||
| scope=self, | ||
| id="{}-role".format(id), | ||
| assumed_by=iam.ServicePrincipal("codebuild.amazonaws.com"), | ||
| inline_policies=inline_policies, | ||
| ) | ||
|
|
||
| # Grant CodeBuild read access to the S3 bucket | ||
| bucket.grant_read(role) | ||
|
|
||
| # Define CodeBuild. | ||
| project = codebuild.Project( | ||
| scope=self, | ||
| id=id, | ||
| project_name=id, | ||
| source=self.git_hub_source, | ||
| role=role, | ||
| timeout=Duration.minutes(self.timeout), | ||
| environment=codebuild.BuildEnvironment( | ||
| compute_type=codebuild.ComputeType.SMALL, | ||
| privileged=False, | ||
| build_image=codebuild.LinuxBuildImage.STANDARD_7_0, | ||
| environment_variables={ | ||
| "GITHUB_REPO_OWNER": codebuild.BuildEnvironmentVariable( | ||
| type=codebuild.BuildEnvironmentVariableType.PLAINTEXT, | ||
| value=GITHUB_REPO_OWNER | ||
| ), | ||
| "GITHUB_REPO_NAME": codebuild.BuildEnvironmentVariable( | ||
| type=codebuild.BuildEnvironmentVariableType.PLAINTEXT, | ||
| value=GITHUB_REPO_NAME | ||
| ), | ||
| "AI_CODE_REVIEW_BUCKET": codebuild.BuildEnvironmentVariable( | ||
| type=codebuild.BuildEnvironmentVariableType.PLAINTEXT, | ||
| value=bucket.bucket_name | ||
| ) | ||
| } | ||
| ), | ||
| build_spec=BuildSpecLoader.load(spec_file_path, env=env), | ||
| ) | ||
|
|
||
| cfn_project = project.node.default_child | ||
| cfn_project.add_property_override("Triggers.PullRequestBuildPolicy", self.pull_request_policy) | ||
|
|
||
| PruneStaleGitHubBuilds( | ||
| scope=self, | ||
| id="PruneStaleGitHubBuilds", | ||
| project=project, | ||
| ec2_permissions=False, | ||
| env=env, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 OR ISC | ||
|
|
||
| version: 0.2 | ||
|
|
||
| phases: | ||
| install: | ||
| runtime-versions: | ||
| nodejs: 18 | ||
| pre_build: | ||
| commands: | ||
| # Download all files from S3 | ||
| - aws s3 sync "s3://${AI_CODE_REVIEW_BUCKET}/" ./tests/ci/cdk/cr/ | ||
|
Contributor
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. Can the script function
Contributor
Author
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. We can but it'll be more steps and potentially more confusing. I think |
||
| - chmod +x ./tests/ci/cdk/cr/*.sh | ||
| build: | ||
| commands: | ||
| - ./tests/ci/cdk/cr/run_ai_code_review.sh | ||
|
Contributor
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. Are Nit: We're missing documentation for
Contributor
Author
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.
Yup! I think this will be useful to those that want to edit the files but don't want to install/deal with the |
Uh oh!
There was an error while loading. Please reload this page.