Skip to content

Commit c9c2cfd

Browse files
PETOSS 733 | Automation | SDK pipeline | Enable the SDK publish pipeline (#185)
PETOSS 733 | Automation | SDK pipeline | Enable the SDK publish pipeline (#185)
1 parent e6002f8 commit c9c2cfd

File tree

2 files changed

+207
-0
lines changed

2 files changed

+207
-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: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
name: Publish
2+
on:
3+
release:
4+
types: [published]
5+
6+
jobs:
7+
publish:
8+
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
14+
steps:
15+
- name: Checkout xero-python repo
16+
uses: actions/checkout@v4
17+
with:
18+
repository: XeroAPI/xero-python
19+
path: xero-python
20+
21+
- name: Set up Python environment
22+
uses: actions/setup-python@v5
23+
with:
24+
python-version: '3.8'
25+
cache: 'pip'
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m venv venv
30+
source venv/bin/activate
31+
pip install --upgrade pip
32+
sudo pip install twine
33+
working-directory: xero-python
34+
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+
45+
- name: Build Package
46+
run: python setup.py sdist
47+
working-directory: xero-python
48+
49+
- name: Publish to PyPi
50+
env:
51+
TWINE_USERNAME: __token__
52+
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
53+
run: twine upload dist/*
54+
working-directory: xero-python
55+
56+
notify-slack-on-success:
57+
runs-on: ubuntu-latest
58+
needs: publish
59+
if: success()
60+
permissions:
61+
contents: read
62+
steps:
63+
- name: Checkout xero-pythonrepo
64+
uses: actions/checkout@v4
65+
with:
66+
repository: XeroAPI/xero-python
67+
path: xero-python
68+
69+
- name: Send slack notification on success
70+
uses: ./xero-python/.github/actions/notify-slack
71+
with:
72+
heading_text: "Publish job has succeeded !"
73+
alert_type: "thumbsup"
74+
job_status: "Success"
75+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
76+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
77+
button_type: "primary"
78+
package_version: ${{needs.publish.outputs.release_number}}
79+
repo_link: ${{github.server_url}}/${{github.repository}}
80+
81+
notify-slack-on-failure:
82+
runs-on: ubuntu-latest
83+
needs: publish
84+
if: failure()
85+
permissions:
86+
contents: read
87+
steps:
88+
- name: Checkout xero-python repo
89+
uses: actions/checkout@v4
90+
with:
91+
repository: XeroAPI/xero-python
92+
path: xero-python
93+
94+
- name: Send slack notification on failure
95+
uses: ./xero-python/.github/actions/notify-slack
96+
with:
97+
heading_text: "Publish job has failed !"
98+
alert_type: "alert"
99+
job_status: "Failed"
100+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
101+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
102+
button_type: "danger"
103+
package_version: ${{needs.publish.outputs.release_number}}
104+
repo_link: ${{github.server_url}}/${{github.repository}}

0 commit comments

Comments
 (0)