Skip to content

Commit 3cb9ad7

Browse files
ci: Added slack alert code
ci: Added slack alert code
1 parent 7a8f410 commit 3cb9ad7

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
lines changed

Diff for: .github/actions/notify-slack/action.yml

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: slack-alert-action
2+
description: "Action to send slack payload to public-sdk-events channel"
3+
4+
inputs:
5+
heading_text:
6+
required: true
7+
description: "Heading of the slack payload"
8+
alert_type:
9+
required: true
10+
description: "type of the slack alert"
11+
job_status:
12+
required: true
13+
description: "status of the job"
14+
XERO_SLACK_WEBHOOK_URL:
15+
required: true
16+
description: "webhook url for channel - public-sdk-events"
17+
job_url:
18+
required: true
19+
description: "job run id link"
20+
button_type:
21+
required: true
22+
description: "color for the check logs button"
23+
package_version:
24+
required: true
25+
description: "released package version"
26+
repo_link:
27+
required: true
28+
description: "link of the repo"
29+
30+
31+
runs:
32+
using: "composite"
33+
34+
steps:
35+
36+
- name: Send slack notification
37+
id: slack
38+
uses: slackapi/[email protected]
39+
env:
40+
SLACK_WEBHOOK_URL: ${{inputs.XERO_SLACK_WEBHOOK_URL}}
41+
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
42+
with:
43+
payload: |
44+
{
45+
"blocks": [
46+
{
47+
"type": "rich_text",
48+
"elements": [
49+
{
50+
"type": "rich_text_section",
51+
"elements": [
52+
{
53+
"type": "text",
54+
"text": "${{inputs.heading_text}} ",
55+
"style": {
56+
"bold": true
57+
}
58+
},
59+
{
60+
"type": "emoji",
61+
"name": "${{inputs.alert_type}}"
62+
}
63+
]
64+
}
65+
]
66+
},
67+
{
68+
"type": "divider"
69+
},
70+
{
71+
"type": "section",
72+
"fields": [
73+
{
74+
"type": "mrkdwn",
75+
"text": "*Repository:* \n ${{inputs.repo_link}}"
76+
},
77+
{
78+
"type": "mrkdwn",
79+
"text": "*Status:*\n ${{inputs.job_status}}"
80+
},
81+
{
82+
"type": "mrkdwn",
83+
"text": "*Package Version:*\n ${{inputs.package_version}}"
84+
}
85+
]
86+
},
87+
{
88+
"type": "actions",
89+
"elements": [
90+
{
91+
"type": "button",
92+
"text": {
93+
"type": "plain_text",
94+
"text": "Check the logs",
95+
"emoji": true
96+
},
97+
"style": "${{inputs.button_type}}",
98+
"url": "${{inputs.job_url}}"
99+
}
100+
]
101+
}
102+
]
103+
}

Diff for: .github/workflows/publish.yml

+61
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
jobs:
77
publish:
88
runs-on: ubuntu-latest
9+
outputs:
10+
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
11+
permissions:
12+
contents: write
13+
pull-requests: write
914
steps:
1015
- name: Checkout xero-python repo
1116
uses: actions/checkout@v4
@@ -27,6 +32,16 @@ jobs:
2732
sudo pip install twine
2833
working-directory: xero-python
2934

35+
- name: Fetch Latest release number
36+
id: get_latest_release_number
37+
run: |
38+
latest_version=$(gh release view --json tagName --jq '.tagName')
39+
echo "Latest release version is - $latest_version"
40+
echo "::set-output name=release_tag::$latest_version"
41+
working-directory: xero-python
42+
env:
43+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
44+
3045
- name: Build Package
3146
run: python setup.py sdist
3247
working-directory: xero-python
@@ -37,3 +52,49 @@ jobs:
3752
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
3853
run: twine upload dist/*
3954
working-directory: xero-python
55+
56+
notify-slack-on-success:
57+
runs-on: ubuntu-latest
58+
needs: publish
59+
if: success()
60+
steps:
61+
- name: Checkout xero-pythonrepo
62+
uses: actions/checkout@v4
63+
with:
64+
repository: XeroAPI/xero-python
65+
path: xero-python
66+
67+
- name: Send slack notification on success
68+
uses: ./xero-python/.github/actions/notify-slack
69+
with:
70+
heading_text: "Publish job has succeeded !"
71+
alert_type: "thumbsup"
72+
job_status: "Success"
73+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
74+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
75+
button_type: "primary"
76+
package_version: ${{needs.publish.outputs.release_number}}
77+
repo_link: ${{github.server_url}}/${{github.repository}}
78+
79+
notify-slack-on-failure:
80+
runs-on: ubuntu-latest
81+
needs: publish
82+
if: failure()
83+
steps:
84+
- name: Checkout xero-python repo
85+
uses: actions/checkout@v4
86+
with:
87+
repository: XeroAPI/xero-python
88+
path: xero-python
89+
90+
- name: Send slack notification on failure
91+
uses: ./xero-python/.github/actions/notify-slack
92+
with:
93+
heading_text: "Publish job has failed !"
94+
alert_type: "alert"
95+
job_status: "Failed"
96+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
97+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
98+
button_type: "danger"
99+
package_version: ${{needs.publish.outputs.release_number}}
100+
repo_link: ${{github.server_url}}/${{github.repository}}

0 commit comments

Comments
 (0)