Skip to content

Commit dcf4e6b

Browse files
committed
feat: make scanned code location configurable
1 parent 3c12f11 commit dcf4e6b

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

action.yml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ branding:
55
color: gray-dark
66
icon: chevrons-up
77
inputs:
8+
path:
9+
description: "Relative path from your project root to the codebase to scanned"
10+
required: false
11+
default: ""
812
config_file:
913
description: "Optionally provide a path to your codeclimate.yml relative to your project"
1014
required: false
@@ -57,6 +61,7 @@ runs:
5761
shell: bash
5862
id: cc
5963
env:
64+
CC_CODE: ${{ github.workspace }}/${{ inputs.path }}
6065
CC_CONF: ${{ inputs.config_file }}
6166
CC_BLOCKERS_ALLOWED: ${{ inputs.blocker_threshold }}
6267
CC_CRITICAL_ALLOWED: ${{ inputs.critical_threshold }}
@@ -69,7 +74,7 @@ runs:
6974
# and accuracy
7075
7176
echo "#### CONFIG ####"
72-
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
77+
if [ cp "$CC_CONF" "$CC_CODE/.codeclimate.yml"; then
7378
echo "Found codeclimate config, using that"
7479
else
7580
echo "::warning::No configuration found, using Code Climate's default configuration"
@@ -78,14 +83,14 @@ runs:
7883
# Run once for JSON output
7984
echo "#### INITIAL RUN ####"
8085
docker run \
81-
--env CODECLIMATE_CODE="$PWD" \
82-
--volume "$PWD":/code \
86+
--env CODECLIMATE_CODE="$CC_CODE" \
87+
--volume "$CC_CODE":/code \
8388
--volume /var/run/docker.sock:/var/run/docker.sock \
8489
--volume /tmp/cc:/tmp/cc \
8590
codeclimate/codeclimate analyze -f json > raw.json
8691
8792
# Strip the json to only issues
88-
jq -c 'map(select(.type | test("issue"; "i")))' raw.json > codeclimate-report.json
93+
jq -c 'map(select(.type | test("issue"; "i")))' "$CC_CODE/raw.json" > codeclimate-report.json
8994
9095
# Parse to provide simple job output
9196
TOTAL_ISSUES=$(jq '. | length' codeclimate-report.json)
@@ -108,6 +113,7 @@ runs:
108113
- name: Generate HTML Report
109114
shell: bash
110115
env:
116+
CC_CODE: ${{ github.workspace }}/${{ inputs.path }}
111117
CC_CONF: ${{ inputs.config_file }}
112118
HTML_REPORT: ${{ inputs.html_report }}
113119
run: |
@@ -117,20 +123,21 @@ runs:
117123
# and accuracy
118124
119125
echo "#### CONFIG ####"
120-
if [ -f .codeclimate.yml ] || cp "$CC_CONF" .codeclimate.yml; then
121-
echo "Found codeclimate.yml at project root"
126+
if [ cp "$CC_CONF" "$CC_CODE/.codeclimate.yml"; then
127+
echo "Found codeclimate config, using that"
122128
else
123129
echo "::warning::No configuration found, using Code Climate's default configuration"
124130
fi
125131
126132
# Run for HTML output
127133
echo "#### GENERATING HTML VERSION ####"
128134
docker run \
129-
--env CODECLIMATE_CODE="$PWD" \
130-
--volume "$PWD":/code \
135+
--env CODECLIMATE_CODE="$CC_CODE" \
136+
--volume "$CC_CODE":/code \
131137
--volume /var/run/docker.sock:/var/run/docker.sock \
132138
--volume /tmp/cc:/tmp/cc \
133139
codeclimate/codeclimate analyze -f html > codeclimate-report.html
140+
mv "$CC_CODE/codeclimate-report.html" codeclimate-report.html
134141
else
135142
echo "HTML REPORT not requested, skipping..."
136143
fi

0 commit comments

Comments
 (0)