Skip to content

Commit

Permalink
Merge branch 'aws:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
martinschaef authored Mar 25, 2022
2 parents 452d742 + 33851c0 commit c6c80f8
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 6 deletions.
20 changes: 19 additions & 1 deletion .github/workflows/self-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,35 @@ jobs:
role-to-assume: arn:aws:iam::048169001733:role/GuruGitHubCICDRole
aws-region: us-west-2


- name: Checkout Test Data
if: steps.iam-role.outcome == 'success'
uses: actions/checkout@master
with:
repository: aws-samples/amazon-codeguru-samples
path: ./amazon-codeguru-samples

- name: Build Test Project
if: steps.iam-role.outcome == 'success'
run: |
cd amazon-codeguru-samples
./gradlew
cd ..
- name: Self Test
if: steps.iam-role.outcome == 'success'
run: |
./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
./build/install/aws-codeguru-cli/bin/aws-codeguru-cli --region us-west-2 -r amazon-codeguru-samples -s amazon-codeguru-samples/src/main/java -b amazon-codeguru-samples/build/libs --no-prompt
cat code-guru/recommendations.json
[[ $(grep "filePath" code-guru/recommendations.json | wc -l) -eq 12 ]] || { echo >&2 "Expected 12 recommendations."; exit 1; }
- name: Get Release Version
run: |
echo "::set-output name=TAG_NAME::$(./gradlew properties -q | grep "version:" | awk '{print $2}')"
id: version

- name: Release
if: steps.iam-role.outcome == 'success'
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.version.outputs.TAG_NAME }}
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ receive results. This CLI wraps the [AWS CLI](https://aws.amazon.com/cli/) comma
[AWS CodeGuru Reviewer](https://aws.amazon.com/codeguru/). Using CodeGuru Reviewer may generate metering fees
in your AWS account. See the [CodeGuru Reviewer pricing](https://aws.amazon.com/codeguru/pricing/) for details.

### Before you start
### Prerequisites

Before we start, let's make sure that you can access an AWS account from your computer.
Follow the credential setup process for the [AWS CLI](https://github.com/aws/aws-cli#configuration).
To run the CLI, we need to have a version of git, Java (e.g., [Amazon Corretto](https://aws.amazon.com/corretto/?filtered-posts.sort-by=item.additionalFields.createdDate&filtered-posts.sort-order=desc)) and the [AWS Command Line interface](https://aws.amazon.com/cli/) installed. Verify that both application are installed on our machine by running:

```
java -version
mvn --version
aws --version
git --version
```

We will also need working credentials on our machine to interact with our AWS account. Learn more about setting up credentials for AWS here: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html.
The credentials must have at least the following permissions:

```json
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/amazonaws/gurureviewercli/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static void main(String[] argv) {
val sourcePaths = main.sourceDirs.stream()
.map(Paths::get).map(Path::toAbsolutePath).map(Path::normalize)
.collect(Collectors.toList());
val buildPaths = main.sourceDirs.stream()
val buildPaths = main.buildDirs.stream()
.map(Paths::get).map(Path::toAbsolutePath).map(Path::normalize)
.collect(Collectors.toList());
scanMetaData = ScanAdapter.startScan(config, gitMetaData, sourcePaths, buildPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,50 @@ public void test_zipAndUpload_happyCaseAllFiles() throws Exception {
Assertions.assertNull(metaData.getBuildKey());
Assertions.assertNotNull(metaData.getSourceKey());
}
}

@Test
public void test_zipAndUpload_happyCaseBuildDir() throws Exception {

val tempDir = Files.createTempDirectory("test_zipAndUpload_happyCaseGitFilesOnly");
val bucketName = "some-bucket";

// only include files from the util dir.
val repoDir = Paths.get("./test-data/fake-repo");
val buildArtifacts = repoDir.resolve("build-dir/lib");
final List<Path> buildDirs = Arrays.asList(buildArtifacts);

val config = Configuration.builder()
.s3Client(s3client)
.interactiveMode(false)
.build();

Answer<Object> answer = invocationOnMock -> {
Path filePath = invocationOnMock.getArgument(1);
if (!filePath.toString().contains("analysis-bin")) {
return null; // only look at the artifacts.
}
Assertions.assertTrue(filePath.toFile().isFile());
try (val zipFile = new ZipFile(filePath.toFile())) {
val entries = zipFile.entries();
int count = 0;
while (entries.hasMoreElements()) {
val s = entries.nextElement().getName();
Assertions.assertTrue(s.endsWith("included.txt"));
count++; // count the files that are not in the git folder.
}
Assertions.assertEquals(1, count);
}
return null;
};
doAnswer(answer).when(s3client).putObject(any(PutObjectRequest.class), any(Path.class));

val metaData =
ArtifactAdapter.zipAndUpload(config, tempDir,
repoDir,
Arrays.asList(repoDir),
Arrays.asList(buildArtifacts),
bucketName);
Assertions.assertNotNull(metaData.getBuildKey());
Assertions.assertNotNull(metaData.getSourceKey());
}
}
1 change: 1 addition & 0 deletions test-data/fake-repo/build-dir/lib/included.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asdf
1 change: 1 addition & 0 deletions test-data/fake-repo/build-dir/should-not-be-included.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions test-data/fake-repo/should-not-be-included.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit c6c80f8

Please sign in to comment.