Skip to content

Commit 5419b79

Browse files
author
sangeet-joy_xero
committed
deploytrack changes
1 parent 3085457 commit 5419b79

File tree

3 files changed

+90
-3
lines changed

3 files changed

+90
-3
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/check-publish.yml

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
name: Check Packagist Publish
22

33
on:
4-
release:
5-
types: [published]
4+
workflow_dispatch:
5+
inputs:
6+
cab_id:
7+
description: "CAB id for the change/release"
8+
required: true
9+
type: string
610

711
jobs:
812
check-publish:
@@ -77,4 +81,41 @@ jobs:
7781
if: ${{env.packagist_status == 'failure'}}
7882
run: |
7983
echo "Job failed because packagist is not updated"
80-
exit 1
84+
exit 1
85+
86+
- name: Install octokit dependencies
87+
run: npm i
88+
working-directory: ${{ github.workspace }}/.github/octokit
89+
90+
- name: Get github app access token
91+
id: get_access_token
92+
env:
93+
GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
94+
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
95+
uses: actions/github-script@v7
96+
with:
97+
result-encoding: string
98+
script: |
99+
const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js')
100+
const token = await getAccessToken()
101+
return token
102+
103+
- name: Notify codegen repo
104+
if: always()
105+
run: |
106+
curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
107+
-H "Accept: application/vnd.github.v3+json" \
108+
-H "Content-Type: application/json" \
109+
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
110+
-d '{
111+
"ref": "master",
112+
"inputs": {
113+
"commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
114+
"status": "${{env.packagist_status}}",
115+
"deployer": "xero-codegen-bot",
116+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
117+
"environment": "test",
118+
"sdk_type": "node",
119+
"cab_key": ${{ github.event.inputs.cab_id }}
120+
}
121+
}'

0 commit comments

Comments
 (0)