Skip to content

Commit dfbdf9f

Browse files
Node SDK | Deploy track changes (#756)
Node SDK | Deploy track changes (#756)
1 parent 3d66920 commit dfbdf9f

File tree

4 files changed

+97
-8
lines changed

4 files changed

+97
-8
lines changed

.github/octokit/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {Octokit} from "@octokit/rest";
2+
import {createAppAuth} from "@octokit/auth-app"
3+
4+
export const getAccessToken = async () => {
5+
6+
const {GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY} = process.env
7+
8+
const octoKitInstance = new Octokit({
9+
authStrategy: createAppAuth,
10+
auth: {
11+
appId: GITHUB_APP_ID,
12+
privateKey: GITHUB_APP_PRIVATE_KEY
13+
}
14+
});
15+
16+
const {data: installations} = await octoKitInstance.rest.apps.listInstallations()
17+
18+
console.log("installations -----", installations);
19+
20+
21+
if(!installations.length) {
22+
throw new Error("No Installations found for this github app")
23+
}
24+
25+
const installationId = installations[0].id;
26+
27+
const installationAccessToken = await octoKitInstance.rest.apps.createInstallationAccessToken({installation_id: installationId})
28+
29+
return installationAccessToken.data.token
30+
}

.github/octokit/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "xero-octokit",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"@octokit/auth-app": "^7.1.1",
14+
"@octokit/rest": "^21.0.2"
15+
}
16+
}

.github/workflows/publish.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,57 @@ jobs:
5555
run: npm publish
5656
working-directory: xero-node
5757

58+
notify-codegen-repo:
59+
needs: publish
60+
if: always()
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: write
64+
pull-requests: write
65+
66+
steps:
67+
- name: Checkout
68+
uses: actions/checkout@v4
69+
with:
70+
repository: XeroAPI/xero-node
71+
path: xero-node
72+
73+
- name: Install octokit dependencies
74+
run: npm i
75+
working-directory: xero-node/.github/octokit
76+
77+
- name: Get github app access token
78+
id: get_access_token
79+
env:
80+
GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
81+
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
82+
uses: actions/github-script@v7
83+
with:
84+
result-encoding: string
85+
script: |
86+
const { getAccessToken } = await import('${{ github.workspace }}/xero-node/.github/octokit/index.js')
87+
const token = await getAccessToken()
88+
return token
89+
90+
- name: Notify codegen repo
91+
run: |
92+
curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
93+
-H "Accept: application/vnd.github.v3+json" \
94+
-H "Content-Type: application/json" \
95+
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
96+
-d '{
97+
"ref": "master",
98+
"inputs": {
99+
"commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
100+
"status": "${{needs.publish.result}}",
101+
"deployer": "xero-codegen-bot",
102+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
103+
"environment": "prod",
104+
"sdk_type": "node",
105+
"cab_key": "${{ github.event.inputs.cab_id }}"
106+
}
107+
}'
108+
58109
notify-slack-on-success:
59110
runs-on: ubuntu-latest
60111
needs: publish

deploytrack.yaml

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)