diff --git a/.github/actions/notify-slack/action.yml b/.github/actions/notify-slack/action.yml new file mode 100644 index 00000000..add9673f --- /dev/null +++ b/.github/actions/notify-slack/action.yml @@ -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/slack-github-action@v1.27.0 + 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}}" + } + ] + } + ] + } diff --git a/.github/workflows/build-test-lint.yml b/.github/workflows/build-test-lint.yml index fdef6146..6b403c9d 100644 --- a/.github/workflows/build-test-lint.yml +++ b/.github/workflows/build-test-lint.yml @@ -27,9 +27,14 @@ 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 @@ -38,9 +43,25 @@ jobs: 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 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8d4bd879..1b045ba2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,6 +6,11 @@ on: 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 @@ -27,6 +32,16 @@ jobs: 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 @@ -35,5 +50,51 @@ jobs: env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }} - run: twine upload --repository-url https://test.pypi.org/legacy/ dist/* + 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: + 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}} diff --git a/README.md b/README.md index bc6bbf51..2bfd07da 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 diff --git a/requirements.txt b/requirements.txt index 11231fa7..f1163e77 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ python-dateutil>=2.7 urllib3 certifi +setuptools>=75.1.0 diff --git a/tests/utils/start-prism.sh b/tests/utils/start-prism.sh new file mode 100755 index 00000000..7a29b941 --- /dev/null +++ b/tests/utils/start-prism.sh @@ -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