Skip to content

Commit

Permalink
feat: add email alerts functionality in repo health job
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Feb 27, 2024
1 parent 303d605 commit 1e94d7a
Showing 1 changed file with 61 additions and 6 deletions.
67 changes: 61 additions & 6 deletions .github/workflows/repo-health-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Repo Health Checks
on:
workflow_call:
secrets:
REPO_HEALTH_BOT_TOKEN:
REPO_HEALTH_BOT_TOKEN:
description: "Github token with read access to all repos and write access to the target repo"
required: true
REPO_HEALTH_BOT_EMAIL:
Expand All @@ -15,6 +15,15 @@ on:
READTHEDOCS_API_KEY:
description: "API Key for READ THE DOCS Access"
required: true
EMAIL_ADDRESS_FOR_ALERTS:
description: "Email Address for the alerts"
required: false
EDX_SMTP_USERNAME:
description: "SMTP Username for sending emails"
required: false
EDX_SMTP_PASSWORD:
description: "SMTP Password for sending emails"
required: false

inputs:
DASHBOARD_NAME:
Expand Down Expand Up @@ -53,6 +62,26 @@ on:
description: "Space seperated list of repos to be ignored i.e. 'repo1 repo2 . . .' "
type: string
default: "clamps-ghsa-c4rq-qwgr-pj5h"
CALLER_REPOSITORY:
description: "Repository that called this workflow"
type: string
default: ""
CALLER_WORKFLOW:
description: "Workflow that called this workflow"
type: string
default: ""
CALLER_RUN_ID:
description: "Run ID of the caller repository"
type: string
default: ""
ENABLE_EMAIL_ALERTS:
description: "Set this to true to enable email alerts."
type: boolean
default: false
ENABLE_EMAIL_ALERTS_ON_SUCCESS:
description: "By default, email alerts are sent on failure. Set this to true to enable email alerts on success as well."
type: boolean
default: false

jobs:
repo_health_check:
Expand All @@ -70,14 +99,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Clone edx-repo-health repo
uses: actions/checkout@v4
with:
repository: openedx/edx-repo-health
path: edx-repo-health
ref: ${{ inputs.EDX_REPO_HEALTH_BRANCH }}

- name: Install pip & pip-tools
run: |
python3 -m pip install -r edx-repo-health/requirements/pip.txt
Expand All @@ -89,14 +118,14 @@ jobs:
repository: openedx/testeng-ci
path: testeng-ci
ref: "master"

- name: Clone repo-tools repo
uses: actions/checkout@v4
with:
repository: openedx/repo-tools
path: repo_tools
ref: master

- name: Clone repo-health-data repo
uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -137,10 +166,36 @@ jobs:
if: ${{ inputs.DASHBOARD_NAME == 'repo_health' }}
run: |
bash edx-repo-health/scripts/repo-health-artifact.sh
- name: Upload sqlite db as artifact
if: ${{ inputs.DASHBOARD_NAME == 'repo_health' }}
uses: actions/upload-artifact@v4
with:
name: sqlite db artifact
path: dashboards/dashboard.sqlite3

- name: Send email on failure
uses: dawidd6/action-send-mail@v3
if: ${{ failure() && inputs.ENABLE_EMAIL_ALERTS }}
with:
server_address: email-smtp.us-east-1.amazonaws.com
server_port: 465
username: ${{secrets.EDX_SMTP_USERNAME}}
password: ${{secrets.EDX_SMTP_PASSWORD}}
subject: Dependencies health job workflow failed in ${{inputs.CALLER_REPOSITORY}}
to: ${{ secrets.EMAIL_ADDRESS_FOR_ALERTS }}
from: github-actions <[email protected]>
body: Dependencies health job workflow in ${{ inputs.CALLER_REPOSITORY }} failed! For details, see "github.com/${{ inputs.CALLER_REPOSITORY }}/actions/runs/${{ inputs.CALLER_RUN_ID }}"

- name: Send email on success
uses: dawidd6/action-send-mail@v3
if: ${{ success() && inputs.ENABLE_EMAIL_ALERTS && inputs.ENABLE_EMAIL_ALERTS_ON_SUCCESS }}
with:
server_address: email-smtp.us-east-1.amazonaws.com
server_port: 465
username: ${{secrets.EDX_SMTP_USERNAME}}
password: ${{secrets.EDX_SMTP_PASSWORD}}
subject: Dependencies health job workflow succeeded in ${{inputs.CALLER_REPOSITORY}}
to: ${{ secrets.EMAIL_ADDRESS_FOR_ALERTS }}
from: github-actions <[email protected]>
body: Dependencies health job workflow in ${{ inputs.CALLER_REPOSITORY }} succeeded! For details, see "github.com/${{ inputs.CALLER_REPOSITORY }}/actions/runs/${{ inputs.CALLER_RUN_ID }}"

0 comments on commit 1e94d7a

Please sign in to comment.