diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 00000000..50d14075 --- /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.analysis . + + - 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@v4 + 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..a5b054f9 --- /dev/null +++ b/entrypoint.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby + +# 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..." + run_rubycritic + run_skunk + exit 0 +end + +# Execute based on provided arguments +commands.each do |command| + case command + when "rubycritic" + puts "Running RubyCritic..." + run_rubycritic + when "skunk" + puts "Running Skunk..." + run_skunk + else + puts "Invalid argument: #{command}" + puts "Usage: docker run --rm [rubycritic] [skunk]" + exit 1 + end +end