diff --git a/pmd-analyser.sh b/pmd-analyser.sh index 40f2179..2ca30b9 100755 --- a/pmd-analyser.sh +++ b/pmd-analyser.sh @@ -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 @@ -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 @@ -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