Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show-args parameter #357

Merged
merged 8 commits into from
Nov 8, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/tf_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: TF Tests

on:
pull_request:
paths: [.github/workflows/tf_tests.yaml, tests/**]
paths: [.github/workflows/tf_tests.yaml, action.yml, tests/**]
types: [opened, reopened, synchronize, closed]

jobs:
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ For each workflow run, a matrix-friendly job summary with logs is added as a fal
| Security | `token` | Specify a GitHub token.</br>Default: `${{ github.token }}` |
| UI | `comment-pr` | PR comment by: `update` existing comment, `recreate` and delete previous one, or `none`.</br>Default: `update` |
| UI | `label-pr` | Add a PR label with the command input.</br>Default: `true` |
| UI | `hide-args` | Hide comma-separated list of CLI arguments from the command input.</br>Default: `detailed-exitcode,lock,out,var` |
| UI | `hide-args` | Hide comma-separated list of CLI arguments from the command input.</br>Default: `detailed-exitcode,lock,out,var=` |
| UI | `show-args` | Show comma-separated list of CLI arguments in the command input.</br>Default: `workspace` |
</br>

The default behavior of `comment-pr` is to update the existing PR comment with the latest plan output, making it easy to track changes over time through the comment's revision history.</br>
Expand Down
29 changes: 21 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ runs:
echo arg-var-file=$([[ -n "${{ inputs.arg-var-file }}" ]] && echo " -var-file=${{ inputs.arg-var-file }}" || echo "") >> "$GITHUB_OUTPUT"
echo arg-var=$([[ -n "${{ inputs.arg-var }}" ]] && echo " -var=${{ inputs.arg-var }}" | sed "s/,/ -var=/g" || echo "") >> "$GITHUB_OUTPUT"
echo arg-write=$([[ -n "${{ inputs.arg-write }}" ]] && echo " -write=${{ inputs.arg-write }}" || echo "") >> "$GITHUB_OUTPUT"
echo arg-workspace=$([[ -n "${{ inputs.arg-workspace }}" ]] && echo " -workspace=${{ inputs.arg-workspace }}" || echo "") >> "$GITHUB_OUTPUT"

- id: identifier
env:
Expand Down Expand Up @@ -203,7 +204,7 @@ runs:

# Diff of changes.
# Filter lines starting with " # " and save to tf.diff.txt, then prepend diff-specific symbols based on specific keywords.
grep -E '^ # ' tf.console.txt | sed -e 's/^ # \(.* be created\)/+ \1/' -e 's/^ # \(.* be destroyed\)/- \1/' -e 's/^ # \(.* be updated\|.* be replaced\)/! \1/' -e 's/^ # \(.* be read\)/~ \1/' -e 's/^ # \(.*\)/# \1/' > tf.diff.txt || true
grep '^ # ' tf.console.txt | sed -e 's/^ # \(.* be created\)/+ \1/' -e 's/^ # \(.* be destroyed\)/- \1/' -e 's/^ # \(.* be updated\|.* be replaced\)/! \1/' -e 's/^ # \(.* be read\)/~ \1/' -e 's/^ # \(.*\)/# \1/' > tf.diff.txt || true

- if: ${{ inputs.plan-encrypt != '' && steps.plan.outcome == 'success' }}
env:
Expand Down Expand Up @@ -267,12 +268,20 @@ runs:
# Parse the tf.command.txt file.
command=$(cat tf.command.txt)

# Remove each comma-delemited argument from the command.
IFS=',' read -ra args <<< "${{ inputs.hide-args }}="
for arg in "${args[@]}"; do
command=$(echo "$command" | grep --invert-match "^ -${arg}\b")
# Remove each comma-delemited hide-args argument from the command.
IFS=',' read -ra hide_args <<< "${{ inputs.hide-args }}"
for arg in "${hide_args[@]}"; do
command=$(echo "$command" | grep --invert-match "^ -${arg}" || true)
done
command=$(echo "$command" | tr -d '\n')

# Conversely, show each comma-delemited show-args argument in the command.
command_append=""
IFS=',' read -ra show_args <<< "${{ inputs.show-args }}"
for arg in "${show_args[@]}"; do
command_append+=$(echo "${{ steps.arg.outputs.arg-workspace }}${{ steps.arg.outputs.arg-backend-config }}${{ steps.arg.outputs.arg-backend }}${{ steps.arg.outputs.arg-backup }}${{ steps.arg.outputs.arg-check }}${{ steps.arg.outputs.arg-compact-warnings }}${{ steps.arg.outputs.arg-concise }}${{ steps.arg.outputs.arg-destroy }}${{ steps.arg.outputs.arg-detailed-exitcode }}${{ steps.arg.outputs.arg-diff }}${{ steps.arg.outputs.arg-force-copy }}${{ steps.arg.outputs.arg-from-module }}${{ steps.arg.outputs.arg-generate-config-out }}${{ steps.arg.outputs.arg-get }}${{ steps.arg.outputs.arg-list }}${{ steps.arg.outputs.arg-lock-timeout }}${{ steps.arg.outputs.arg-lock }}${{ steps.arg.outputs.arg-lockfile }}${{ steps.arg.outputs.arg-migrate-state }}${{ steps.arg.outputs.arg-no-tests }}${{ steps.arg.outputs.arg-or-create }}${{ steps.arg.outputs.arg-parallelism }}${{ steps.arg.outputs.arg-plugin-dir }}${{ steps.arg.outputs.arg-reconfigure }}${{ steps.arg.outputs.arg-recursive }}${{ steps.arg.outputs.arg-refresh-only }}${{ steps.arg.outputs.arg-refresh }}${{ steps.arg.outputs.arg-replace }}${{ steps.arg.outputs.arg-state-out }}${{ steps.arg.outputs.arg-state }}${{ steps.arg.outputs.arg-target }}${{ steps.arg.outputs.arg-test-directory }}${{ steps.arg.outputs.arg-upgrade }}${{ steps.arg.outputs.arg-var-file }}${{ steps.arg.outputs.arg-var }}${{ steps.arg.outputs.arg-write }}${{ steps.arg.outputs.arg-auto-approve }}" | sed 's/ -/\n -/g' | grep "^ -${arg}" || true)
done

command=$(echo "$command" | tr -d '\n')$command_append
echo "command=$command" >> "$GITHUB_OUTPUT"

# Parse the tf.console.txt file, truncated for character limit.
Expand Down Expand Up @@ -432,8 +441,8 @@ inputs:
description: "Check format of TF code (e.g., `false`)."
required: false
hide-args:
default: "detailed-exitcode,lock,out,var"
description: "Hide comma-separated arguments from the command input (e.g., `detailed-exitcode,lock,out,var`)."
default: "detailed-exitcode,lock,out,var="
description: "Hide comma-separated arguments from the command input (e.g., `detailed-exitcode,lock,out,var=`)."
required: false
label-pr:
default: "true"
Expand All @@ -447,6 +456,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
show-args:
default: "workspace"
description: "Show comma-separated arguments in the command input (e.g., `workspace`)."
required: false
token:
default: ${{ github.token }}
description: "Specify a GitHub token (e.g., `secrets.GITHUB_TOKEN`)."
Expand Down
Loading