Skip to content

Automating SDK generation process #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
553c0ab
Adds Deploy step
Sep 26, 2024
db2412c
adds a separate deploy step
Sep 26, 2024
08fa57b
install twine
Sep 26, 2024
61d9370
update to correct alpha version
Sep 26, 2024
8327412
removed some unused steps
Sep 26, 2024
e119bd2
final commit with test instance
Sep 26, 2024
e718f32
fixed review comments - corrected name from deploy to publish
Sep 26, 2024
49e5f12
Merge pull request #157 from XeroAPI/PETOSS-534-Publish-Python-SDK-af…
vigneshk-tw Sep 26, 2024
b7c4c85
updated packages, added audit ci step, added prism script
Oct 8, 2024
a7604ec
ci: fix build ci step
Oct 8, 2024
a2bdc74
added alpha version for testing
Oct 8, 2024
1cfdd02
added vulnerable package to text test the pipeline
Oct 8, 2024
15dc01e
refactored the audit steps
Oct 8, 2024
a05d150
added sudo to pip audit
Oct 8, 2024
2810f3f
Added read me file
Oct 8, 2024
f58785a
renamed a step
Oct 8, 2024
2e46874
incorporated the review comments
Oct 8, 2024
23377eb
renamed the step
Oct 8, 2024
9bc7862
increase alpha version for testing
vigneshk-tw Oct 11, 2024
cbb4403
Merge pull request #158 from XeroAPI/PETOSS-517-python-vulnerabilitie…
vigneshk-tw Oct 11, 2024
cc72c3b
adds verbose
vigneshk-tw Oct 11, 2024
22e9cf2
verify publish with the new token
vigneshk-tw Oct 22, 2024
651e4e3
adds if case to publish either to pypi or testpypi
vigneshk-tw Oct 22, 2024
1de299a
update publish script
vigneshk-tw Oct 22, 2024
65a9aa2
deploy to pypi instead of test instance
vigneshk-tw Oct 22, 2024
8473d38
removed unwanted changes
vigneshk-tw Oct 22, 2024
7a1632e
removed the verbose flag
vigneshk-tw Oct 22, 2024
06e3fa5
Merge pull request #162 from XeroAPI/PETOSS-604-Replace-Test-instance…
vigneshk-tw Oct 22, 2024
26d6e2f
start and stop prism for running tests
vigneshk-tw Oct 22, 2024
d20a509
install prism
vigneshk-tw Oct 22, 2024
41fd22a
check if prism is installed properly
vigneshk-tw Oct 22, 2024
e3e7fce
corrected start script
vigneshk-tw Oct 22, 2024
b672e73
removed sudo
vigneshk-tw Oct 22, 2024
7834c27
adds nohup
vigneshk-tw Oct 22, 2024
ec413b6
adds disown
vigneshk-tw Oct 23, 2024
bea1f9d
adds continue-on-error
vigneshk-tw Oct 23, 2024
15f4f51
uncommented and adds sleep
vigneshk-tw Oct 23, 2024
234066d
commented source activation
vigneshk-tw Oct 23, 2024
0b9cc88
adds environment
vigneshk-tw Oct 23, 2024
0b05dd3
removed version for urllib3
vigneshk-tw Oct 23, 2024
20873cd
increase sleep timing
vigneshk-tw Oct 23, 2024
94a8f5f
commented echo statemenet
vigneshk-tw Oct 23, 2024
3797926
try adding sleep while starting prism
vigneshk-tw Oct 23, 2024
c0b657b
increase sleep timer
vigneshk-tw Oct 23, 2024
d6b63e2
try removing disown
vigneshk-tw Oct 23, 2024
217a7ef
clanup commit
vigneshk-tw Oct 23, 2024
b8eb6d8
final cleanup
vigneshk-tw Oct 23, 2024
7a8f410
Merge pull request #163 from XeroAPI/PETOSS-585-Enable-Test-Step-in-C…
vigneshk-tw Oct 23, 2024
3cb9ad7
ci: Added slack alert code
sangeet-joy-tw Oct 23, 2024
dcbf497
Merge branch 'master' into feature/sdk-automation
sangeet-joy-tw Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions .github/actions/notify-slack/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: slack-alert-action
description: "Action to send slack payload to public-sdk-events channel"

inputs:
heading_text:
required: true
description: "Heading of the slack payload"
alert_type:
required: true
description: "type of the slack alert"
job_status:
required: true
description: "status of the job"
XERO_SLACK_WEBHOOK_URL:
required: true
description: "webhook url for channel - public-sdk-events"
job_url:
required: true
description: "job run id link"
button_type:
required: true
description: "color for the check logs button"
package_version:
required: true
description: "released package version"
repo_link:
required: true
description: "link of the repo"


runs:
using: "composite"

steps:

- name: Send slack notification
id: slack
uses: slackapi/[email protected]
env:
SLACK_WEBHOOK_URL: ${{inputs.XERO_SLACK_WEBHOOK_URL}}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
with:
payload: |
{
"blocks": [
{
"type": "rich_text",
"elements": [
{
"type": "rich_text_section",
"elements": [
{
"type": "text",
"text": "${{inputs.heading_text}} ",
"style": {
"bold": true
}
},
{
"type": "emoji",
"name": "${{inputs.alert_type}}"
}
]
}
]
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Repository:* \n ${{inputs.repo_link}}"
},
{
"type": "mrkdwn",
"text": "*Status:*\n ${{inputs.job_status}}"
},
{
"type": "mrkdwn",
"text": "*Package Version:*\n ${{inputs.package_version}}"
}
]
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Check the logs",
"emoji": true
},
"style": "${{inputs.button_type}}",
"url": "${{inputs.job_url}}"
}
]
}
]
}
39 changes: 30 additions & 9 deletions .github/workflows/build-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

- name: Set up Python environment
uses: actions/setup-python@v5
with:
with:
python-version: '3.8'
cache: 'pip'

Expand All @@ -27,20 +27,41 @@ jobs:
pip install --upgrade pip
pip install black
sudo pip install flake8
sudo pip install pip-audit
pip install -r requirements.txt -r requirements/dev.txt
working-directory: xero-python


- name: Check vulnerable packages
run: pip-audit -r requirements.txt -r requirements/dev.txt
working-directory: xero-python

- name: Run Flake8
run: flake8 xero_python
working-directory: xero-python

- name: Build package
run: python setup.py sdist
working-directory: xero-python

# - name: Run Test
# run: |
# source venv/bin/activate
# pip install -r requirements/test.txt
# pytest -v
# working-directory: xero-python
- name: Set up Node environment
uses: actions/setup-node@v2
with:
node-version: 20

- name: Install Prism
run: npm install -g @stoplight/prism-cli

- name: Start PRISM Server
run: ./start-prism.sh & sleep 15
working-directory: xero-python/tests/utils

- name: Run Test
run: |
source venv/bin/activate
pytest -v
working-directory: xero-python

- name: Stop PRISM
if: success() || failure()
run: pkill -f prism
working-directory: xero-python
100 changes: 100 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: Publish
on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
outputs:
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout xero-python repo
uses: actions/checkout@v4
with:
repository: XeroAPI/xero-python
path: xero-python

- name: Set up Python environment
uses: actions/setup-python@v5
with:
python-version: '3.8'
cache: 'pip'

- name: Install dependencies
run: |
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
sudo pip install twine
working-directory: xero-python

- name: Fetch Latest release number
id: get_latest_release_number
run: |
latest_version=$(gh release view --json tagName --jq '.tagName')
echo "Latest release version is - $latest_version"
echo "::set-output name=release_tag::$latest_version"
working-directory: xero-python
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Build Package
run: python setup.py sdist
working-directory: xero-python

- name: Publish to PyPi
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
run: twine upload dist/*
working-directory: xero-python

notify-slack-on-success:
runs-on: ubuntu-latest
needs: publish
if: success()
steps:
- name: Checkout xero-pythonrepo
uses: actions/checkout@v4
with:
repository: XeroAPI/xero-python
path: xero-python

- name: Send slack notification on success
uses: ./xero-python/.github/actions/notify-slack
with:
heading_text: "Publish job has succeeded !"
alert_type: "thumbsup"
job_status: "Success"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "primary"
package_version: ${{needs.publish.outputs.release_number}}
repo_link: ${{github.server_url}}/${{github.repository}}

notify-slack-on-failure:
Comment on lines +57 to +79

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
runs-on: ubuntu-latest
needs: publish
if: failure()
steps:
- name: Checkout xero-python repo
uses: actions/checkout@v4
with:
repository: XeroAPI/xero-python
path: xero-python

- name: Send slack notification on failure
uses: ./xero-python/.github/actions/notify-slack
with:
heading_text: "Publish job has failed !"
alert_type: "alert"
job_status: "Failed"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "danger"
package_version: ${{needs.publish.outputs.release_number}}
repo_link: ${{github.server_url}}/${{github.repository}}
Comment on lines +80 to +100

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ The xero-python SDK makes it easy for developers to access Xero's APIs in their
- [Helper Methods](#helper-methods)
- [Usage Examples](#usage-examples)
- [SDK conventions](#sdk-conventions)
- [Running Test(s) in Local](#running-tests-in-local)
- [Participating in Xero’s developer community](#participating-in-xeros-developer-community)
- [Contributing](#contributing)

Expand Down Expand Up @@ -540,6 +541,18 @@ created_invoice_attachments_by_file_name = accounting_api.create_invoice_attachm
---
## SDK conventions


---
## Running Test(s) in Local
For Running Test cases PRISM Mock Server needs to be started in the local machine.
Steps to Run Test(s)
* Install PRISM from npm using the command: **npm install -g @stoplight/prism-cli**
* Verify Installation: **prism --version**
* Navigate to **tests--> utils--> ** folder in the terminal
* Execute the script **./start-prism.sh**
* This will start the PRISM Server in Local
* Run **pytest** to run the dotnet test cases.

### Querying & Filtering

Describe the support for query options and filtering
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
python-dateutil>=2.7
urllib3
certifi
setuptools>=75.1.0
11 changes: 11 additions & 0 deletions tests/utils/start-prism.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_accounting.yaml --host 127.0.0.1 --port 4010 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-app-store.yaml --host 127.0.0.1 --port 4011 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_assets.yaml --host 127.0.0.1 --port 4012 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero_bankfeeds.yaml --host 127.0.0.1 --port 4013 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-finance.yaml --host 127.0.0.1 --port 4014 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-uk.yaml --host 127.0.0.1 --port 4015 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-nz.yaml --host 127.0.0.1 --port 4016 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-payroll-au.yaml --host 127.0.0.1 --port 4017 &
prism mock https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/refs/heads/master/xero-projects.yaml --host 127.0.0.1 --port 4018
Loading