Skip to content

Commit 7e9fa33

Browse files
Merge branch 'master' into feature/prism-changes-python
2 parents c874642 + 51d85f3 commit 7e9fa33

File tree

4 files changed

+309
-0
lines changed

4 files changed

+309
-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/octokit/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Octokit} from "@octokit/rest";
2+
import {createAppAuth} from "@octokit/auth-app"
3+
4+
export const getAccessToken = async () => {
5+
6+
const {GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY} = process.env
7+
8+
const octoKitInstance = new Octokit({
9+
authStrategy: createAppAuth,
10+
auth: {
11+
appId: GITHUB_APP_ID,
12+
privateKey: GITHUB_APP_PRIVATE_KEY
13+
}
14+
});
15+
16+
const {data: installations} = await octoKitInstance.rest.apps.listInstallations()
17+
18+
console.log("installations -----", installations);
19+
20+
21+
if(!installations.length) {
22+
throw new Error("No Installations found for this github app")
23+
}
24+
25+
const installationId = installations[0].id;
26+
27+
const installationAccessToken = await octoKitInstance.rest.apps.createInstallationAccessToken({installation_id: installationId})
28+
29+
return installationAccessToken.data.token
30+
}

.github/octokit/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "xero-octokit",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@octokit/auth-app": "^7.1.1",
14+
"@octokit/rest": "^21.0.2"
15+
}
16+
}

.github/workflows/publish.yml

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
name: Publish & Release SDK
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
cab_id:
6+
description: "CAB id for the change/release"
7+
required: true
8+
type: string
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
environment: prod
14+
outputs:
15+
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
16+
permissions:
17+
contents: write
18+
pull-requests: write
19+
steps:
20+
- name: Checkout xero-python repo
21+
uses: actions/checkout@v4
22+
with:
23+
repository: XeroAPI/xero-python
24+
path: xero-python
25+
26+
- name: Set up Python environment
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: '3.8'
30+
cache: 'pip'
31+
32+
- name: Install dependencies
33+
run: |
34+
python -m venv venv
35+
source venv/bin/activate
36+
pip install --upgrade pip
37+
sudo pip install twine
38+
working-directory: xero-python
39+
40+
- name: Fetch Latest release number
41+
id: get_latest_release_number
42+
run: |
43+
latest_version=$(gh release view --json tagName --jq '.tagName')
44+
echo "Latest release version is - $latest_version"
45+
echo "::set-output name=release_tag::$latest_version"
46+
working-directory: xero-python
47+
env:
48+
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
49+
50+
- name: Build Package
51+
run: python setup.py sdist
52+
working-directory: xero-python
53+
54+
- name: Publish to PyPi
55+
env:
56+
TWINE_USERNAME: __token__
57+
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
58+
run: twine upload dist/*
59+
working-directory: xero-python
60+
61+
notify-slack-on-success:
62+
runs-on: ubuntu-latest
63+
needs: publish
64+
if: success()
65+
permissions:
66+
contents: read
67+
steps:
68+
- name: Checkout xero-pythonrepo
69+
uses: actions/checkout@v4
70+
with:
71+
repository: XeroAPI/xero-python
72+
path: xero-python
73+
74+
- name: Send slack notification on success
75+
uses: ./xero-python/.github/actions/notify-slack
76+
with:
77+
heading_text: "Publish job has succeeded !"
78+
alert_type: "thumbsup"
79+
job_status: "Success"
80+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
81+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
82+
button_type: "primary"
83+
package_version: ${{needs.publish.outputs.release_number}}
84+
repo_link: ${{github.server_url}}/${{github.repository}}
85+
86+
notify-slack-on-failure:
87+
runs-on: ubuntu-latest
88+
needs: publish
89+
if: failure()
90+
permissions:
91+
contents: read
92+
steps:
93+
- name: Checkout xero-python repo
94+
uses: actions/checkout@v4
95+
with:
96+
repository: XeroAPI/xero-python
97+
path: xero-python
98+
99+
- name: Send slack notification on failure
100+
uses: ./xero-python/.github/actions/notify-slack
101+
with:
102+
heading_text: "Publish job has failed !"
103+
alert_type: "alert"
104+
job_status: "Failed"
105+
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
106+
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
107+
button_type: "danger"
108+
package_version: ${{needs.publish.outputs.release_number}}
109+
repo_link: ${{github.server_url}}/${{github.repository}}
110+
111+
notify-codegen-repo:
112+
needs: publish
113+
if: always()
114+
runs-on: ubuntu-latest
115+
permissions:
116+
contents: write
117+
pull-requests: write
118+
119+
steps:
120+
- name: Checkout
121+
uses: actions/checkout@v4
122+
with:
123+
repository: XeroAPI/xero-python
124+
path: xero-python
125+
126+
- name: Install octokit dependencies
127+
run: npm i
128+
working-directory: xero-python/.github/octokit
129+
130+
- name: Get github app access token
131+
id: get_access_token
132+
env:
133+
GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
134+
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
135+
uses: actions/github-script@v7
136+
with:
137+
result-encoding: string
138+
script: |
139+
const { getAccessToken } = await import('${{ github.workspace }}/xero-python/.github/octokit/index.js')
140+
const token = await getAccessToken()
141+
return token
142+
143+
- name: Notify codegen repo
144+
run: |
145+
curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
146+
-H "Accept: application/vnd.github.v3+json" \
147+
-H "Content-Type: application/json" \
148+
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
149+
-d '{
150+
"ref": "master",
151+
"inputs": {
152+
"commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
153+
"status": "${{needs.publish.result}}",
154+
"deployer": "xero-codegen-bot",
155+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
156+
"environment": "prod",
157+
"sdk_type": "python",
158+
"cab_key": "${{ github.event.inputs.cab_id }}"
159+
}
160+
}'

0 commit comments

Comments
 (0)