From 2f153d67b5fff31ba92609a84f7d541fa9c24aeb Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Wed, 12 Feb 2025 14:07:40 -0300 Subject: [PATCH 1/5] Configure code analysis docker image --- .github/workflows/code-analysis.yml | 29 +++++++++++++++++++++++++++++ Dockerfile.analysis | 25 +++++++++++++++++++++++++ entrypoint.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 .github/workflows/code-analysis.yml create mode 100644 Dockerfile.analysis create mode 100644 entrypoint.rb diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 00000000..e2fc2eb2 --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,29 @@ +name: Code Analysis + +on: + pull_request: + +jobs: + static_analysis: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Set Up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build Docker Image + run: docker build -t code-analysis -f Dockerfile . + + - name: Run Code Analysis + run: | + mkdir -p reports + docker run --rm -v $(pwd)/reports:/app/reports code-analysis + + - name: Upload Reports + uses: actions/upload-artifact@v3 + with: + name: code-analysis-reports + path: reports/ diff --git a/Dockerfile.analysis b/Dockerfile.analysis new file mode 100644 index 00000000..5a74b937 --- /dev/null +++ b/Dockerfile.analysis @@ -0,0 +1,25 @@ +# Use the base Ruby 3.4 image +FROM ruby:3.4 + +# Set working directory +WORKDIR /app + +# Install dependencies +RUN apt-get update && apt-get install -y \ + git \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Install Bundler (latest version compatible with Ruby 3.4) +RUN gem install rubycritic skunk + +# Copy the entrypoint script +COPY entrypoint.rb /entrypoint.rb + +# Set execute permissions +RUN chmod +x /entrypoint.rb + +VOLUME ["/app"] + +# Set the Ruby script as the entrypoint +ENTRYPOINT ["ruby", "/entrypoint.rb"] diff --git a/entrypoint.rb b/entrypoint.rb new file mode 100644 index 00000000..6ac90aca --- /dev/null +++ b/entrypoint.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby + +# Get arguments passed to the container +commands = ARGV + +# Default behavior: Run both tools if no args are provided +if commands.empty? + puts "No arguments provided. Running both RubyCritic and Skunk..." + system("rubycritic") + system("skunk -o skunk.txt") + exit 0 +end + +# Execute based on provided arguments +commands.each do |command| + case command + when "rubycritic" + puts "Running RubyCritic..." + system("rubycritic") + when "skunk" + puts "Running Skunk..." + system("skunk -o skunk.txt") + else + puts "Invalid argument: #{command}" + puts "Usage: docker run --rm [rubycritic] [skunk]" + exit 1 + end +end From 1ec8d2dc6ad34d3ff0f636a592661029ce64444d Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Wed, 12 Feb 2025 14:10:27 -0300 Subject: [PATCH 2/5] Use v4 of upload-artifact action --- .github/workflows/code-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index e2fc2eb2..7a82c64b 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -23,7 +23,7 @@ jobs: docker run --rm -v $(pwd)/reports:/app/reports code-analysis - name: Upload Reports - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: code-analysis-reports path: reports/ From ac8caa18489e38acf14d710385d2f5a33ce8c7c6 Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Wed, 12 Feb 2025 14:11:42 -0300 Subject: [PATCH 3/5] Fix Dockerfile name --- .github/workflows/code-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index 7a82c64b..50d14075 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -15,7 +15,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Build Docker Image - run: docker build -t code-analysis -f Dockerfile . + run: docker build -t code-analysis -f Dockerfile.analysis . - name: Run Code Analysis run: | From fcdce1021e2d8c379561ca14fd49928427c6195d Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Wed, 12 Feb 2025 14:19:00 -0300 Subject: [PATCH 4/5] Fix rubycritic and skunk calls to save artifacts in the right folder --- entrypoint.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/entrypoint.rb b/entrypoint.rb index 6ac90aca..093c0d17 100644 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -3,11 +3,18 @@ # Get arguments passed to the container commands = ARGV +def run_rubycritic + system("rubycritic -p reports/rubycritic") +end + +def run_skunk + system("skunk -o reports/skunk.txt") +end + # Default behavior: Run both tools if no args are provided if commands.empty? puts "No arguments provided. Running both RubyCritic and Skunk..." - system("rubycritic") - system("skunk -o skunk.txt") + run_rubycritic exit 0 end @@ -16,10 +23,10 @@ case command when "rubycritic" puts "Running RubyCritic..." - system("rubycritic") + run_rubycritic when "skunk" puts "Running Skunk..." - system("skunk -o skunk.txt") + run_skunk else puts "Invalid argument: #{command}" puts "Usage: docker run --rm [rubycritic] [skunk]" From 4219d325529768edd47c7b79bd358bf338a2d849 Mon Sep 17 00:00:00 2001 From: Mateus Pereira Date: Wed, 12 Feb 2025 14:22:25 -0300 Subject: [PATCH 5/5] Run skunk --- entrypoint.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.rb b/entrypoint.rb index 093c0d17..a5b054f9 100644 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -15,6 +15,7 @@ def run_skunk if commands.empty? puts "No arguments provided. Running both RubyCritic and Skunk..." run_rubycritic + run_skunk exit 0 end