From ec5194a23888e4398c8edee3d21d34d0f06dbd25 Mon Sep 17 00:00:00 2001 From: Salma Lalji Date: Fri, 1 May 2026 15:51:06 -0700 Subject: [PATCH 1/4] notification to slack --- .github/workflows/testsPython.yml | 56 ++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/.github/workflows/testsPython.yml b/.github/workflows/testsPython.yml index 452f71d..b78f142 100644 --- a/.github/workflows/testsPython.yml +++ b/.github/workflows/testsPython.yml @@ -72,8 +72,54 @@ jobs: steps: - name: Notify on test results run: | - if [ "${{ needs.python-unit-tests.result }}" == "success" ]; then - echo "success notifications go here" - else - echo "failure notifications go here" - fi + steps: + - name: Notify Slack on success + if: needs.python-unit-tests.result == 'success' + uses: slackapi/slack-github-action@v1.27.0 + with: + payload: | + { + "text": "Tests Passed!*", + "attachments": [ + { + "color": "#36A64F", + "fields": [ + { "title": "Repository", "value": "${{ github.repository }}", "short": true }, + { "title": "Branch", "value": "${{ github.ref_name }}", "short": true }, + { "title": "Python Version", "value": "${{ env.python-version }}", "short": true }, + { "title": "Triggered by", "value": "${{ github.actor }}", "short": true }, + { "title": "Commit", "value": "${{ github.sha }}", "short": false }, + { "title": "View Run", "value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "short": false } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + + - name: Notify Slack on failure + if: needs.python-unit-tests.result != 'success' + uses: slackapi/slack-github-action@v1.27.0 + with: + payload: | + { + "text": "Tests Failed!", + "attachments": [ + { + "color": "#FF0000", + "fields": [ + { "title": "Repository", "value": "${{ github.repository }}", "short": true }, + { "title": "Branch", "value": "${{ github.ref_name }}", "short": true }, + { "title": "Python Version", "value": "${{ env.python-version }}", "short": true }, + { "title": "Triggered by", "value": "${{ github.actor }}", "short": true }, + { "title": "Commit", "value": "${{ github.sha }}", "short": false }, + { "title": "View Run", "value": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "short": false } + ] + } + ] + } + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK + From b0f579354cac9b2f15acb7ad36f405c7e71d1c7c Mon Sep 17 00:00:00 2001 From: Salma Lalji Date: Fri, 1 May 2026 16:03:20 -0700 Subject: [PATCH 2/4] notify to slack channel --- .github/workflows/testsPython.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/testsPython.yml b/.github/workflows/testsPython.yml index b78f142..2f84430 100644 --- a/.github/workflows/testsPython.yml +++ b/.github/workflows/testsPython.yml @@ -79,7 +79,7 @@ jobs: with: payload: | { - "text": "Tests Passed!*", + "text": "Tests Passed", "attachments": [ { "color": "#36A64F", From d7d168b3c3cc1754f344cf084cc02367581f4efb Mon Sep 17 00:00:00 2001 From: Salma Lalji Date: Fri, 1 May 2026 22:04:58 -0700 Subject: [PATCH 3/4] fix config to slack --- .github/workflows/testsPython.yml | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/.github/workflows/testsPython.yml b/.github/workflows/testsPython.yml index 2f84430..17cf21d 100644 --- a/.github/workflows/testsPython.yml +++ b/.github/workflows/testsPython.yml @@ -13,10 +13,12 @@ # 1. Checkout repository code # 2. Set up Python environment using a custom action # 3. Run unit tests and report results +# 4. Send Slack notification on success or failure # # Notes: # - secrets are set in https://github.com/smarter-sh/smarter/settings/secrets/actions # - Integrates with Codecov for coverage reporting +# - SLACK_WEBHOOK_URL must be added to repo secrets ############################################################################### name: Python Unit Tests @@ -37,11 +39,8 @@ env: jobs: # Job #1: Run Python unit tests - # - # This job will run on an Ubuntu runner and execute the Python - # tests by using a custom action located in ./.github/actions/tests/python. python-unit-tests: - runs-on: ubuntu-latest # the runner (remote machine) will use Ubuntu OS + runs-on: ubuntu-latest steps: - name: Checkout code id: checkout @@ -63,23 +62,19 @@ jobs: codecov-token: "${{ secrets.CODECOV_TOKEN }}" # Job #2: Notifications (Mini-capstone assignment) - # This job will run after the Python unit tests and - # is scaffolded to facilitate sending notifications based - # on the test results. + # Sends a Slack notification on success or failure. notifications: needs: python-unit-tests runs-on: ubuntu-latest + if: always() # ← ensures this job runs even when tests fail steps: - - name: Notify on test results - run: | - steps: - name: Notify Slack on success if: needs.python-unit-tests.result == 'success' uses: slackapi/slack-github-action@v1.27.0 with: payload: | { - "text": "Tests Passed", + "text": "*Tests Passed!*", "attachments": [ { "color": "#36A64F", @@ -104,7 +99,7 @@ jobs: with: payload: | { - "text": "Tests Failed!", + "text": "*Tests Failed!*", "attachments": [ { "color": "#FF0000", @@ -122,4 +117,3 @@ jobs: env: SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK - From 89f48c300ca378f80b31bbd74f23f80bf4a9987b Mon Sep 17 00:00:00 2001 From: Salma Lalji Date: Fri, 1 May 2026 22:17:18 -0700 Subject: [PATCH 4/4] add notification to slack if success or failed --- .github/workflows/testsPython.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/testsPython.yml b/.github/workflows/testsPython.yml index 17cf21d..21d0285 100644 --- a/.github/workflows/testsPython.yml +++ b/.github/workflows/testsPython.yml @@ -13,12 +13,10 @@ # 1. Checkout repository code # 2. Set up Python environment using a custom action # 3. Run unit tests and report results -# 4. Send Slack notification on success or failure # # Notes: # - secrets are set in https://github.com/smarter-sh/smarter/settings/secrets/actions # - Integrates with Codecov for coverage reporting -# - SLACK_WEBHOOK_URL must be added to repo secrets ############################################################################### name: Python Unit Tests @@ -39,8 +37,11 @@ env: jobs: # Job #1: Run Python unit tests + # + # This job will run on an Ubuntu runner and execute the Python + # tests by using a custom action located in ./.github/actions/tests/python. python-unit-tests: - runs-on: ubuntu-latest + runs-on: ubuntu-latest # the runner (remote machine) will use Ubuntu OS steps: - name: Checkout code id: checkout @@ -62,7 +63,9 @@ jobs: codecov-token: "${{ secrets.CODECOV_TOKEN }}" # Job #2: Notifications (Mini-capstone assignment) - # Sends a Slack notification on success or failure. + # This job will run after the Python unit tests and + # is scaffolded to facilitate sending notifications based + # on the test results. notifications: needs: python-unit-tests runs-on: ubuntu-latest