From 3792cf782a874c496153c5e15093553faf6e2c66 Mon Sep 17 00:00:00 2001 From: Dan Vassallo Date: Mon, 25 Mar 2024 16:42:19 -0400 Subject: [PATCH] [Documentation] Use Docker for JUNIT examples (#484) --- guard-examples/ci/.circleci/config.yml | 40 ++----------------- .../workflows/junit-test-and-validate.yml | 23 ++--------- 2 files changed, 7 insertions(+), 56 deletions(-) diff --git a/guard-examples/ci/.circleci/config.yml b/guard-examples/ci/.circleci/config.yml index 3da04dd98..7f07b1edd 100644 --- a/guard-examples/ci/.circleci/config.yml +++ b/guard-examples/ci/.circleci/config.yml @@ -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 @@ -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 @@ -68,7 +35,6 @@ jobs: executor: default steps: - checkout - - install_guard - validate - test workflows: diff --git a/guard-examples/ci/.github/workflows/junit-test-and-validate.yml b/guard-examples/ci/.github/workflows/junit-test-and-validate.yml index 03b727ff0..18a49e6b6 100644 --- a/guard-examples/ci/.github/workflows/junit-test-and-validate.yml +++ b/guard-examples/ci/.github/workflows/junit-test-and-validate.yml @@ -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()