Skip to content

Commit d5b537f

Browse files
ci: added slack alert pipeline code
ci: added slack alert pipeline code
1 parent b462d17 commit d5b537f

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/[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+
}

.github/workflows/publish.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,28 @@ 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-ruby repo
1116
uses: actions/checkout@v4
1217
with:
1318
repository: XeroAPI/xero-ruby
1419
path: xero-ruby
1520

21+
- name: Fetch Latest release number
22+
id: get_latest_release_number
23+
run: |
24+
latest_version=$(gh release view --json tagName --jq '.tagName')
25+
echo "Latest release version is - $latest_version"
26+
echo "::set-output name=release_tag::$latest_version"
27+
working-directory: xero-ruby
28+
env:
29+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
30+
1631
- name: Set up Ruby environment
1732
uses: ruby/setup-ruby@v1
1833
with:
@@ -32,3 +47,49 @@ jobs:
3247
echo "$gem_file"
3348
gem push "$gem_file"
3449
working-directory: xero-ruby
50+
51+
notify-slack-on-success:
52+
runs-on: ubuntu-latest
53+
needs: publish
54+
if: success()
55+
steps:
56+
- name: Checkout xero-ruby repo
57+
uses: actions/checkout@v4
58+
with:
59+
repository: XeroAPI/xero-ruby
60+
path: xero-ruby
61+
62+
- name: Send slack notification on success
63+
uses: ./xero-ruby/.github/actions/notify-slack
64+
with:
65+
heading_text: "Publish job has succeeded !"
66+
alert_type: "thumbsup"
67+
job_status: "Success"
68+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
69+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
70+
button_type: "primary"
71+
package_version: ${{needs.publish.outputs.release_number}}
72+
repo_link: ${{github.server_url}}/${{github.repository}}
73+
74+
notify-slack-on-failure:
75+
runs-on: ubuntu-latest
76+
needs: publish
77+
if: failure()
78+
steps:
79+
- name: Checkout xero-ruby repo
80+
uses: actions/checkout@v4
81+
with:
82+
repository: XeroAPI/xero-ruby
83+
path: xero-ruby
84+
85+
- name: Send slack notification on failure
86+
uses: ./xero-ruby/.github/actions/notify-slack
87+
with:
88+
heading_text: "Publish job has failed !"
89+
alert_type: "alert"
90+
job_status: "Failed"
91+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
92+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
93+
button_type: "danger"
94+
package_version: ${{needs.publish.outputs.release_number}}
95+
repo_link: ${{github.server_url}}/${{github.repository}}

0 commit comments

Comments
 (0)