Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/octokit/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {Octokit} from "@octokit/rest";
import {createAppAuth} from "@octokit/auth-app"

export const getAccessToken = async () => {

const {GITHUB_APP_ID, GITHUB_APP_PRIVATE_KEY} = process.env

const octoKitInstance = new Octokit({
authStrategy: createAppAuth,
auth: {
appId: GITHUB_APP_ID,
privateKey: GITHUB_APP_PRIVATE_KEY
}
});

const {data: installations} = await octoKitInstance.rest.apps.listInstallations()

console.log("installations -----", installations);


if(!installations.length) {
throw new Error("No Installations found for this github app")
}

const installationId = installations[0].id;

const installationAccessToken = await octoKitInstance.rest.apps.createInstallationAccessToken({installation_id: installationId})

return installationAccessToken.data.token
}
16 changes: 16 additions & 0 deletions .github/octokit/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "xero-octokit",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"@octokit/auth-app": "^7.1.1",
"@octokit/rest": "^21.0.2"
}
}
52 changes: 52 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
publish:
runs-on: ubuntu-latest
environment: prod
outputs:
release_number: ${{steps.get_latest_release_number.outputs.release_tag}}
permissions:
Expand Down Expand Up @@ -106,3 +107,54 @@ jobs:
button_type: "danger"
package_version: ${{needs.publish.outputs.release_number}}
repo_link: ${{github.server_url}}/${{github.repository}}

notify-codegen-repo:
needs: publish
if: always()
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: XeroAPI/xero-python
path: xero-python

- name: Install octokit dependencies
run: npm i
working-directory: xero-python/.github/octokit

- name: Get github app access token
id: get_access_token
env:
GITHUB_APP_ID: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_ID }}
GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_CODEGEN_BOT_APPLICATION_KEY }}
uses: actions/github-script@v7
with:
result-encoding: string
script: |
const { getAccessToken } = await import('${{ github.workspace }}/xero-python/.github/octokit/index.js')
const token = await getAccessToken()
return token

- name: Notify codegen repo
run: |
curl -X POST -H "Authorization: token ${{ steps.get_access_token.outputs.result }}" \
-H "Accept: application/vnd.github.v3+json" \
-H "Content-Type: application/json" \
https://api.github.com/repos/xero-internal/xeroapi-sdk-codegen/actions/workflows/notify-sdk-publish.yml/dispatches \
-d '{
"ref": "master",
"inputs": {
"commit": "${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}",
"status": "${{needs.publish.result}}",
"deployer": "xero-codegen-bot",
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"environment": "prod",
"sdk_type": "python",
"cab_key": "${{ github.event.inputs.cab_id }}"
}
}'