Skip to content

Commit

Permalink
Revert prev script changes, add bash & bash shellcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
MattLoe committed Dec 19, 2022
1 parent f3b2142 commit d9ca829
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pmd-analyser.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# shellcheck shell=sh
#!/bin/bash

# shellcheck shell=bash

# Check whether to use latest version of PMD
if [ "$PMD_VERSION" = 'latest' ]; then
if [ "$PMD_VERSION" == 'latest' ]; then
LATEST_TAG="$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/pmd/pmd/releases/latest | jq --raw-output '.tag_name')"
PMD_VERSION="${LATEST_TAG#"pmd_releases/"}"
fi
Expand All @@ -10,13 +12,13 @@ fi
wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F"${PMD_VERSION}"/pmd-bin-"${PMD_VERSION}".zip
unzip pmd-bin-"${PMD_VERSION}".zip
# Now either run the full analysis or files changed based on the settings defined
if [ "$ANALYSE_ALL_CODE" = 'true' ]; then
if [ "$ANALYSE_ALL_CODE" == 'true' ]; then
pmd-bin-"${PMD_VERSION}"/bin/run.sh pmd -d "$FILE_PATH" -R "$RULES_PATH" -failOnViolation false -f sarif > pmd-raw-output.sarif
else
if [ "$ACTION_EVENT_NAME" = 'pull_request' ]; then
if [ "$ACTION_EVENT_NAME" == 'pull_request' ]; then
# Now to determine whether to get the files changed from a git diff or using the files changed in a GitHub Pull Request
# Both options will generate a CSV file first with the files changed
if [ "$FILE_DIFF_TYPE" = 'git' ]; then
if [ "$FILE_DIFF_TYPE" == 'git' ]; then
git diff --name-only --diff-filter=d origin/"$CURRENT_CODE"..origin/"${CHANGED_CODE#"refs/heads/"}" | paste -s -d "," >> diff-file.csv
else
curl -H "Accept: application/vnd.github.v3+json" -H "Authorization: token ${AUTH_TOKEN}" https://api.github.com/repos/"$REPO_NAME"/pulls/"$PR_NUMBER"/files | jq --raw-output '.[] .filename' | paste -s -d "," >> diff-file.csv
Expand All @@ -32,7 +34,7 @@ fi
echo "::set-output name=error-found::false"
while read -r rule; do
RULE="$(echo "$rule" | jq --raw-output '.id')"
if [[ $RULE && "$ERROR_RULES" == *"$RULE"* ]]; then
if [[ "$RULE" && "$ERROR_RULES" == *"$RULE"* ]]; then
echo "::set-output name=error-found::true"
break
fi
Expand Down

0 comments on commit d9ca829

Please sign in to comment.