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

Make scanned code path configurable #15

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ branding:
color: gray-dark
icon: chevrons-up
inputs:
path:
description: "Relative path from your project root to the codebase to scanned"
required: false
default: ""
config_file:
description: "Optionally provide a path to your codeclimate.yml relative to your project"
required: false
Expand Down Expand Up @@ -57,6 +61,7 @@ runs:
shell: bash
id: cc
env:
CC_CODE: ${{ github.workspace }}/${{ inputs.path }}
CC_CONF: ${{ inputs.config_file }}
CC_BLOCKERS_ALLOWED: ${{ inputs.blocker_threshold }}
CC_CRITICAL_ALLOWED: ${{ inputs.critical_threshold }}
Expand All @@ -69,7 +74,7 @@ runs:
# and accuracy

echo "#### CONFIG ####"
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
if [ cp "$CC_CONF" "$CC_CODE/.codeclimate.yml"; then
echo "Found codeclimate config, using that"
else
echo "::warning::No configuration found, using Code Climate's default configuration"
Expand All @@ -78,14 +83,14 @@ runs:
# Run once for JSON output
echo "#### INITIAL RUN ####"
docker run \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--env CODECLIMATE_CODE="$CC_CODE" \
--volume "$CC_CODE":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze -f json > raw.json

# Strip the json to only issues
jq -c 'map(select(.type | test("issue"; "i")))' raw.json > codeclimate-report.json
jq -c 'map(select(.type | test("issue"; "i")))' "$CC_CODE/raw.json" > codeclimate-report.json

# Parse to provide simple job output
TOTAL_ISSUES=$(jq '. | length' codeclimate-report.json)
Expand All @@ -108,6 +113,7 @@ runs:
- name: Generate HTML Report
shell: bash
env:
CC_CODE: ${{ github.workspace }}/${{ inputs.path }}
CC_CONF: ${{ inputs.config_file }}
HTML_REPORT: ${{ inputs.html_report }}
run: |
Expand All @@ -117,20 +123,21 @@ runs:
# and accuracy

echo "#### CONFIG ####"
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
echo "Found codeclimate.yml at project root"
if [ cp "$CC_CONF" "$CC_CODE/.codeclimate.yml"; then
echo "Found codeclimate config, using that"
else
echo "::warning::No configuration found, using Code Climate's default configuration"
fi

# Run for HTML output
echo "#### GENERATING HTML VERSION ####"
docker run \
--env CODECLIMATE_CODE="$PWD" \
--volume "$PWD":/code \
--env CODECLIMATE_CODE="$CC_CODE" \
--volume "$CC_CODE":/code \
--volume /var/run/docker.sock:/var/run/docker.sock \
--volume /tmp/cc:/tmp/cc \
codeclimate/codeclimate analyze -f html > codeclimate-report.html
mv "$CC_CODE/codeclimate-report.html" codeclimate-report.html
else
echo "HTML REPORT not requested, skipping..."
fi
Expand Down