@@ -174,83 +174,87 @@ jobs:
174174 if-no-files-found : error
175175
176176 notify :
177- name : " Notify via Power Automate Webhook"
177+ name : " Notify via Teams Webhook"
178178 runs-on : ubuntu-latest
179179 needs :
180180 - drift
181181 - acceptance
182182 if : ${{ always() }}
183183 steps :
184- - name : Download all drift artifacts
185- uses : actions/download-artifact@v4
186- with :
187- path : drift-artifacts
188-
189184 - name : Download all artifacts
190185 uses : actions/download-artifact@v4
191186 with :
192187 path : artifacts
193188
194- - name : Build summary payload
195- id : build_payload
189+ - name : Build and send Teams notification
190+ env :
191+ TEAMS_WEBHOOK_URL : ${{ secrets.TEAMS_WEBHOOK_URL }}
192+ GITHUB_URL : ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
193+ WORKFLOW_NAME : ${{ github.workflow }}
194+ BRANCH_NAME : ${{ github.ref_name }}
196195 run : |
197- echo "PWD: $(pwd)"
198- ls -R artifacts
199-
200- drift_summary="{"
201- acc_summary="{"
202- first=true
203-
204- # Loop through drift artifacts
196+ # Build drift summary
197+ drift_text=""
205198 for file in artifacts/drift-results-*/result-drift-*.json; do
206199 version=$(jq -r .version < "$file")
207200 exitcode=$(jq -r .exitcode < "$file")
208- status="unknown"
209201 if [ "$exitcode" -eq 0 ]; then
210- status="no_drift "
202+ drift_text+="✅ TF $version: No drift\n "
211203 elif [ "$exitcode" -eq 2 ]; then
212- status="drift_detected "
213- elif [ "$exitcode" -eq 1 ]; then
214- status="error "
204+ drift_text+="⚠️ TF $version: Drift detected\n "
205+ else
206+ drift_text+="❌ TF $version: Error\n "
215207 fi
216-
217- if [ "$first" = false ]; then
218- drift_summary+=", "
219- fi
220- drift_summary+="\"${version}\": \"${status}\""
221- first=false
222208 done
223- drift_summary+="}"
224209
225- first=true
226- # Loop through acceptance artifacts
210+ # Build acceptance summary
211+ acc_text=""
212+ all_passed=true
227213 for file in artifacts/acceptance-results-*/result-acceptance-*.json; do
228214 version=$(jq -r .version < "$file")
229215 result=$(jq -r .result < "$file")
230-
231- if [ "$first" = false ]; then
232- acc_summary+=", "
216+ if [ "$result" = "success" ]; then
217+ acc_text+="✅ TF $version: Passed\n"
218+ else
219+ acc_text+="❌ TF $version: Failed\n"
220+ all_passed=false
233221 fi
234- acc_summary+="\"${version}\": \"${result}\""
235- first=false
236222 done
237- acc_summary+="}"
238223
239- echo "payload="$(jq -n \
240- --arg wf "${{ github.workflow }}" \
241- --arg branch "${{ github.ref_name }}" \
242- --arg runid "${{ github.run_id }}" \
243- --arg url "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
244- --argjson tested_versions '["0.15.5","0.14.11","1.1.2","1.5.3"]' \
245- --argjson drift_summary "$drift_summary" \
246- --argjson acceptance_summary "$acc_summary" \
247- '{workflow: $wf, branch: $branch, run_id: $runid, github_url: $url, tested_versions: $tested_versions, drift_summary: $drift_summary, acceptance_summary: $acceptance_summary }') \
248- >> $GITHUB_OUTPUT
249- - name : Trigger Power Automate Flow
250- uses : fjogeleit/http-request-action@v1.16.3
251- with :
252- url : ${{ secrets.POWER_AUTOMATE_HOOK_URL }}
253- method : ' POST'
254- contentType : ' application/json'
255- data : |
256- ${{ steps.build_payload.outputs.payload }}
224+ # Set title color based on results
225+ if [ "$all_passed" = true ]; then
226+ theme_color="00FF00"
227+ title="✅ Nightly Tests Passed"
228+ else
229+ theme_color="FF0000"
230+ title="❌ Nightly Tests Failed"
231+ fi
232+
233+ # Send to Teams
234+ curl -H "Content-Type: application/json" -d "{
235+ \"@type\": \"MessageCard\",
236+ \"@context\": \"http://schema.org/extensions\",
237+ \"themeColor\": \"${theme_color}\",
238+ \"summary\": \"${title}\",
239+ \"sections\": [{
240+ \"activityTitle\": \"${title}\",
241+ \"facts\": [
242+ { \"name\": \"Workflow\", \"value\": \"${WORKFLOW_NAME}\" },
243+ { \"name\": \"Branch\", \"value\": \"${BRANCH_NAME}\" }
244+ ],
245+ \"markdown\": true
246+ },
247+ {
248+ \"activityTitle\": \"Drift Detection\",
249+ \"text\": \"${drift_text}\"
250+ },
251+ {
252+ \"activityTitle\": \"Acceptance Tests\",
253+ \"text\": \"${acc_text}\"
254+ }],
255+ \"potentialAction\": [{
256+ \"@type\": \"OpenUri\",
257+ \"name\": \"View in GitHub\",
258+ \"targets\": [{ \"os\": \"default\", \"uri\": \"${GITHUB_URL}\" }]
259+ }]
260+ }" "${TEAMS_WEBHOOK_URL}"
0 commit comments