Skip to content

Commit baa28fa

Browse files
Deploytrack changes (#338)
Deploytrack changes (#338)
1 parent 3fc6d3b commit baa28fa

File tree

3 files changed

+98
-1
lines changed

3 files changed

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

0 commit comments

Comments
 (0)