Skip to content

Commit 13062f3

Browse files
author
sangeet-joy_xero
committed
ci: Added the slack alert code for python
1 parent cbb4403 commit 13062f3

File tree

2 files changed

+168
-1
lines changed

2 files changed

+168
-1
lines changed
Lines changed: 103 additions & 0 deletions
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/slack-github-action@v1.27.0
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+
}

.github/workflows/publish.yml

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ name: Publish
22
on:
33
release:
44
types: [published]
5+
pull_request:
6+
branches:
7+
- master
58

69
jobs:
710
publish:
811
runs-on: ubuntu-latest
12+
outputs:
13+
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
14+
permissions:
15+
contents: write
16+
pull-requests: write
917
steps:
1018
- name: Checkout xero-python repo
1119
uses: actions/checkout@v4
@@ -27,13 +35,69 @@ jobs:
2735
sudo pip install twine
2836
working-directory: xero-python
2937

38+
- name: Fetch Latest release number
39+
id: get_latest_release_number
40+
run: |
41+
latest_version=$(gh release view --json tagName --jq '.tagName')
42+
echo "Latest release version is - $latest_version"
43+
echo "::set-output name=release_tag::$latest_version"
44+
working-directory: xero-python
45+
env:
46+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
47+
3048
- name: Build Package
3149
run: python setup.py sdist
3250
working-directory: xero-python
3351

3452
- name: Publish to PyPi
3553
env:
3654
TWINE_USERNAME: __token__
37-
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
55+
# TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
3856
run: twine upload --repository-url https://test.pypi.org/legacy/ dist/*
3957
working-directory: xero-python
58+
59+
notify-slack-on-success:
60+
runs-on: ubuntu-latest
61+
needs: publish
62+
if: success()
63+
steps:
64+
- name: Checkout xero-node repo
65+
uses: actions/checkout@v4
66+
with:
67+
repository: XeroAPI/xero-node
68+
path: xero-node
69+
70+
- name: Send slack notification on success
71+
uses: ./xero-node/.github/actions/notify-slack
72+
with:
73+
heading_text: "Publish job has succeeded !"
74+
alert_type: "thumbsup"
75+
job_status: "Success"
76+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
77+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
78+
button_type: "primary"
79+
package_version: ${{needs.publish.outputs.release_number}}
80+
repo_link: ${{github.server_url}}/${{github.repository}}
81+
82+
notify-slack-on-failure:
83+
runs-on: ubuntu-latest
84+
needs: publish
85+
if: failure()
86+
steps:
87+
- name: Checkout xero-node repo
88+
uses: actions/checkout@v4
89+
with:
90+
repository: XeroAPI/xero-node
91+
path: xero-node
92+
93+
- name: Send slack notification on failure
94+
uses: ./xero-node/.github/actions/notify-slack
95+
with:
96+
heading_text: "Publish job has failed !"
97+
alert_type: "alert"
98+
job_status: "Failed"
99+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
100+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
101+
button_type: "danger"
102+
package_version: ${{needs.publish.outputs.release_number}}
103+
repo_link: ${{github.server_url}}/${{github.repository}}

0 commit comments

Comments
 (0)