Skip to content

Commit 1daafe6

Browse files
authored
Initial commit (#1)
Initial commit of aws-codeguru-cli
1 parent 71b2b9b commit 1daafe6

File tree

118 files changed

+5331
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+5331
-6
lines changed

.github/workflows/guru-reviewer.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
2+
name: Analyze with CodeGuru Reviewer
3+
4+
on: [push]
5+
6+
permissions:
7+
id-token: write
8+
contents: read
9+
security-events: write
10+
11+
jobs:
12+
build:
13+
name: Run CodeGuru Reviewer
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Configure AWS credentials
17+
uses: aws-actions/configure-aws-credentials@v1
18+
continue-on-error: true
19+
id: iam-role
20+
with:
21+
role-to-assume: arn:aws:iam::048169001733:role/GuruGitHubCICDRole
22+
aws-region: us-west-2
23+
24+
- uses: actions/checkout@v2
25+
if: steps.iam-role.outcome == 'success'
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Set up JDK 1.8
30+
if: steps.iam-role.outcome == 'success'
31+
uses: actions/setup-java@v1
32+
with:
33+
java-version: 1.8
34+
- name: Build project
35+
if: steps.iam-role.outcome == 'success'
36+
run: ./gradlew clean installDist
37+
38+
- name: CodeGuru Reviewer
39+
if: steps.iam-role.outcome == 'success'
40+
id: codeguru
41+
uses: aws-actions/[email protected]
42+
continue-on-error: false
43+
with:
44+
s3_bucket: codeguru-reviewer-build-artifacts-048169001733-us-west-2
45+
build_path: ./build/libs
46+
47+
- name: Upload review result
48+
if: steps.iam-role.outcome == 'success' && steps.codeguru.outcome == 'success'
49+
continue-on-error: true
50+
uses: github/codeql-action/upload-sarif@v1
51+
with:
52+
sarif_file: codeguru-results.sarif.json

.github/workflows/java-compatible.yml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
name: Build with different JDKs
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
id-token: write
11+
contents: write
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
java: [ '8', '11', '16', '17' ]
19+
name: Java ${{ matrix.Java }} build
20+
21+
steps:
22+
- uses: actions/checkout@v2
23+
- name: Setup java
24+
uses: actions/setup-java@v2
25+
with:
26+
distribution: 'temurin'
27+
java-version: ${{ matrix.java }}
28+
- name: Build project
29+
run: ./gradlew clean installDist
30+
- name: Run cli
31+
run: ./build/install/aws-codeguru-cli/bin/aws-codeguru-cli
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Created using https://github.com/aws-samples/aws-codeguru-reviewer-cicd-cdk-sample
2+
name: Self-test and release
3+
4+
on:
5+
push:
6+
branches:
7+
- main
8+
9+
permissions:
10+
id-token: write
11+
contents: write
12+
13+
jobs:
14+
build:
15+
name: Build, self-test, release
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
with:
20+
fetch-depth: 0
21+
22+
- name: Set up JDK 1.8
23+
uses: actions/setup-java@v1
24+
with:
25+
java-version: 1.8
26+
- name: Build project
27+
run: ./gradlew clean installDist distZip
28+
29+
- name: Configure AWS credentials
30+
uses: aws-actions/configure-aws-credentials@v1
31+
continue-on-error: true
32+
id: iam-role
33+
with:
34+
role-to-assume: arn:aws:iam::048169001733:role/GuruGitHubCICDRole
35+
aws-region: us-west-2
36+
37+
- name: Self Test
38+
if: steps.iam-role.outcome == 'success'
39+
run: |
40+
./build/install/aws-codeguru-cli/bin/aws-codeguru-cli --region us-west-2 -r . -s src/main/java -b build/libs -c HEAD^:HEAD --no-prompt
41+
42+
- name: Get Release Version
43+
run: |
44+
echo "::set-output name=TAG_NAME::$(./gradlew properties -q | grep "version:" | awk '{print $2}')"
45+
id: version
46+
47+
- name: Release
48+
uses: softprops/action-gh-release@v1
49+
with:
50+
tag_name: ${{ steps.version.outputs.TAG_NAME }}
51+
prerelease: false
52+
draft: false
53+
body: >
54+
Version ${{ steps.version.outputs.TAG_NAME }} of the AWS CodeGuru Reviewer CLI.
55+
files: |
56+
./build/distributions/aws-codeguru-cli.zip
57+
LICENSE

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build
2+
.gradle
3+
.vscode
4+
.guru
5+
code-guru
6+
.DS_Store
7+
.idea
8+
test-output*

README.md

+100-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,106 @@
1-
## My Project
1+
# CodeGuru Reviewer CLI Wrapper
2+
Simple CLI wrapper for CodeGuru reviewer that provides a one-line command to scan a local clone of a repository and
3+
receive results. This CLI wraps the [AWS CLI](https://aws.amazon.com/cli/) commands to communicated with
4+
[AWS CodeGuru Reviewer](https://aws.amazon.com/codeguru/). Using CodeGuru Reviewer may generate metering fees
5+
in your AWS account. See the [CodeGuru Reviewer pricing](https://aws.amazon.com/codeguru/pricing/) for details.
26

3-
TODO: Fill this README out!
7+
### Before you start
48

5-
Be sure to:
9+
Before we start, let's make sure that you can access an AWS account from your computer.
10+
Follow the credential setup process for the [AWS CLI](https://github.com/aws/aws-cli#configuration).
11+
The credentials must have at least the following permissions:
612

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
13+
```json
14+
{
15+
"Version": "2012-10-17",
16+
"Statement": [
17+
{
18+
"Action": [
19+
"codeguru-reviewer:ListRepositoryAssociations",
20+
"codeguru-reviewer:AssociateRepository",
21+
"codeguru-reviewer:DescribeRepositoryAssociation",
22+
"codeguru-reviewer:CreateCodeReview",
23+
"codeguru-reviewer:DescribeCodeReview",
24+
"codeguru-reviewer:ListRecommendations"
25+
],
26+
"Resource": "*",
27+
"Effect": "Allow"
28+
},
29+
{
30+
"Action": [
31+
"s3:CreateBucket",
32+
"s3:GetBucket*",
33+
"s3:List*",
34+
"s3:GetObject",
35+
"s3:PutObject",
36+
"s3:DeleteObject"
37+
],
38+
"Resource": [
39+
"arn:aws:s3:::codeguru-reviewer-cli-*",
40+
"arn:aws:s3:::codeguru-reviewer-cli-*/*"
41+
],
42+
"Effect": "Allow"
43+
}
44+
]
45+
}
46+
```
47+
48+
49+
### Download the CLI and scan an Example
50+
51+
You can download the [aws-codeguru-cli](releases/download/latest/aws-codeguru-cli.zip) from the releases section.
52+
Download the latest version and add it to your `PATH`:
53+
```
54+
curl -OL https://github.com/martinschaef/aws-codeguru-cli/releases/download/latest/aws-codeguru-cli.zip
55+
unzip aws-codeguru-cli.zip
56+
export PATH=$PATH:./aws-codeguru-cli/bin
57+
```
58+
59+
Now, lets download an example project (requires Maven):
60+
```
61+
git clone https://github.com/aws-samples/amazon-codeguru-reviewer-sample-app
62+
cd amazon-codeguru-reviewer-sample-app
63+
mvn clean compile
64+
```
65+
After compiling, we can run CodeGuru with:
66+
```
67+
aws-codeguru-cli --root-dir ./ --build target/classes --src src --output ./output
68+
open output/codeguru-report.html
69+
```
70+
where `--root-dir .` specifies that the root of the project that we want to analyze. The option `--build target/classses` states that the build artifacts are located under `./target/classes` and `--src` says that we only want to analyze source files that are
71+
located under `./src`. The option `--output ./output` specifies where CodeGuru should write its recommendations to. By default,
72+
CodeGuru produces a Json and Html report.
73+
74+
You can provide your own bucket name using the `--bucket-name` option. Note that, currently, CodeGuru Reviewer only
75+
accepts bucket names that start with the prefix `codeguru-reviewer-`.
76+
77+
### Running from CI/CD
78+
79+
You can use this CLI to run CodeGuru from inside your CI/CD pipeline. See [this action](.github/workflows/self-test-and-release.yml#L30-L41) as an example. First, you need credentials for a role with the permissions mentioned above. If you already scanned
80+
the repository once with the CLI, the S3 bucket has been created, and the you do not need the `s3:CreateBucket*` permission anymore.
81+
82+
Then you can run the CLI in non-interactive mode using the `--no-prompt` option. Further, you can specify a region and
83+
AWS profile using the `--region` and `--profile` options as needed:
84+
```
85+
aws-codeguru-cli --region [BUCKET REGION] --no-prompt -r ./ ...
86+
```
87+
obtain the commit range works differently for different CI/CD providers. For example, GitHub provides the relevant
88+
commits via environment variables such as `${{ github.event.before }}` and `${{ github.event.after }}`.
89+
90+
### Build from Source
91+
92+
To build the project, you need Java 8 or later. Checkout this repository and run:
93+
```
94+
./gradlew installDist
95+
```
96+
and now run your local build with:
97+
```
98+
./build/install/aws-codeguru-cli/bin/aws-codeguru-cli
99+
```
100+
you can run a self-test with:
101+
```
102+
./build/install/aws-codeguru-cli/bin/aws-codeguru-cli -r . -s src/main/java -b build/libs -c HEAD^:HEAD
103+
```
9104

10105
## Security
11106

@@ -14,4 +109,3 @@ See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more inform
14109
## License
15110

16111
This project is licensed under the Apache-2.0 License.
17-

build.gradle

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
2+
buildscript {
3+
repositories {
4+
maven {
5+
url "https://plugins.gradle.org/m2/"
6+
}
7+
}
8+
dependencies {
9+
classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.3"
10+
}
11+
}
12+
13+
/*
14+
Applies core Gradle plugins, which are ones built into Gradle itself.
15+
*/
16+
plugins {
17+
// Java for compile and unit test of Java source files. Read more at:
18+
// https://docs.gradle.org/current/userguide/java_plugin.html
19+
id 'java'
20+
21+
// Checkstyle for style checks and reports on Java source files. Read more at:
22+
// https://docs.gradle.org/current/userguide/checkstyle_plugin.html
23+
id 'checkstyle'
24+
25+
id 'application'
26+
}
27+
28+
// SpotBugs for quality checks and reports of source files. Read more at:
29+
// https://spotbugs.readthedocs.io/en/stable/gradle.html
30+
apply plugin: 'com.github.spotbugs'
31+
32+
checkstyle {
33+
sourceSets = [sourceSets.main]
34+
ignoreFailures = false
35+
}
36+
37+
spotbugs {
38+
ignoreFailures.set(false)
39+
}
40+
41+
repositories {
42+
mavenCentral()
43+
}
44+
45+
defaultTasks('installDist')
46+
47+
version = '0.0.1'
48+
jar.archiveName = "${jar.baseName}.${jar.extension}"
49+
distZip.archiveName = "${jar.baseName}.zip"
50+
51+
application {
52+
mainClass = 'com.amazonaws.gurureviewercli.Main'
53+
}
54+
55+
dependencies {
56+
implementation 'software.amazon.awssdk:s3:2.17.113'
57+
implementation 'software.amazon.awssdk:sts:2.17.113'
58+
implementation 'software.amazon.awssdk:codegurureviewer:2.17.113'
59+
implementation 'software.amazon.awssdk:sdk-core:2.17.113'
60+
61+
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.0'
62+
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0'
63+
64+
implementation 'com.beust:jcommander:1.81'
65+
66+
implementation 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
67+
68+
implementation 'org.apache.logging.log4j:log4j-core:2.17.1'
69+
implementation 'org.slf4j:slf4j-nop:2.0.0-alpha5'
70+
71+
// For Java 9+
72+
implementation 'javax.xml.bind:jaxb-api:2.3.1'
73+
74+
implementation 'org.commonmark:commonmark:0.18.1'
75+
76+
implementation 'org.beryx:text-io:3.4.1'
77+
78+
implementation 'com.google.code.findbugs:jsr305:3.0.2'
79+
80+
compileOnly 'org.projectlombok:lombok:1.18.22'
81+
annotationProcessor 'org.projectlombok:lombok:1.18.22'
82+
83+
testCompileOnly 'org.projectlombok:lombok:1.18.22'
84+
testAnnotationProcessor 'org.projectlombok:lombok:1.18.22'
85+
86+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
87+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
88+
testImplementation 'org.mockito:mockito-junit-jupiter:4.2.0'
89+
}
90+
91+
test {
92+
useJUnitPlatform()
93+
}
94+

gradle/wrapper/gradle-wrapper.jar

57.8 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)