From f8db227b3babce6313f4fa65d1b23900f959ad35 Mon Sep 17 00:00:00 2001 From: Nicolas Rey Date: Mon, 30 Sep 2024 18:32:54 -0300 Subject: [PATCH] test new tools --- .github/workflows/test-tools.yml | 24 ++++++++++++++++++++++++ Makefile | 26 +++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/test-tools.yml diff --git a/.github/workflows/test-tools.yml b/.github/workflows/test-tools.yml new file mode 100644 index 0000000..8814814 --- /dev/null +++ b/.github/workflows/test-tools.yml @@ -0,0 +1,24 @@ +name: Test Container Sec Tools + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-test: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build and test all tools + run: | + for tool in $(make list | tail -n +2); do + echo "Testing tool: $tool" + make test $tool + done diff --git a/Makefile b/Makefile index 5881816..7ac4baa 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ TOOLS := trivy trufflehog -.PHONY: help build-all build run list clean +.PHONY: help build-all build run list clean test help: @echo "Usage:" @@ -14,6 +14,7 @@ help: @echo " run -- [args...] Run a specific tool (e.g., make run trufflehog -- git ssh://github.com/reynico/container-sec-tools --only-verified)" @echo " list List all available tools" @echo " clean Remove all Docker images" + @echo " test Test a specific tool to check if it runs without errors" @echo "" @echo "Available tools:" @echo " $(TOOLS)" @@ -58,6 +59,29 @@ clean: done @echo "All images removed." +test: + @tool="$(word 2,$(MAKECMDGOALS))"; \ + if [ -z "$$tool" ]; then \ + echo "Please specify a tool to test. Available tools: $(TOOLS)"; \ + exit 1; \ + fi; \ + if echo "$(TOOLS)" | grep -wq "$$tool"; then \ + echo "Testing Docker image for $$tool"; \ + make build $$tool; \ + echo "Running $$tool to ensure it executes without errors..."; \ + docker run --rm $$tool; \ + if [ $$? -eq 0 ]; then \ + echo "Test for $$tool passed!"; \ + else \ + echo "Test for $$tool failed!"; \ + exit 1; \ + fi; \ + else \ + echo "Tool $$tool not found. Available tools: $(TOOLS)"; \ + exit 1; \ + fi + @exit 0 + # Prevent make from interpreting additional arguments as targets %: @: