From b997dcd5af013c196dd97126c21f66c8c9c9f881 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Thu, 5 Jun 2025 13:21:20 +0530 Subject: [PATCH 1/8] Deploy track changes python --- .github/workflows/publish.yml | 61 +++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 0d569d9b..deee7247 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,11 @@ -name: Publish +name: Publish & Release SDK on: - release: - types: [published] + workflow_dispatch: + inputs: + cab_id: + description: "CAB id for the change/release" + required: true + type: string jobs: publish: @@ -102,3 +106,54 @@ jobs: button_type: "danger" package_version: ${{needs.publish.outputs.release_number}} repo_link: ${{github.server_url}}/${{github.repository}} + + notify-codegen-repo: + needs: publish + if: always() + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + repository: XeroAPI/xero-node + path: xero-node + + - name: Install octokit dependencies + run: npm i + working-directory: ${{ github.workspace }}/.github/octokit + + - name: Get github app access token + id: get_access_token + env: + GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }} + GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }} + uses: actions/github-script@v7 + with: + result-encoding: string + script: | + const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') + const token = await getAccessToken() + return token + + - name: Notify codegen repo + run: | + curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -H "Content-Type: application/json" \ + https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \ + -d '{ + "ref": "deploy-track-pipeline-changes", + "inputs": { + "commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}", + "status": "${{needs.publish.result}}", + "deployer": "xero-codegen-bot", + "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", + "environment": "test", + "sdk_type": "node", + "cab_key": ${{ github.event.inputs.cab_id }} + } + }' From f3e3c8ec11d8e83a53a2d27a820e22880f5c4808 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Thu, 5 Jun 2025 15:57:01 +0530 Subject: [PATCH 2/8] added octokit --- .github/octokit/index.js | 30 ++++++++++++++++++++++++++++++ .github/octokit/package.json | 16 ++++++++++++++++ .github/workflows/publish.yml | 6 +++--- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 .github/octokit/index.js create mode 100644 .github/octokit/package.json diff --git a/.github/octokit/index.js b/.github/octokit/index.js new file mode 100644 index 00000000..b308cb3b --- /dev/null +++ b/.github/octokit/index.js @@ -0,0 +1,30 @@ +import {Octokit} from "@octokit/rest"; +import {createAppAuth} from "@octokit/auth-app" + +export const getAccessToken = async () => { + + const {GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY} = process.env + + const octoKitInstance = new Octokit({ + authStrategy: createAppAuth, + auth: { + appId: GITHUB_APP_ID, + privateKey: GITHUB_APP_PRIVATE_KEY + } + }); + + const {data: installations} = await octoKitInstance.rest.apps.listInstallations() + + console.log("installations -----", installations); + + + if(!installations.length) { + throw new Error("No Installations found for this github app") + } + + const installationId = installations[0].id; + + const installationAccessToken = await octoKitInstance.rest.apps.createInstallationAccessToken({installation_id: installationId}) + + return installationAccessToken.data.token +} \ No newline at end of file diff --git a/.github/octokit/package.json b/.github/octokit/package.json new file mode 100644 index 00000000..66fb13ca --- /dev/null +++ b/.github/octokit/package.json @@ -0,0 +1,16 @@ +{ + "name": "xero-octokit", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@octokit/auth-app": "^7.1.1", + "@octokit/rest": "^21.0.2" + } + } \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index deee7247..cf9cf510 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -119,8 +119,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - repository: XeroAPI/xero-node - path: xero-node + repository: XeroAPI/xero-python + path: xero-python - name: Install octokit dependencies run: npm i @@ -146,7 +146,7 @@ jobs: -H "Content-Type: application/json" \ https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \ -d '{ - "ref": "deploy-track-pipeline-changes", + "ref": "master", "inputs": { "commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}", "status": "${{needs.publish.result}}", From 9054328f3b985b1f8a40aa3c9d7b621c53bb0e23 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 14:25:21 +0530 Subject: [PATCH 3/8] deploytrack-changes-python --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cf9cf510..084cc5b1 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,6 +10,7 @@ on: jobs: publish: runs-on: ubuntu-latest + environment: protected-env outputs: release_number: ${{steps.get_latest_release_number.outputs.release_tag}} permissions: From baedc273f35b8fe10ac2d9bc3f3e656dd1656b5a Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 18:59:44 +0530 Subject: [PATCH 4/8] corrected path --- .github/workflows/publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 084cc5b1..6273fee7 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -125,7 +125,7 @@ jobs: - name: Install octokit dependencies run: npm i - working-directory: ${{ github.workspace }}/.github/octokit + working-directory: xero-python/.github/octokit - name: Get github app access token id: get_access_token @@ -136,7 +136,7 @@ jobs: with: result-encoding: string script: | - const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') + const { getAccessToken } = await import('${{ github.workspace }}/xero-python/.github/octokit/index.js') const token = await getAccessToken() return token @@ -155,6 +155,6 @@ jobs: "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "environment": "test", "sdk_type": "node", - "cab_key": ${{ github.event.inputs.cab_id }} + "cab_key": "${{ github.event.inputs.cab_id }}" } }' From a2692121bae1144f90608302e904782fb975cca8 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 19:01:57 +0530 Subject: [PATCH 5/8] corrected notify slack path --- .github/{workflows => }/actions/notify-slack/action.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflows => }/actions/notify-slack/action.yml (100%) diff --git a/.github/workflows/actions/notify-slack/action.yml b/.github/actions/notify-slack/action.yml similarity index 100% rename from .github/workflows/actions/notify-slack/action.yml rename to .github/actions/notify-slack/action.yml From 0608e30688ce116032fcbee8dbc34d7db187a0c0 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Mon, 16 Jun 2025 12:55:55 +0530 Subject: [PATCH 6/8] testing --- .github/workflows/publish.yml | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 6273fee7..84b996af 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,40 +23,40 @@ jobs: 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: 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: 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: 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: 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 + # - 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 @@ -154,7 +154,7 @@ jobs: "deployer": "xero-codegen-bot", "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "environment": "test", - "sdk_type": "node", + "sdk_type": "python", "cab_key": "${{ github.event.inputs.cab_id }}" } }' From af437e27e1d7f523ee7ed596f83c152279f39fac Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Mon, 16 Jun 2025 13:36:59 +0530 Subject: [PATCH 7/8] clean up --- .github/workflows/publish.yml | 62 +++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 84b996af..fd51f424 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,40 +23,40 @@ jobs: 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: 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: 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: 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: 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 + - 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 @@ -153,7 +153,7 @@ jobs: "status": "${{needs.publish.result}}", "deployer": "xero-codegen-bot", "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", - "environment": "test", + "environment": "prod", "sdk_type": "python", "cab_key": "${{ github.event.inputs.cab_id }}" } From d542c2d48b21dc7f30f145aeb405c8a0e057b17f Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 17 Jun 2025 11:03:07 +0530 Subject: [PATCH 8/8] renamed env --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index fd51f424..6ea5b553 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ on: jobs: publish: runs-on: ubuntu-latest - environment: protected-env + environment: prod outputs: release_number: ${{steps.get_latest_release_number.outputs.release_tag}} permissions: