From 5419b7915b8cb955e39d4c593249829aeaa5814d Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Thu, 5 Jun 2025 15:54:15 +0530 Subject: [PATCH 1/3] deploytrack changes --- .github/octokit/index.js | 30 ++++++++++++++++++ .github/octokit/package.json | 16 ++++++++++ .github/workflows/check-publish.yml | 47 +++++++++++++++++++++++++++-- 3 files changed, 90 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/check-publish.yml b/.github/workflows/check-publish.yml index 245f6406..8ad4f86e 100644 --- a/.github/workflows/check-publish.yml +++ b/.github/workflows/check-publish.yml @@ -1,8 +1,12 @@ name: Check Packagist Publish on: - release: - types: [published] + workflow_dispatch: + inputs: + cab_id: + description: "CAB id for the change/release" + required: true + type: string jobs: check-publish: @@ -77,4 +81,41 @@ jobs: if: ${{env.packagist_status == 'failure'}} run: | echo "Job failed because packagist is not updated" - exit 1 \ No newline at end of file + exit 1 + + - 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 + if: always() + 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": "master", + "inputs": { + "commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}", + "status": "${{env.packagist_status}}", + "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 }} + } + }' \ No newline at end of file From 92a01f247bcff45788196bc677b7083123242359 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 14:21:20 +0530 Subject: [PATCH 2/3] reverted some changes --- .github/workflows/check-publish.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/check-publish.yml b/.github/workflows/check-publish.yml index 8ad4f86e..a5ba5f13 100644 --- a/.github/workflows/check-publish.yml +++ b/.github/workflows/check-publish.yml @@ -1,12 +1,8 @@ name: Check Packagist Publish on: - workflow_dispatch: - inputs: - cab_id: - description: "CAB id for the change/release" - required: true - type: string + release: + types: [published] jobs: check-publish: From 54ed5a6fda5cbd789a475531744ce5f5ce585704 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 19:03:55 +0530 Subject: [PATCH 3/3] corrected the path in php --- .github/workflows/check-publish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-publish.yml b/.github/workflows/check-publish.yml index a5ba5f13..0ea0843e 100644 --- a/.github/workflows/check-publish.yml +++ b/.github/workflows/check-publish.yml @@ -81,7 +81,7 @@ jobs: - name: Install octokit dependencies run: npm i - working-directory: ${{ github.workspace }}/.github/octokit + working-directory: xero-php-oauth2/.github/octokit - name: Get github app access token id: get_access_token @@ -92,7 +92,7 @@ jobs: with: result-encoding: string script: | - const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') + const { getAccessToken } = await import('${{ github.workspace }}/xero-php-oauth2/.github/octokit/index.js') const token = await getAccessToken() return token @@ -112,6 +112,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 }}" } }' \ No newline at end of file