Skip to content

Commit

Permalink
[Documentation] Use Docker for JUNIT examples (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvassallo authored Mar 25, 2024
1 parent 8537ff1 commit 3792cf7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 56 deletions.
40 changes: 3 additions & 37 deletions guard-examples/ci/.circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,16 @@ version: 2.1
executors:
default:
docker:
- image: alpine:latest
- image: public.ecr.aws/aws-cloudformation/cloudformation-guard:latest
commands:
# At the time of creating this example, only 3.1.0-beta supports junit output.
# This example downloads the binary directly and adds it to the PATH so you can
# easily copy over and replace the tests and validations with your own existing
# commands.
install_guard:
description: "Install cfn-guard"
steps:
- run:
name: Install curl
command: apk add curl
- run:
name: Create cfn-guard v3 directory
command: mkdir -p ~/.guard/3
- run:
name: Create cfn-guard bin directory
command: mkdir -p ~/.guard/bin
- run:
name: Download cfn-guard
command: curl -L -o /tmp/guard.tar.gz https://github.com/aws-cloudformation/cloudformation-guard/releases/download/3.1.0-beta/cfn-guard-v3-x86_64-ubuntu-latest.tar.gz
- run:
name: Extract cfn-guard
command: tar -C ~/.guard/3 -xzf /tmp/guard.tar.gz
- run:
name: Link cfn-guard
command: ln -sf ~/.guard/3/cfn-guard-v3-x86_64-ubuntu-latest/cfn-guard ~/.guard/bin && ls -l ~/.guard/bin
- run:
name: Add ~/.guard/bin/ to PATH
command: |
echo 'export PATH=$HOME/.guard/bin/:$PATH' >> $BASH_ENV
source "$BASH_ENV"
cfn-guard --help
validate:
description: "Run cfn-guard validate"
steps:
- run:
# Replace these paths with your own
command: |
source "$BASH_ENV"
mkdir -p ~/test-results/validate/
if ! cfn-guard validate -r ./path/to/rules/directory_or_file/ -d ./path/to/data/directory_or_file/ --output-format junit --show-summary none --structured > ~/test-results/validate/validate.xml; then
if ! /usr/src/cloudformation-guard/cfn-guard validate -r ./path/to/rules/directory_or_file/ -d ./path/to/data/directory_or_file/ --output-format junit --show-summary none --structured > ~/test-results/validate/validate.xml; then
exit 1
fi
when: always
Expand All @@ -55,9 +23,8 @@ commands:
- run:
# Replace these paths with your own
command: |
source "$BASH_ENV"
mkdir -p ~/test-results/test/
if ! cfn-guard test -r ./path/to/test/directory_or_file/ -t ./path/to/data/directory_or_file/ --output-format junit > ~/test-results/test/test.xml; then
if ! /usr/src/cloudformation-guard/cfn-guard test -r ./path/to/test/directory_or_file/ -t ./path/to/data/directory_or_file/ --output-format junit > ~/test-results/test/test.xml; then
exit 1
fi
when: always
Expand All @@ -68,7 +35,6 @@ jobs:
executor: default
steps:
- checkout
- install_guard
- validate
- test
workflows:
Expand Down
23 changes: 4 additions & 19 deletions guard-examples/ci/.github/workflows/junit-test-and-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,17 @@ jobs:
build:
name: Run cfn-guard validate & test with Junit output
runs-on: ubuntu-latest
# Note: GitHub workflows require additional permissions to use the install script.
# This example downloads the binary directly and adds it to the PATH so you can
# easily copy over and replace the tests and validations with your own existing
# commands.
container:
image: public.ecr.aws/aws-cloudformation/cloudformation-guard:latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Create cfn-guard v3 directory
run: mkdir -p ~/.guard/3
- name: Create cfn-guard bin directory
run: mkdir -p ~/.guard/bin
- name: Download cfn-guard
# At the time of creating this example, only 3.1.0-beta supports junit output.
run: curl -L -o /tmp/guard.tar.gz https://github.com/aws-cloudformation/cloudformation-guard/releases/download/3.1.0-beta/cfn-guard-v3-x86_64-ubuntu-latest.tar.gz
- name: Extract cfn-guard
run: tar -C ~/.guard/3 -xzf /tmp/guard.tar.gz
- name: Link cfn-guard
run: ln -sf ~/.guard/3/cfn-guard-v3-x86_64-ubuntu-latest/cfn-guard ~/.guard/bin && ls -l ~/.guard/bin
- name: Add ~/.guard/bin/ to PATH
run: echo "$HOME/.guard/bin/" >> $GITHUB_PATH
- name: Run cfn-guard validate with Junit output
# Replace these paths with your own
run: cfn-guard validate -r ./path/to/rules/directory_or_file/ -d ./path/to/data/directory_or_file/ --output-format junit --show-summary none --structured > validate-junit.xml || true
run: /usr/src/cloudformation-guard/cfn-guard validate -r ./path/to/rules/directory_or_file/ -d ./path/to/data/directory_or_file/ --output-format junit --show-summary none --structured > validate-junit.xml || true
- name: Run cfn-guard test with Junit output
# Replace these paths with your own
run: cfn-guard test -r ./path/to/test/directory_or_file/ -t ./path/to/test/directory_or_file/ --output-format junit > test-junit.xml || true
run: /usr/src/cloudformation-guard/cfn-guard test -r ./path/to/test/directory_or_file/ -t ./path/to/data/directory_or_file/ --output-format junit > test-junit.xml || true
- name: Publish Validate Report
uses: mikepenz/action-junit-report@v4
if: success() || failure()
Expand Down

0 comments on commit 3792cf7

Please sign in to comment.