Skip to content

Commit 95e2702

Browse files
committed
[infra] update actions
1 parent 605481b commit 95e2702

1 file changed

Lines changed: 100 additions & 11 deletions

File tree

actions/aws-terraform-runner/action.yml

Lines changed: 100 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ runs:
240240
write_output terraform_version "$TFV"
241241
write_output workspace "$WS"
242242
243-
- name: Terraform Summary
243+
- name: Summary
244244
if: inputs.show_summary != 'false'
245245
continue-on-error: true
246246
shell: bash
@@ -257,7 +257,7 @@ runs:
257257
AWS_REGION: ${{ inputs.aws_region }}
258258
run: |
259259
set -eo pipefail
260-
[[ "$LIMIT" =~ ^[0-9]+$ ]] || LIMIT=250
260+
[[ "$LIMIT" =~ ^[0-9]+$ ]] || LIMIT=50
261261
262262
WS="${TF_WORKSPACE:-}"
263263
[ -z "$WS" ] && WS="default"
@@ -273,20 +273,109 @@ runs:
273273
[ -n "${BACKEND_REGION:-}" ] && echo " in \`${BACKEND_REGION}\`"
274274
fi
275275
[ -n "${AWS_REGION:-}" ] && echo "- **AWS region (vars):** \`${AWS_REGION}\`"
276+
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
277+
278+
if [ "${TF_COMMAND:-}" = "plan" ] && [ -f tfplan ]; then
279+
if command -v jq >/dev/null 2>&1; then
280+
terraform show -json tfplan > /tmp/plan.json || true
281+
282+
ADDS=$(jq '[.resource_changes[]? | select(.change.actions == ["create"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
283+
UPDS=$(jq '[.resource_changes[]? | select(.change.actions == ["update"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
284+
REPL=$(jq '[.resource_changes[]? | select(.change.actions == ["delete","create"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
285+
DELS=$(jq '[.resource_changes[]? | select(.change.actions == ["delete"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
286+
TOTAL=$((ADDS+UPDS+REPL+DELS))
287+
288+
{
289+
echo
290+
echo "### 📋 Change summary"
291+
echo "- ➕ **create:** ${ADDS}"
292+
echo "- ✏️ **update:** ${UPDS}"
293+
echo "- 🔁 **replace:** ${REPL}"
294+
echo "- ➖ **delete:** ${DELS}"
295+
echo "- **total:** ${TOTAL}"
296+
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
276297
277-
if [ "${TF_COMMAND:-}" = "plan" ] && [ -f tfplan ]; then
278-
echo
279-
if command -v terraform >/dev/null 2>&1; then
280-
TOTAL_LINES=$(terraform show -no-color tfplan | wc -l | awk '{print $1}')
298+
{
299+
echo
300+
echo "### 🔎 Top ${LIMIT} changes"
301+
echo
302+
jq -r --argjson limit "$LIMIT" '
303+
.resource_changes // [] |
304+
map({addr: .address, act: .change.actions}) |
305+
map({
306+
addr,
307+
badge:
308+
(if .act==["create"] then "➕ create"
309+
elif .act==["update"] then "✏️ update"
310+
elif .act==["delete","create"] then "🔁 replace"
311+
elif .act==["delete"] then "➖ delete"
312+
else (.act|join(",")) end)
313+
}) |
314+
sort_by(
315+
(if .badge|test("^➕") then 0
316+
elif .badge|test("^✏️") then 1
317+
elif .badge|test("^🔁") then 2
318+
elif .badge|test("^➖") then 3
319+
else 4 end),
320+
.addr
321+
) |
322+
.[:$limit] |
323+
if length==0 then "*(no resource changes)*"
324+
else map("- `\(.addr)` — **\(.badge)**")[] end
325+
' /tmp/plan.json
326+
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
327+
328+
{
329+
echo
330+
echo "<details>"
331+
echo "<summary>Show attribute-level changes (first ${LIMIT})</summary>"
332+
echo
333+
echo '```'
334+
jq -r --argjson limit "$LIMIT" '
335+
.resource_changes // [] |
336+
.[:$limit] |
337+
.[] |
338+
.address as $a |
339+
.change.actions as $act |
340+
(
341+
if $act==["create"] then "CREATE " + $a
342+
elif $act==["update"] then "UPDATE " + $a
343+
elif $act==["delete","create"] then "REPLACE " + $a
344+
elif $act==["delete"] then "DELETE " + $a
345+
else ( ($act|join(",")) + " " + $a) end
346+
) as $head |
347+
(
348+
.change.after_unknown // {} | keys_unsorted[]? |
349+
" ~ unknown: " + .
350+
),
351+
(
352+
.change.before? as $b |
353+
.change.after? as $c |
354+
([$b,$c] | any) |
355+
if . then
356+
( ($b // {}) as $bb | ($c // {}) as $cc |
357+
( ($bb|keys_unsorted + $cc|keys_unsorted) | unique )[] |
358+
select( ($bb[.]|tostring) != ($cc[.]|tostring) ) |
359+
" ~ " + .
360+
)
361+
else empty end
362+
)
363+
' /tmp/plan.json
364+
echo '```'
365+
echo
366+
echo "</details>"
367+
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
368+
369+
else
370+
TOTAL_LINES=$(terraform show -no-color tfplan | wc -l | awk '{print $1}')
371+
{
372+
echo
281373
echo "### 📄 Plan (first ${LIMIT} lines${TOTAL_LINES:+ of ${TOTAL_LINES}})"
282374
terraform show -no-color tfplan | sed -n "1,${LIMIT}p"
283375
if [ -n "${TOTAL_LINES:-}" ] && [ "$TOTAL_LINES" -gt "$LIMIT" ]; then
284376
echo
285377
echo "_…truncated, total lines: $TOTAL_LINES_"
286378
fi
287-
else
288-
echo "### 📄 Plan"
289-
echo "_terraform binary not available to render plan output_"
290-
fi
379+
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
291380
fi
292-
} >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
381+
fi

0 commit comments

Comments
 (0)