@@ -236,47 +236,88 @@ jobs:
236236 needs : [ plan-common, plan-dev, plan-prod ]
237237 if : always()
238238 steps :
239+ - name : Generate Comment Body
240+ id : comment
241+ run : |
242+ cat > comment.md << 'EOF'
243+ ## 📄 Terraform Plan Summary
244+
245+ ### 🛡️ Common Infrastructure
246+ ```
247+ EOF
248+ echo "${{ needs.plan-common.outputs.summary_output || 'No output available' }}" >> comment.md
249+ cat >> comment.md << 'EOF'
250+ ```
251+ EOF
252+
253+ if [ "${{ needs.plan-common.outputs.plan_status }}" = "error" ]; then
254+ echo "**Status:** ❌ Failed" >> comment.md
255+ elif [ "${{ needs.plan-common.outputs.plan_status }}" = "changes" ]; then
256+ echo "**Status:** 🔄 Changes Detected" >> comment.md
257+ else
258+ echo "**Status:** ✅ No Changes" >> comment.md
259+ fi
260+
261+ if [ "${{ needs.plan-dev.result }}" != "skipped" ]; then
262+ cat >> comment.md << 'EOF'
263+
264+ ---
265+ ### 🛠️ Development Environment
266+ ```
267+ EOF
268+ echo "${{ needs.plan-dev.outputs.summary_output || 'No output available' }}" >> comment.md
269+ cat >> comment.md << 'EOF'
270+ ```
271+ EOF
272+
273+ if [ "${{ needs.plan-dev.outputs.plan_status }}" = "error" ]; then
274+ echo "**Status:** ❌ Failed" >> comment.md
275+ elif [ "${{ needs.plan-dev.outputs.plan_status }}" = "changes" ]; then
276+ echo "**Status:** 🔄 Changes Detected" >> comment.md
277+ else
278+ echo "**Status:** ✅ No Changes" >> comment.md
279+ fi
280+ fi
281+
282+ if [ "${{ needs.plan-prod.result }}" != "skipped" ]; then
283+ cat >> comment.md << 'EOF'
284+
285+ ---
286+ ### 🚀 Production Environment
287+ ```
288+ EOF
289+ echo "${{ needs.plan-prod.outputs.summary_output || 'No output available' }}" >> comment.md
290+ cat >> comment.md << 'EOF'
291+ ```
292+ EOF
293+
294+ if [ "${{ needs.plan-prod.outputs.plan_status }}" = "error" ]; then
295+ echo "**Status:** ❌ Failed" >> comment.md
296+ elif [ "${{ needs.plan-prod.outputs.plan_status }}" = "changes" ]; then
297+ echo "**Status:** 🔄 Changes Detected" >> comment.md
298+ else
299+ echo "**Status:** ✅ No Changes" >> comment.md
300+ fi
301+ fi
302+
303+ cat >> comment.md << 'EOF'
304+
305+ ---
306+ 📋 **Full Results:** [View in Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
307+ EOF
308+
309+ {
310+ echo "body<<EOF"
311+ cat comment.md
312+ echo "EOF"
313+ } >> "$GITHUB_OUTPUT"
314+
239315 - name : Comment PR with Plan Summary
240316 uses : peter-evans/create-or-update-comment@v4
241317 with :
242318 token : ${{ secrets.GITHUB_TOKEN }}
243319 issue-number : ${{ github.event.pull_request.number }}
244- body : |
245- ## 📄 Terraform Plan Summary
246-
247- ### 🛡️ Common Infrastructure
248- ```
249- ${{ needs.plan-common.outputs.summary_output || 'No output available' }}
250- ```
251- **Status:** ${{ needs.plan-common.outputs.plan_status == 'error' && '❌ Failed' || needs.plan-common.outputs.plan_status == 'changes' && '🔄 Changes Detected' || '✅ No Changes' }}
252-
253- ${{ needs.plan-dev.result != 'skipped' && '---' || '' }}
254- ${{ needs.plan-dev.result != 'skipped' && '### 🛠️ Development Environment' || '' }}
255- ${{ needs.plan-dev.result != 'skipped' && '```
256- ${{ needs.plan-dev.result != 'skipped' && (needs.plan-dev.outputs.summary_output || 'No output available') || '' }}
257- ${{ needs.plan-dev.result != 'skipped' && '```' || '' }}
258- ${{ needs.plan-dev.result != 'skipped' && format('**Status:** {0}', needs.plan-dev.outputs.plan_status == 'error' && '❌ Failed' || needs.plan-dev.outputs.plan_status == 'changes' && '🔄 Changes Detected' || '✅ No Changes') || '' }}
259-
260- ${{ needs.plan-prod.result != 'skipped' && '---' || '' }}
261- ${{ needs.plan-prod.result != 'skipped' && '### 🚀 Production Environment' || '' }}
262- ${{ needs.plan-prod.result != 'skipped' && '```
263- ${{ needs.plan-prod.result != 'skipped' && (needs.plan-prod.outputs.summary_output || 'No output available') || '' }}
264- ${{ needs.plan-prod.result != 'skipped' && '```' || '' }}
265- ${{ needs.plan-prod.result != 'skipped' && format('**Status:** {0}', needs.plan-prod.outputs.plan_status == 'error' && '❌ Failed' || needs.plan-prod.outputs.plan_status == 'changes' && '🔄 Changes Detected' || '✅ No Changes') || '' }}
266-
267- ---
268-
269- 📋 **Full Terraform Plan Results:** [View in Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
270-
271- <details>
272- <summary>📊 Execution Summary</summary>
273-
274- - **Common:** ${{ needs.plan-common.result }}
275- - **Dev:** ${{ needs.plan-dev.result }}
276- - **Prod:** ${{ needs.plan-prod.result }}
277-
278- </details>
279-
320+ body : ${{ steps.comment.outputs.body }}
280321
281322 - name : Fail job if any plan failed
282323 if : |
0 commit comments