Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration tests against aws-guard-rules-registry on Ubuntu #337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 78 additions & 10 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,109 @@ name: Rust

on:
push:
branches: [ main ]
branches: [ main, development ]
pull_request:
branches: [ main ]
branches: [ main, development ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

name: Build all crates & run unit tests
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Build
- name: Build all crates
run: cargo build --release --verbose
- name: Run tests
- name: Run unit tests
run: cargo test --verbose

shellcheck:

name: Shellcheck
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Shellcheck
run: shellcheck install-guard.sh

formatting:
name: cargo fmt
name: Formatting check (cargo fmt)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Rustfmt Check
uses: actions-rust-lang/rustfmt@v1
uses: actions-rust-lang/rustfmt@v1

aws-guard-rules-registry-ubuntu-integration-tests:
name: Integration tests against aws-guard-rules-registry on Ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
name: Checkout cfn-guard
with:
path: cloudformation-guard
- name: Build binary
run: |
cd cloudformation-guard/guard/
cargo build --release
- uses: actions/checkout@v3
name: Checkout aws-guard-rules-registry
with:
repository: aws-cloudformation/aws-guard-rules-registry
path: aws-guard-rules-registry
ref: main
- name: Run integration tests using test command
run: |
if cloudformation-guard/target/release/cfn-guard test -d aws-guard-rules-registry/rules; then
echo "The integration tests for test command have passed."
else
echo "The integration tests for test command have failed."
exit 1
fi

- name: Run integration tests using parse-tree command
run: |
cd aws-guard-rules-registry/rules

FAILED_RULES=()
SKIPPED_RULES=()
rules=( $(find . -type f -name "*.guard") )

for rule in "${rules[@]}"
do
if [ $(sed -e '/^[ \s]*#.*$/d' $rule | sed -r '/^\s*$/d' | wc -l) -eq 0 ]; then
SKIPPED_RULES+=("$rule")
elif ../../cloudformation-guard/target/release/cfn-guard parse-tree --rules $rule; then
continue
else
FAILED_RULES+=("$rule")
fi
done

SKIPPED_RULE_COUNT=${#SKIPPED_RULES[@]}
if [ $SKIPPED_RULE_COUNT -gt 0 ]; then
echo "The following $SKIPPED_RULE_COUNT rule(s) were skipped because they contained only comments:"
for skipped_rule in "${SKIPPED_RULES[@]}"
do
echo "$skipped_rule"
done
fi

FAILED_RULE_COUNT=${#FAILED_RULES[@]}

if [ $FAILED_RULE_COUNT -gt 0 ]; then
echo "The following $FAILED_RULE_COUNT rule(s) have failed the parse-tree integration tests with a non-zero error code:"
for failed_rule in "${FAILED_RULES[@]}"
do
echo "$failed_rule"
done
exit 1
else
echo "All the rules have succeeded the parse-tree integration tests."
fi


2 changes: 1 addition & 1 deletion guard/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn main() -> Result<(), Error> {
let mut output_writer: Writer = if [PARSE_TREE, MIGRATE, RULEGEN]
.contains(&command.name())
{
let writer: Writer = match app.get_one::<String>(OUTPUT.0) {
let writer: Writer = match value.get_one::<String>(OUTPUT.0) {
Some(file) => {
Writer::new(WBFile(File::create(file)?), Stderr(std::io::stderr()))
}
Expand Down