Skip to content

Commit eff9ecd

Browse files
ci: Added the slack alert pipeline code
ci: Added the slack alert pipeline code
1 parent f7ec805 commit eff9ecd

File tree

2 files changed

+164
-0
lines changed

2 files changed

+164
-0
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: 61 additions & 0 deletions
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-node repo
1116
uses: actions/checkout@v4
@@ -29,8 +34,64 @@ jobs:
2934
run: npm run build
3035
working-directory: xero-node
3136

37+
- name: Fetch Latest release number
38+
id: get_latest_release_number
39+
run: |
40+
latest_version=$(gh release view --json tagName --jq '.tagName')
41+
echo "Latest release version is - $latest_version"
42+
echo "::set-output name=release_tag::$latest_version"
43+
working-directory: xero-node
44+
env:
45+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
46+
3247
- name: Publish to npm
3348
env:
3449
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3550
run: npm publish
3651
working-directory: xero-node
52+
53+
notify-slack-on-success:
54+
runs-on: ubuntu-latest
55+
needs: publish
56+
if: success()
57+
steps:
58+
- name: Checkout xero-node repo
59+
uses: actions/checkout@v4
60+
with:
61+
repository: XeroAPI/xero-node
62+
path: xero-node
63+
64+
- name: Send slack notification on success
65+
uses: ./xero-node/.github/actions/notify-slack
66+
with:
67+
heading_text: "Publish job has succeeded !"
68+
alert_type: "thumbsup"
69+
job_status: "Success"
70+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
71+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
72+
button_type: "primary"
73+
package_version: ${{needs.publish.outputs.release_number}}
74+
repo_link: ${{github.server_url}}/${{github.repository}}
75+
76+
notify-slack-on-failure:
77+
runs-on: ubuntu-latest
78+
needs: publish
79+
if: failure()
80+
steps:
81+
- name: Checkout xero-node repo
82+
uses: actions/checkout@v4
83+
with:
84+
repository: XeroAPI/xero-node
85+
path: xero-node
86+
87+
- name: Send slack notification on failure
88+
uses: ./xero-node/.github/actions/notify-slack
89+
with:
90+
heading_text: "Publish job has failed !"
91+
alert_type: "alert"
92+
job_status: "Failed"
93+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
94+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
95+
button_type: "danger"
96+
package_version: ${{needs.publish.outputs.release_number}}
97+
repo_link: ${{github.server_url}}/${{github.repository}}

0 commit comments

Comments
 (0)