diff --git a/Dockerfile b/Dockerfile index b5b481a..fb20bef 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,4 @@ -# Stage 1: Base Image with Vorpal CLI -FROM checkmarx/vorpal-cli:1.0.116 as build-vorpal - -# Stage 1: Build Reviewdog executable using Alpine +# Build Reviewdog executable using Alpine FROM alpine:latest AS build-reviewdog ENV REVIEWDOG_VERSION=v0.20.1 @@ -10,15 +7,14 @@ ENV REVIEWDOG_VERSION=v0.20.1 RUN apk --no-cache add curl bash \ && curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s -- -b /usr/local/bin ${REVIEWDOG_VERSION} -# Deploy the application binary -FROM cgr.dev/chainguard/bash:latest +# Base Image with Vorpal CLI +FROM checkmarx/vorpal-cli:1.0.116 AS build-vorpal # Set the working directory WORKDIR /app/bin # Copy the Reviewdog executable from the builder stage COPY --from=build-reviewdog /usr/local/bin/reviewdog /usr/local/bin/reviewdog -COPY --from=build-vorpal /app/bin/vorpal /app/bin/vorpal # Copy the entrypoint script COPY entrypoint.sh /entrypoint.sh @@ -27,4 +23,4 @@ COPY entrypoint.sh /entrypoint.sh RUN chmod +x /app/bin/vorpal /usr/local/bin/reviewdog /entrypoint.sh # Set the entrypoint -ENTRYPOINT ["/entrypoint.sh"] +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/README.md b/README.md index bff5f93..1f6d1b1 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,11 @@ With reporter: github-pr-review a comment is added to the Pull Request Conversat **Description**: Specify the source paths to analyze (comma-separated). **Required**: true +### `folders_to_ignore` + +**Description**: Specify the folders to ignore on Vorpal scan (comma-separated). +**Required**: false + ### `level` **Description**: Report level for reviewdog [info, warning, error]. @@ -117,6 +122,4 @@ jobs: ## License -Apache License Version 2.0 - - +Apache License Version 2.0 \ No newline at end of file diff --git a/action.yaml b/action.yaml index 2ee97e6..cfd8e7a 100644 --- a/action.yaml +++ b/action.yaml @@ -1,14 +1,17 @@ # action.yml -name: "Vorpal Github Action With reviewdog" -description: "Action Scan files with Vorpal engine and shows with reviewdog annotations and comments in PR" +name: 'Vorpal Github Action With reviewdog' +description: 'Action Scan files with Vorpal engine and shows with reviewdog annotations and comments in PR' inputs: github_token: description: 'GITHUB_TOKEN.' required: true default: ${{ github.token }} source_path: - description: "The path to the source code to scan" + description: 'The path to the source code to scan' required: true + folders_to_ignore: + description: 'The paths of the folders to be ignored during the Vorpal scan' + required: false level: description: 'Report level for reviewdog [info,warning,error]' default: 'error' @@ -31,10 +34,10 @@ inputs: description: 'Additional reviewdog flags' default: '' runs: - using: "docker" + using: 'docker' image: Dockerfile env: WORKSPACE_PATH: $GITHUB_WORKSPACE branding: icon: 'monitor' - color: 'purple' + color: 'purple' \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh index bc7129c..d65e2bb 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,6 +16,9 @@ else IFS=','; set -- $INPUT_SOURCE_PATH; unset IFS fi +# Parse folders to ignore +folders_to_ignore=$(echo "${INPUT_FOLDERS_TO_IGNORE}" | tr ',' ' ') + export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" # Create a file to store all the results @@ -25,14 +28,33 @@ all_results_file="all_results.errorformat" # Scan Vorpal for each file for file in "$@"; do - echo "${DATETIME} - INF : about to scan file $file" - echo "${DATETIME} - INF : vorpal command -s $file -r result.errorformat" - /app/bin/vorpal -s "$file" -r result.errorformat + # Check if the file is in any of the ignored folders + skip_file=false + for folder in $folders_to_ignore; do + if echo "$file" | grep -q "^$folder"; then + echo "${DATETIME} - INF : Skipping file $file as it is in ignored folder $folder" + skip_file=true + break + fi + done + + # If not in an ignored folder, proceed with scanning + if [ "$skip_file" = false ]; then + echo "${DATETIME} - INF : about to scan file $file" + echo "${DATETIME} - INF : vorpal command -s $file -r result.errorformat" + /app/bin/vorpal -s "$file" -r result.errorformat - # Append the results to the all_results_file - cat result.errorformat >> "$all_results_file" + # Append the results to the all_results_file + cat result.errorformat >> "$all_results_file" + fi done +# Check if the all_results_file is empty +if [ ! -s "$all_results_file" ]; then + echo "${DATETIME} - INF : No results found. Skipping Reviewdog." + exit 0 +fi + # Reviewdog echo "${DATETIME} - INF : Reviewdog executing on version $(reviewdog -version)" cat "$all_results_file" | reviewdog -efm '%f:%l:%c:%m' \