Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ All supported CLI argument inputs are [listed below](#arguments) with accompanyi
| CLI | `command` | Command to run between: `plan` or `apply`.<sup>1</sup></br>Example: `plan` |
| CLI | `tool` | Provisioning tool to use between: `terraform` or `tofu`.</br>Default: `terraform` |
| CLI | `plan-file` | Supply existing plan file path instead of the auto-generated one.</br>Example: `path/to/file.tfplan` |
| CLI | `pr-number` | Specify PR number in case of unsupported workflow trigger.</br>Example: `123` |
| Check | `format` | Check format of TF code.</br>Default: `false` |
| Check | `validate` | Check validation of TF code.</br>Default: `false` |
| Check | `plan-parity` | Replace plan file if it matches a newly-generated one to prevent stale apply.<sup>2</sup></br>Default: `false` |
Expand Down
11 changes: 10 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,16 @@ runs:
echo arg-workspace=$([[ -n "$TF_WORKSPACE" ]] && echo " -workspace=$TF_WORKSPACE" || echo "") >> "$GITHUB_OUTPUT"

- id: identifier
env:
INPUT_PR_NUMBER: ${{ inputs.pr-number }}
shell: bash
run: |
# Unique identifier.
# Get PR number using GitHub API for different event triggers.
if [[ "$GITHUB_EVENT_NAME" == "push" || "$GITHUB_EVENT_NAME" == "repository_dispatch" || "$GITHUB_EVENT_NAME" == "workflow_call" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" || "$GITHUB_EVENT_NAME" == "workflow_run" ]]; then
if [[ "$INPUT_PR_NUMBER" != "" ]]; then
# Use provided PR number if specified.
pr_number="$INPUT_PR_NUMBER"
elif [[ "$GITHUB_EVENT_NAME" == "push" || "$GITHUB_EVENT_NAME" == "repository_dispatch" || "$GITHUB_EVENT_NAME" == "workflow_call" || "$GITHUB_EVENT_NAME" == "workflow_dispatch" || "$GITHUB_EVENT_NAME" == "workflow_run" ]]; then
# List PRs associated with the commit, then get the PR number from the head ref or the latest PR.
associated_prs=$(gh api /repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha || github.sha }}/pulls --header "$GH_API" --method GET --paginate)
pr_number=$(echo "$associated_prs" | jq --raw-output '(.[] | select(.head.ref == env.GITHUB_REF_NAME) | .number) // .[0].number // 0')
Expand Down Expand Up @@ -522,6 +527,10 @@ inputs:
default: "false"
description: "Replace the plan file if it matches a newly-generated one to prevent stale apply (e.g., `false`)."
required: false
pr-number:
default: ""
description: "Specify PR number in case of unsupported workflow trigger (e.g., `123`)."
required: false
preserve-plan:
default: "false"
description: "Preserve plan file in the given working directory after workflow execution (e.g., `false`)."
Expand Down
Loading