From 060fcce66ccb5ab2e766b3526d312d8090165f2a Mon Sep 17 00:00:00 2001 From: "Trez.One" Date: Fri, 7 Nov 2025 20:13:04 -0500 Subject: [PATCH] Working dir tweak. --- tf-pr-comment.sh | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tf-pr-comment.sh b/tf-pr-comment.sh index 4d60963..a6ad6f8 100644 --- a/tf-pr-comment.sh +++ b/tf-pr-comment.sh @@ -1,20 +1,25 @@ #!/usr/bin/env bash set -e +# Add OpenTofu binary to PATH export PATH="${PATH}:/home/runner/.opentofu/bin" -################## -# Inputs -################## -COMMAND="$1" # fmt | init | plan | validate -COMMENTER_INPUT="$2" # stdout/stderr output OR newline-separated file list (for fmt) -COMMENTER_EXITCODE="$3" # exit code from previous step -WORKING_DIR="$4" +# Read inputs +COMMAND=$1 +INPUT=$2 +EXIT_CODE=$3 +WORKING_DIR=$4 -# Change to working directory if provided +# Determine repo root (where .git exists) +REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null || echo "$PWD") + +# Change to working directory if provided, relative to repo root if [[ -n "$WORKING_DIR" ]]; then - echo "Switching to working directory: $WORKING_DIR" - cd "$WORKING_DIR" || { echo "Directory $WORKING_DIR not found"; exit 1; } + TARGET_DIR="$REPO_ROOT/$WORKING_DIR" + echo "Switching to working directory: $TARGET_DIR" + cd "$TARGET_DIR" || { echo "Directory $TARGET_DIR not found"; exit 1; } +else + cd "$REPO_ROOT" || { echo "Cannot determine repo root"; exit 1; } fi # Strip ANSI codes from input