Skip to content

Commit

Permalink
chore: migrate to GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwittig committed Oct 6, 2023
1 parent 28ef544 commit c5ae346
Show file tree
Hide file tree
Showing 23 changed files with 1,417 additions and 1 deletion.
45 changes: 45 additions & 0 deletions .github/workflows/acceptance-test-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
name: Acceptenace Test Run
on:
workflow_call:
inputs:
tests:
required: true
type: string
deletion-policy:
required: true
type: string # delete/retain
permissions:
id-token: write
contents: read
defaults:
run:
shell: bash
jobs:
run:
runs-on: ['hyperenv', 'medium']
steps:
- uses: actions/checkout@v4
- uses: aws-actions/configure-aws-credentials@v4.0.1
with:
role-to-assume: arn:aws:iam::859548834666:role/github-openid-connect
role-session-name: github-actions-aws-in-action-code3
role-duration-seconds: 21600
aws-region: us-east-1
- uses: actions/setup-java@v3
with:
distribution: corretto
java-version: '8'
cache: maven
- working-directory: test
env:
DELETION_POLICY: ${{ inputs.deletion-policy }}
TEMPLATE_DIR: ../
run: mvn -B clean test site -Dtest=${{ inputs.tests }} -Dsurefire.reportNameSuffix=us-east-1
- uses: actions/upload-artifact@v3
if: failure()
with:
name: surefire-reports-us-east-1
path: |
test/target/surefire-reports/
test/target/site/
39 changes: 39 additions & 0 deletions .github/workflows/acceptance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
name: Acceptenace Test
on:
workflow_dispatch:
inputs:
tests:
required: true
type: choice
default: '*'
options: # compile list with cd test/src && find . -name '*Test*' -execdir basename {} .java ';' | sort
- '*'
- Chapter02Test
- Chapter04Test
- Chapter05Test
- Chapter08Test
- Chapter09Test
- Chapter10Test
- Chapter11Test
- Chapter13Test
- Chapter14Test
- Chapter15Test
- Chapter17Test
- Chapter18Test
deletion-policy:
required: true
type: choice
default: delete
options:
- delete
- retain
defaults:
run:
shell: bash
jobs:
acceptance-test:
uses: ./.github/workflows/acceptance-test-run.yml
with:
tests: ${{ inputs.tests }}
deletion-policy: ${{ inputs.deletion-policy }}
21 changes: 21 additions & 0 deletions .github/workflows/acceptance-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Acceptenace Tests
on:
workflow_dispatch: {}
push:
branches:
- master
paths:
- '.github/workflows/acceptance-tests.yml'
- '*.yaml'
- 'test/**'
concurrency: acceptenace-tests-${{ github.ref }}
defaults:
run:
shell: bash
jobs:
acceptance-test:
uses: ./.github/workflows/acceptance-test-run.yml
with:
tests: '*'
deletion-policy: delete
2 changes: 1 addition & 1 deletion .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
aws-region: us-east-1
- name: latest
run: |
aws s3 sync --delete --exact-timestamps --exclude ".git/*" --exclude ".github/*" ./ s3://awsinaction-code3/
aws s3 sync --delete --exact-timestamps --exclude ".git/*" --exclude ".github/*" --exclude "test/*" ./ s3://awsinaction-code3/
63 changes: 63 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# AWS in Action (3rd edition) Code tests

Tests for https://github.com/AWSinAction/code3

The goal of this tests is to ensure that our templates are always working. The test are implemented in Java 8 and run in JUnit 4.

If you run this tests, many AWS CloudFormation tests are created and **charges will apply**!

## Supported env variables

* `IAM_ROLE_ARN` if the tests should assume an IAM role before they run supply the ARN of the IAM role
* `TEMPLATE_DIR` Load templates from local disk (instead of S3 bucket `widdix-aws-cf-templates`). Must end with an `/`. See `BUCKET_NAME` as well.
* `BUCKET_NAME` Some templates are to big to be passed as a string from local disk, therefore you need to supply the name of the bucket that is used to upload templates.
* `BUCKET_REGION` **required if BUCKET_NAME is set** Region of the bucket
* `DELETION_POLICY` (default `delete`, allowed values [`delete`, `retain`]) should resources be deleted?

## Usage

### AWS credentials

The AWS credentials are passed in as defined by the AWS SDK for Java: http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/credentials.html

One addition is, that you can supply the env variable `IAM_ROLE_ARN` which let's the tests assume a role before they start with the default credentials.

### Region selection

The region selection works like defined by the AWS SDK for Java: http://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html

### Run all tests

```
AWS_REGION="us-east-1" mvn test
```

### Run a single test suite

to run the `TestJenkins` tests:

```
AWS_REGION="us-east-1" mvn -Dtest=TestJenkins test
```

### Run a single test

to run the `TestJenkins.testHA` test:

```
AWS_REGION="us-east-1" mvn -Dtest=TestJenkins#testHA test
```

### Load templates from local file system

```
AWS_REGION="us-east-1" BUCKET_REGION="..." BUCKET_NAME="..." TEMPLATE_DIR="/path/to/widdix-aws-cf-templates/" mvn test
```

### Assume role

This is useful if you run on a integration server like Jenkins and want to assume a different IAM role for this tests.

```
IAM_ROLE_ARN="arn:aws:iam::ACCOUNT_ID:role/ROLE_NAME" mvn test
```
98 changes: 98 additions & 0 deletions test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.widdix</groupId>
<artifactId>aws-in-action-code3-tests</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-cloudformation</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ec2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-ecs</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sts</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.taimos</groupId>
<artifactId>httputils</artifactId>
<version>1.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.evanlennick</groupId>
<artifactId>retry4j</artifactId>
<version>0.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.54</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-bom</artifactId>
<version>1.11.883</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<parallel>classes</parallel>
<threadCount>2</threadCount>
</configuration>
</plugin>
</plugins>
</build>

</project>
Loading

0 comments on commit c5ae346

Please sign in to comment.