From 92b430da6387c98ea0503d9020190459ed3f7790 Mon Sep 17 00:00:00 2001 From: mistermalm Date: Wed, 30 Oct 2024 09:44:21 +0100 Subject: [PATCH 1/4] build: wip --- .github/workflows/smoketest-webhook.yml | 63 +++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/smoketest-webhook.yml diff --git a/.github/workflows/smoketest-webhook.yml b/.github/workflows/smoketest-webhook.yml new file mode 100644 index 000000000..4637d1d76 --- /dev/null +++ b/.github/workflows/smoketest-webhook.yml @@ -0,0 +1,63 @@ +name: Smoke test webhook + +on: + push: + branches: + - build/smoketest-webhook + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Run your build or tests + run: | + echo "Running build/test..." + # Replace this with your actual build/test command + exit 1 # Simulate failure + + - name: Notify Teams on failure + if: failure() + env: + TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }} + REPO_NAME: ${{ github.repository }} + BRANCH_NAME: ${{ github.ref }} + COMMIT_SHA: ${{ github.sha }} + RUN_URL: '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}' + run: | + curl -H 'Content-Type: application/json' -d '{ + "type": "message", + "attachments": [ + { + "contentType": "application/vnd.microsoft.card.hero", + "content": { + "title": "Build Failure Notification", + "text": "The build has failed. Please check the details.", + "facts": [ + { + "name": "Repository", + "value": "'"${REPO_NAME}"'" + }, + { + "name": "Branch", + "value": "'"${BRANCH_NAME}"'" + }, + { + "name": "Commit", + "value": "'"${COMMIT_SHA}"'" + } + ], + "buttons": [ + { + "type": "openUrl", + "title": "View Logs", + "value": "'"${RUN_URL}"'" + } + ] + } + } + ] + }' "$TEAMS_WEBHOOK_URL" From a2111b67677cc04aab94112baff8761aef2a9ac1 Mon Sep 17 00:00:00 2001 From: mistermalm Date: Wed, 30 Oct 2024 11:23:45 +0100 Subject: [PATCH 2/4] fix: content now visible in post --- .github/workflows/smoketest-webhook.yml | 41 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/.github/workflows/smoketest-webhook.yml b/.github/workflows/smoketest-webhook.yml index 4637d1d76..6a7d03168 100644 --- a/.github/workflows/smoketest-webhook.yml +++ b/.github/workflows/smoketest-webhook.yml @@ -32,29 +32,40 @@ jobs: "type": "message", "attachments": [ { - "contentType": "application/vnd.microsoft.card.hero", + "contentType": "application/vnd.microsoft.card.adaptive", "content": { - "title": "Build Failure Notification", - "text": "The build has failed. Please check the details.", - "facts": [ + "type": "AdaptiveCard", + "version": "1.0", + "body": [ { - "name": "Repository", - "value": "'"${REPO_NAME}"'" + "type": "TextBlock", + "size": "Medium", + "weight": "Bolder", + "text": "Build Failure Notification" }, { - "name": "Branch", - "value": "'"${BRANCH_NAME}"'" - }, - { - "name": "Commit", - "value": "'"${COMMIT_SHA}"'" + "type": "FactSet", + "facts": [ + { + "title": "Repository", + "value": "'"${REPO_NAME}"'" + }, + { + "title": "Branch", + "value": "'"${BRANCH_NAME}"'" + }, + { + "title": "Commit", + "value": "'"${COMMIT_SHA}"'" + } + ] } ], - "buttons": [ + "actions": [ { - "type": "openUrl", + "type": "Action.OpenUrl", "title": "View Logs", - "value": "'"${RUN_URL}"'" + "url": "'"${RUN_URL}"'" } ] } From 50c4b6150e8d52d003bdf8ef26a8f47c4dfeb7d6 Mon Sep 17 00:00:00 2001 From: mistermalm Date: Thu, 31 Oct 2024 16:30:39 +0100 Subject: [PATCH 3/4] chore: updated button text --- .github/workflows/smoketest-webhook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/smoketest-webhook.yml b/.github/workflows/smoketest-webhook.yml index 6a7d03168..7e03f005a 100644 --- a/.github/workflows/smoketest-webhook.yml +++ b/.github/workflows/smoketest-webhook.yml @@ -64,7 +64,7 @@ jobs: "actions": [ { "type": "Action.OpenUrl", - "title": "View Logs", + "title": "View failed jobs", "url": "'"${RUN_URL}"'" } ] From 62fd070d70a2e2a37cb378b3073a737641283a21 Mon Sep 17 00:00:00 2001 From: mistermalm Date: Fri, 1 Nov 2024 11:21:13 +0100 Subject: [PATCH 4/4] ci: webbhook to post failure in teams channel --- .../{smoketest-all.yml => smoke-test-all.yml} | 3 +++ ...bhook.yml => smoke-test-failure-webhook.yml} | 17 +++-------------- 2 files changed, 6 insertions(+), 14 deletions(-) rename .github/workflows/{smoketest-all.yml => smoke-test-all.yml} (98%) rename .github/workflows/{smoketest-webhook.yml => smoke-test-failure-webhook.yml} (82%) diff --git a/.github/workflows/smoketest-all.yml b/.github/workflows/smoke-test-all.yml similarity index 98% rename from .github/workflows/smoketest-all.yml rename to .github/workflows/smoke-test-all.yml index fdf87296e..3ff350718 100644 --- a/.github/workflows/smoketest-all.yml +++ b/.github/workflows/smoke-test-all.yml @@ -213,3 +213,6 @@ jobs: - name: Check results run: | echo "All previous jobs have completed successfully!" + - name: Notify in Teams on failure + if: failure() + uses: ./.github/workflows/smoke-test-webhook.yml diff --git a/.github/workflows/smoketest-webhook.yml b/.github/workflows/smoke-test-failure-webhook.yml similarity index 82% rename from .github/workflows/smoketest-webhook.yml rename to .github/workflows/smoke-test-failure-webhook.yml index 7e03f005a..bc2219cef 100644 --- a/.github/workflows/smoketest-webhook.yml +++ b/.github/workflows/smoke-test-failure-webhook.yml @@ -1,4 +1,4 @@ -name: Smoke test webhook +name: 'ci: smoke test failure webhook' on: push: @@ -8,19 +8,8 @@ on: jobs: build: runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Run your build or tests - run: | - echo "Running build/test..." - # Replace this with your actual build/test command - exit 1 # Simulate failure - - - name: Notify Teams on failure - if: failure() + - name: Post failure in Teams channel env: TEAMS_WEBHOOK_URL: ${{ secrets.TEAMS_WEBHOOK_URL }} REPO_NAME: ${{ github.repository }} @@ -64,7 +53,7 @@ jobs: "actions": [ { "type": "Action.OpenUrl", - "title": "View failed jobs", + "title": "View failed run", "url": "'"${RUN_URL}"'" } ]