Skip to content

Commit 2f153d6

Browse files
committed
Configure code analysis docker image
1 parent 18085be commit 2f153d6

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Code Analysis
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
static_analysis:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout Code
12+
uses: actions/checkout@v3
13+
14+
- name: Set Up Docker Buildx
15+
uses: docker/setup-buildx-action@v2
16+
17+
- name: Build Docker Image
18+
run: docker build -t code-analysis -f Dockerfile .
19+
20+
- name: Run Code Analysis
21+
run: |
22+
mkdir -p reports
23+
docker run --rm -v $(pwd)/reports:/app/reports code-analysis
24+
25+
- name: Upload Reports
26+
uses: actions/upload-artifact@v3
27+
with:
28+
name: code-analysis-reports
29+
path: reports/

Dockerfile.analysis

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Use the base Ruby 3.4 image
2+
FROM ruby:3.4
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Install dependencies
8+
RUN apt-get update && apt-get install -y \
9+
git \
10+
curl \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
# Install Bundler (latest version compatible with Ruby 3.4)
14+
RUN gem install rubycritic skunk
15+
16+
# Copy the entrypoint script
17+
COPY entrypoint.rb /entrypoint.rb
18+
19+
# Set execute permissions
20+
RUN chmod +x /entrypoint.rb
21+
22+
VOLUME ["/app"]
23+
24+
# Set the Ruby script as the entrypoint
25+
ENTRYPOINT ["ruby", "/entrypoint.rb"]

entrypoint.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env ruby
2+
3+
# Get arguments passed to the container
4+
commands = ARGV
5+
6+
# Default behavior: Run both tools if no args are provided
7+
if commands.empty?
8+
puts "No arguments provided. Running both RubyCritic and Skunk..."
9+
system("rubycritic")
10+
system("skunk -o skunk.txt")
11+
exit 0
12+
end
13+
14+
# Execute based on provided arguments
15+
commands.each do |command|
16+
case command
17+
when "rubycritic"
18+
puts "Running RubyCritic..."
19+
system("rubycritic")
20+
when "skunk"
21+
puts "Running Skunk..."
22+
system("skunk -o skunk.txt")
23+
else
24+
puts "Invalid argument: #{command}"
25+
puts "Usage: docker run --rm <image> [rubycritic] [skunk]"
26+
exit 1
27+
end
28+
end

0 commit comments

Comments
 (0)