Skip to content

Commit c7dc688

Browse files
Deploy track changes (#188)
Deploy track changes (#188)
1 parent 71bdd4f commit c7dc688

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed
File renamed without changes.

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

0 commit comments

Comments
 (0)