From 513e5ec770636a8892894181f67f7a43ec584aad Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Thu, 5 Jun 2025 13:26:28 +0530 Subject: [PATCH 1/7] deploy track changes --- .github/workflows/publish.yml | 53 ++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7d79bfc8..3ab92261 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -100,4 +100,55 @@ jobs: 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}} \ No newline at end of file + 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 }} + } + }' \ No newline at end of file From b68fa8cc4b90de3d036ae77fc38acdcbef2eb582 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Thu, 5 Jun 2025 15:55:57 +0530 Subject: [PATCH 2/7] added octokit --- .github/octokit/index.js | 30 ++++++++++++++++++++++++++++++ .github/octokit/package.json | 16 ++++++++++++++++ .github/workflows/publish.yml | 7 +++---- 3 files changed, 49 insertions(+), 4 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 3ab92261..8d4e1827 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -101,7 +101,6 @@ 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() @@ -114,8 +113,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 with: - repository: XeroAPI/xero-node - path: xero-node + repository: XeroAPI/xero-ruby + path: xero-ruby - name: Install octokit dependencies run: npm i @@ -141,7 +140,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 31d67018e196fefbd71da0b749c389430cbcdc37 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 14:23:10 +0530 Subject: [PATCH 3/7] added protected env --- .github/workflows/publish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8d4e1827..6efdbdc5 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 7fb152d6479d4eb0d3febcf64eb64dce787591b0 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 10 Jun 2025 19:00:56 +0530 Subject: [PATCH 4/7] corrected octokit 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 6efdbdc5..e980bf66 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -119,7 +119,7 @@ jobs: - name: Install octokit dependencies run: npm i - working-directory: ${{ github.workspace }}/.github/octokit + working-directory: xero-ruby/.github/octokit - name: Get github app access token id: get_access_token @@ -130,7 +130,7 @@ jobs: with: result-encoding: string script: | - const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') + const { getAccessToken } = await import('${{ github.workspace }}/xero-ruby/.github/octokit/index.js') const token = await getAccessToken() return token @@ -149,6 +149,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 From 6e6bb8488f57c6b8895201a4d3e844e3d4ded7fb Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 17 Jun 2025 10:02:23 +0530 Subject: [PATCH 5/7] testing --- .github/workflows/publish.yml | 146 +++++++++++++++++----------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e980bf66..701d59c0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,85 +23,85 @@ jobs: repository: XeroAPI/xero-ruby path: xero-ruby - - 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-ruby - 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-ruby + # env: + # GH_TOKEN: ${{secrets.GITHUB_TOKEN}} - - name: Set up Ruby environment - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.2.0' - bundler-cache: true + # - name: Set up Ruby environment + # uses: ruby/setup-ruby@v1 + # with: + # ruby-version: '3.2.0' + # bundler-cache: true - - name: Install dependencies - run: bundle install - working-directory: xero-ruby + # - name: Install dependencies + # run: bundle install + # working-directory: xero-ruby - - name: Publish to Ruby - env: - GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} - run: | - gemspec_file=$(ls *.gemspec) - gem_file=$(gem build "$gemspec_file" | grep -o '[^ ]*\.gem') - echo "$gem_file" - gem push "$gem_file" - working-directory: xero-ruby + # - name: Publish to Ruby + # env: + # GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} + # run: | + # gemspec_file=$(ls *.gemspec) + # gem_file=$(gem build "$gemspec_file" | grep -o '[^ ]*\.gem') + # echo "$gem_file" + # gem push "$gem_file" + # working-directory: xero-ruby - notify-slack-on-success: - runs-on: ubuntu-latest - needs: publish - if: success() - permissions: - contents: read - steps: - - name: Checkout xero-ruby repo - uses: actions/checkout@v4 - with: - repository: XeroAPI/xero-ruby - path: xero-ruby + # notify-slack-on-success: + # runs-on: ubuntu-latest + # needs: publish + # if: success() + # permissions: + # contents: read + # steps: + # - name: Checkout xero-ruby repo + # uses: actions/checkout@v4 + # with: + # repository: XeroAPI/xero-ruby + # path: xero-ruby - - name: Send slack notification on success - uses: ./xero-ruby/.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}} + # - name: Send slack notification on success + # uses: ./xero-ruby/.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() - permissions: - contents: read - steps: - - name: Checkout xero-ruby repo - uses: actions/checkout@v4 - with: - repository: XeroAPI/xero-ruby - path: xero-ruby + # notify-slack-on-failure: + # runs-on: ubuntu-latest + # needs: publish + # if: failure() + # permissions: + # contents: read + # steps: + # - name: Checkout xero-ruby repo + # uses: actions/checkout@v4 + # with: + # repository: XeroAPI/xero-ruby + # path: xero-ruby - - name: Send slack notification on failure - uses: ./xero-ruby/.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}} + # - name: Send slack notification on failure + # uses: ./xero-ruby/.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}} notify-codegen-repo: needs: publish if: always() @@ -148,7 +148,7 @@ jobs: "deployer": "xero-codegen-bot", "url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}", "environment": "test", - "sdk_type": "node", + "sdk_type": "ruby", "cab_key": "${{ github.event.inputs.cab_id }}" } }' \ No newline at end of file From 44a14da7fe5b0f8e475057991a420897a5a0b602 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 17 Jun 2025 10:19:51 +0530 Subject: [PATCH 6/7] clean up --- .github/workflows/publish.yml | 146 +++++++++++++++++----------------- 1 file changed, 73 insertions(+), 73 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 701d59c0..025c0455 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,85 +23,85 @@ jobs: repository: XeroAPI/xero-ruby path: xero-ruby - # - 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-ruby - # 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-ruby + env: + GH_TOKEN: ${{secrets.GITHUB_TOKEN}} - # - name: Set up Ruby environment - # uses: ruby/setup-ruby@v1 - # with: - # ruby-version: '3.2.0' - # bundler-cache: true + - name: Set up Ruby environment + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2.0' + bundler-cache: true - # - name: Install dependencies - # run: bundle install - # working-directory: xero-ruby + - name: Install dependencies + run: bundle install + working-directory: xero-ruby - # - name: Publish to Ruby - # env: - # GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} - # run: | - # gemspec_file=$(ls *.gemspec) - # gem_file=$(gem build "$gemspec_file" | grep -o '[^ ]*\.gem') - # echo "$gem_file" - # gem push "$gem_file" - # working-directory: xero-ruby + - name: Publish to Ruby + env: + GEM_HOST_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }} + run: | + gemspec_file=$(ls *.gemspec) + gem_file=$(gem build "$gemspec_file" | grep -o '[^ ]*\.gem') + echo "$gem_file" + gem push "$gem_file" + working-directory: xero-ruby - # notify-slack-on-success: - # runs-on: ubuntu-latest - # needs: publish - # if: success() - # permissions: - # contents: read - # steps: - # - name: Checkout xero-ruby repo - # uses: actions/checkout@v4 - # with: - # repository: XeroAPI/xero-ruby - # path: xero-ruby + notify-slack-on-success: + runs-on: ubuntu-latest + needs: publish + if: success() + permissions: + contents: read + steps: + - name: Checkout xero-ruby repo + uses: actions/checkout@v4 + with: + repository: XeroAPI/xero-ruby + path: xero-ruby - # - name: Send slack notification on success - # uses: ./xero-ruby/.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}} + - name: Send slack notification on success + uses: ./xero-ruby/.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() - # permissions: - # contents: read - # steps: - # - name: Checkout xero-ruby repo - # uses: actions/checkout@v4 - # with: - # repository: XeroAPI/xero-ruby - # path: xero-ruby + notify-slack-on-failure: + runs-on: ubuntu-latest + needs: publish + if: failure() + permissions: + contents: read + steps: + - name: Checkout xero-ruby repo + uses: actions/checkout@v4 + with: + repository: XeroAPI/xero-ruby + path: xero-ruby - # - name: Send slack notification on failure - # uses: ./xero-ruby/.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}} + - name: Send slack notification on failure + uses: ./xero-ruby/.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}} notify-codegen-repo: needs: publish if: always() @@ -147,7 +147,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": "ruby", "cab_key": "${{ github.event.inputs.cab_id }}" } From 0d9aaf3e754c69404cc3376a8cfa77881eb5e941 Mon Sep 17 00:00:00 2001 From: sangeet-joy_xero Date: Tue, 17 Jun 2025 11:04:30 +0530 Subject: [PATCH 7/7] 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 025c0455..5fef44a8 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: