From 1b630100a5e28893467bec32b370757594717cd0 Mon Sep 17 00:00:00 2001 From: "Trez.One" Date: Fri, 7 Nov 2025 12:54:16 -0500 Subject: [PATCH] Working dir input. --- action.yml | 16 +++++++++------- tf-pr-comment.sh | 11 ++++++++++- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/action.yml b/action.yml index 6521197..5d26706 100644 --- a/action.yml +++ b/action.yml @@ -2,7 +2,6 @@ name: "Terraform/OpenTofu PR Commenter" description: "Posts Terraform/OpenTofu `fmt`, `init`, `plan`, or `validate` results as PR comments on GitHub or Gitea." author: "Charish Patel" -# Define the inputs inputs: command: description: "The command type: fmt | init | plan | validate" @@ -46,9 +45,11 @@ inputs: description: "Terraform/OpenTofu workspace (default: 'default')" required: false default: default + working_directory: + description: "Optional working directory relative to repo root; if set, script runs there" + required: false + default: "" - -# Define the action type runs: using: "composite" steps: @@ -56,9 +57,12 @@ runs: shell: bash run: | chmod +x ${{ github.action_path }}/tf-pr-comment.sh - ${{ github.action_path }}/tf-pr-comment.sh "${{ inputs.command }}" "${{ inputs.commenter_input }}" "${{ inputs.commenter_exitcode }}" + ${{ github.action_path }}/tf-pr-comment.sh \ + "${{ inputs.command }}" \ + "${{ inputs.commenter_input }}" \ + "${{ inputs.commenter_exitcode }}" \ + "${{ inputs.working_directory }}" env: - # PR Environment Variables PR_NUMBER: ${{ inputs.pr_number }} PR_COMMENTS_URL: ${{ inputs.pr_comments_url }} PR_COMMENT_URI: ${{ inputs.pr_comment_uri }} @@ -67,7 +71,5 @@ runs: GITEA_ACTION: ${{ inputs.gitea_action }} GITEA_API_URL: ${{ inputs.gitea_api_url }} GITEA_REPOSITORY: ${{ inputs.gitea_repository }} - # Optional highlighting HIGHLIGHT_CHANGES: ${{ inputs.highlight_changes }} TF_WORKSPACE: ${{ inputs.tf_workspace }} - diff --git a/tf-pr-comment.sh b/tf-pr-comment.sh index 12cf734..4d60963 100644 --- a/tf-pr-comment.sh +++ b/tf-pr-comment.sh @@ -9,7 +9,16 @@ export PATH="${PATH}:/home/runner/.opentofu/bin" 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 -WORKSPACE="${TF_WORKSPACE:-default}" +WORKING_DIR="$4" + +# Change to working directory if provided +if [[ -n "$WORKING_DIR" ]]; then + echo "Switching to working directory: $WORKING_DIR" + cd "$WORKING_DIR" || { echo "Directory $WORKING_DIR not found"; exit 1; } +fi + +# Strip ANSI codes from input +# INPUT=$(echo "$INPUT" | sed 's/\x1b\[[0-9;]*m//g') ################## # CI Detection