Skip to content

Commit f53bb5f

Browse files
Deploy track changes (#410)
Deploy track changes (#410)
1 parent b0a6786 commit f53bb5f

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
jobs:
1111
publish:
1212
runs-on: ubuntu-latest
13+
environment: prod
1314

1415
outputs:
1516
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
@@ -110,3 +111,54 @@ jobs:
110111
button_type: "danger"
111112
package_version: ${{needs.publish.outputs.release_number}}
112113
repo_link: ${{github.server_url}}/${{github.repository}}
114+
115+
notify-codegen-repo:
116+
needs: publish
117+
if: always()
118+
runs-on: ubuntu-latest
119+
permissions:
120+
contents: write
121+
pull-requests: write
122+
123+
steps:
124+
- name: Checkout
125+
uses: actions/checkout@v4
126+
with:
127+
repository: XeroAPI/Xero-Java
128+
path: Xero-Java
129+
130+
- name: Install octokit dependencies
131+
run: npm i
132+
working-directory: Xero-Java/.github/octokit
133+
134+
- name: Get github app access token
135+
id: get_access_token
136+
env:
137+
GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
138+
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
139+
uses: actions/github-script@v7
140+
with:
141+
result-encoding: string
142+
script: |
143+
const { getAccessToken } = await import('${{ github.workspace }}/Xero-Java/.github/octokit/index.js')
144+
const token = await getAccessToken()
145+
return token
146+
147+
- name: Notify codegen repo
148+
run: |
149+
curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
150+
-H "Accept: application/vnd.github.v3+json" \
151+
-H "Content-Type: application/json" \
152+
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
153+
-d '{
154+
"ref": "master",
155+
"inputs": {
156+
"commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
157+
"status": "${{needs.publish.result}}",
158+
"deployer": "xero-codegen-bot",
159+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
160+
"environment": "prod",
161+
"sdk_type": "java",
162+
"cab_key": "${{ github.event.inputs.cab_id }}"
163+
}
164+
}'

0 commit comments

Comments
 (0)