From 4f4cc25ae45b446ad559a9c902e32965f5605721 Mon Sep 17 00:00:00 2001 From: MattLoe <107530444+MattLoe@users.noreply.github.com> Date: Mon, 19 Dec 2022 01:34:50 +0000 Subject: [PATCH 1/3] Fix version check in script --- pmd-analyser.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-analyser.sh b/pmd-analyser.sh index 4b0ba89..2ca8f41 100755 --- a/pmd-analyser.sh +++ b/pmd-analyser.sh @@ -1,7 +1,7 @@ # shellcheck shell=sh # 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 From f3b214265ac67d09bcd8e2acb6d41517bc25cb52 Mon Sep 17 00:00:00 2001 From: MattLoe <107530444+MattLoe@users.noreply.github.com> Date: Mon, 19 Dec 2022 01:43:10 +0000 Subject: [PATCH 2/3] Fix script if statements --- pmd-analyser.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pmd-analyser.sh b/pmd-analyser.sh index 2ca8f41..40f2179 100755 --- a/pmd-analyser.sh +++ b/pmd-analyser.sh @@ -1,7 +1,7 @@ # shellcheck shell=sh # 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 +10,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 From d9ca8290ea6400b896a60936c15aaa0513f5e283 Mon Sep 17 00:00:00 2001 From: MattLoe <107530444+MattLoe@users.noreply.github.com> Date: Mon, 19 Dec 2022 02:10:14 +0000 Subject: [PATCH 3/3] Revert prev script changes, add bash & bash shellcheck --- pmd-analyser.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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