-
Notifications
You must be signed in to change notification settings - Fork 156
[PETOSS-829] Add codegen testing and replace linters #757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 19 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
4f30dd6
[PETOSS-829] added OAS-release actions and PR- Health check
ryanNexus 27ddddf
fix: change npm ci to npm install and add package-lock.json
ryanNexus a07f371
[PETOSS-829] use npm ci not install as its faster
ryanNexus 4f15215
[PETOSS-829] use latest version of npm
ryanNexus a950752
[PETOSS-829] gha fixes
ryanNexus 8a7e8c0
[PETOSS-829] gha fixes +1
ryanNexus d046385
[PETOSS-829] gha fixes +2
ryanNexus 87c005e
[PETOSS-829] gha fixes +3
ryanNexus 3ae3ee1
[PETOSS-829] gha fixes +4
ryanNexus 9492985
fix: use public npm registry instead of Xero Artifactory
ryanNexus 92c753e
[PETOSS-829] removed linter as its now a seperate action
ryanNexus fd4f976
[PETOSS-829] gha fixes +5
ryanNexus 4d31438
[PETOSS-829] rolledback to v1 of dispatch as v2 creates a distinct i…
ryanNexus baf70ab
[PETOSS-829] updated how the sdk generation is called
ryanNexus f9bf5b2
[PETOSS-829] increase timeout
ryanNexus 1d8fa8f
[PETOSS-829] removed disabled linting steps
ryanNexus 0ae6260
[PETOSS-829] re phrased readme
ryanNexus f3f6795
[PETOSS-829] re named OAS release to Github release
ryanNexus bc66166
[PETOSS-829] removed auto merge GHA step
ryanNexus f351437
[PETOSS-829] removed redundant code
ryanNexus d884869
[PETOSS-829] removed more auto merging code
ryanNexus cd1d669
[PETOSS-829] renamed package to function name
ryanNexus 5833874
[PETOSS-829] moved commit lint files to .github folder
ryanNexus 499a03e
[PETOSS-829] set working directory for commit lint
ryanNexus e5e3798
[PETOSS-829] Update package config
the-chris-mitchell 6b0ee15
[PETOSS-829] Remove workflow and generator code
the-chris-mitchell 2948e67
[PETOSS-829] Rename workflows
the-chris-mitchell 309009a
[PETOSS-829] Make consistent and update naming
the-chris-mitchell 2b26a3d
[PETOSS-829] Increase timeout
the-chris-mitchell 3f39109
[PETOSS-829] Change config file format
the-chris-mitchell 619da55
[PETOSS-829] Update installation process and paths
the-chris-mitchell 1eb1bcc
[PETOSS-829] Rename jobs
the-chris-mitchell 500f0b7
[PETOSS-829] Reformat yaml
the-chris-mitchell 0502525
[PETOSS-829] Consolidate pr validation steps
the-chris-mitchell 04e9e89
[PETOSS-829] Update linter version
the-chris-mitchell 71173b0
[PETOSS-829] Add specific job names
the-chris-mitchell 742f826
[PETOSS-829] Use correct option key
the-chris-mitchell 996aeab
[PETOSS-829] Move spectral into megalinter
the-chris-mitchell 8a063d3
[PETOSS-829] Tidy up file no longer required
the-chris-mitchell f1d9de5
[PETOSS-829] Update megalinter and spectral config
the-chris-mitchell 240ddb8
[PETOSS-829] Rename file
the-chris-mitchell 1ae9e67
[PETOSS-829] Install spectral plugin
the-chris-mitchell 3121e22
[PETOSS-829] Update megalinter config
the-chris-mitchell 6aa3759
[PETOSS-829] Remove actionslint
the-chris-mitchell 438a948
[PETOSS-829] Disable rules
the-chris-mitchell 384192a
Merge branch 'master' of https://github.com/XeroAPI/Xero-OpenAPI into…
the-chris-mitchell be02f96
[PETOSS-829] Only lint OAS files
the-chris-mitchell 6cc7239
[PETOSS-829] Disable rules
the-chris-mitchell 79492f1
[PETOSS-829] Disable flavor suggestions
the-chris-mitchell 70a0f90
[PETOSS-829] Rename package
the-chris-mitchell f089547
[PETOSS-829] Add comments and newlines back in
the-chris-mitchell a56eb31
[PETOSS-829] Remove mention of commitlint
the-chris-mitchell a4820db
[PETOSS-829] Reword note
the-chris-mitchell File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 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() | ||
|
|
||
| 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 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "openapi-release", | ||
| "private": true, | ||
| "devDependencies": { | ||
| "@semantic-release/git": "^10.0.1", | ||
| "@semantic-release/github": "^11.0.0", | ||
| "semantic-release": "^24.1.1" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| const config = { | ||
| branches: ['master'], | ||
| tagFormat: "${version}", | ||
| plugins: [ | ||
| ['@semantic-release/release-notes-generator', | ||
| { | ||
| preset: 'angular', | ||
| writerOpts: { | ||
| headerPartial: '## What\'s changed', | ||
| footerPartial: '\n**Full Changelog**:https://github.com/XeroAPI/Xero-OpenAPI/compare/{{previousTag}}...{{version}}' | ||
| } | ||
| } | ||
| ], | ||
| '@semantic-release/commit-analyzer', | ||
| '@semantic-release/github', | ||
| '@semantic-release/git', | ||
|
|
||
| ] | ||
| } | ||
| module.exports = config; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| name: Create Github Release | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| Github-release: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| issues: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
|
|
||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Node environment | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
|
|
||
| - name: install node package | ||
| run: npm i | ||
| working-directory: ${{ github.workspace }}/.github/semantic-release | ||
|
|
||
| - name: Perform release | ||
| run: | | ||
| npx semantic-release | ||
| env: | ||
| GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
| working-directory: ${{ github.workspace }}/.github/semantic-release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| name: OAS PR health check | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, reopened, synchronize] | ||
| branches: | ||
| - master | ||
| push: | ||
| branches: | ||
| - master | ||
|
|
||
| jobs: | ||
| pr-health-check: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| actions: read | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Node environment | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| registry-url: 'https://registry.npmjs.org' | ||
|
|
||
| - name: Install dependencies | ||
| timeout-minutes: 5 | ||
| run: | | ||
| npm config set registry https://registry.npmjs.org | ||
| npm ci --verbose | ||
|
|
||
| - name: Install octokit dependencies | ||
| run: npm i | ||
| working-directory: ${{ github.workspace }}/.github/octokit | ||
|
|
||
| - name: Get github app access token | ||
| id: get_access_token | ||
| env: | ||
| GITHUB_APP_ID: ${{ secrets.XERO_GITHUB_APP_ID }} | ||
| GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_GITHUB_APPLICATION_KEY }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| result-encoding: string | ||
| script: | | ||
| const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') | ||
| const token = await getAccessToken() | ||
| return token | ||
|
|
||
| - name: Trigger all SDK workflow | ||
| id: return_dispatch | ||
| env: | ||
| GH_TOKEN: ${{ steps.get_access_token.outputs.result }} | ||
| run: | | ||
| BRANCH_NAME="${{ github.event_name == 'pull_request' && github.head_ref || 'master' }}" | ||
|
|
||
| # Trigger the workflow and capture the response | ||
| gh workflow run pr.yml \ | ||
| --repo xero-internal/xeroapi-sdk-codegen \ | ||
| --ref master \ | ||
| --field branch_name="$BRANCH_NAME" | ||
|
|
||
| # Wait a moment for the run to be created | ||
| sleep 5 | ||
|
|
||
| # Get the latest run ID for the workflow | ||
| RUN_ID=$(gh run list \ | ||
| --repo xero-internal/xeroapi-sdk-codegen \ | ||
| --workflow=pr.yml \ | ||
| --limit 1 \ | ||
| --json databaseId \ | ||
| --jq '.[0].databaseId') | ||
|
|
||
| echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT | ||
| echo "Triggered workflow run ID: $RUN_ID" | ||
|
|
||
| - name: Checking SDK health status | ||
| uses: Codex-/await-remote-run@v1.12.2 | ||
| with: | ||
| token: ${{ steps.get_access_token.outputs.result }} | ||
| repo: xeroapi-sdk-codegen | ||
| owner: xero-internal | ||
| run_id: ${{ steps.return_dispatch.outputs.run_id }} | ||
| workflow_time_minimum: 60 | ||
| max_timeout: 3600 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| name: Update OAS version and raise PR | ||
|
|
||
| on: | ||
| release: | ||
| types: [published] | ||
|
|
||
| jobs: | ||
| Update-yaml-version: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Checkout Repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: 'master' | ||
|
|
||
| - name: Install octokit dependencies | ||
| run: npm i | ||
| working-directory: ${{ github.workspace }}/.github/octokit | ||
|
|
||
| - name: Get github app access token | ||
| id: get_access_token | ||
| env: | ||
| GITHUB_APP_ID: ${{ secrets.XERO_PUBLIC_BOT_APP_ID }} | ||
| GITHUB_APP_PRIVATE_KEY: ${{ secrets.XERO_PUBLIC_BOT_KEY }} | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| result-encoding: string | ||
| script: | | ||
| const { getAccessToken } = await import('${{ github.workspace }}/.github/octokit/index.js') | ||
| const token = await getAccessToken() | ||
| return token | ||
|
|
||
| - name: Fetch Latest release number | ||
| id: get_latest_release_number | ||
| run: | | ||
| latest_version=$(gh release view --json tagName --jq '.tagName') | ||
| echo "Latest release version is - $latest_version" | ||
| echo "releaseVersion=$latest_version" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{steps.get_access_token.outputs.result}} | ||
|
|
||
|
|
||
| - name: Set up branch name | ||
| id: identify_branch_name | ||
| run: | | ||
| branch_name='OAS-version-update-${{steps.get_latest_release_number.outputs.releaseVersion}}' | ||
| echo "branchName=$branch_name" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Checkout branch | ||
| run: | | ||
| if git ls-remote --heads origin ${{steps.identify_branch_name.outputs.branchName}} | grep -q "refs/heads/${{steps.identify_branch_name.outputs.branchName}}"; then | ||
| echo "checking out existing branch" | ||
| git fetch origin > /dev/null 2>&1 | ||
| git checkout ${{steps.identify_branch_name.outputs.branchName}} | ||
| else | ||
| echo "branch does not exists, creating new branch" | ||
| echo "branchName *****>> ${{steps.identify_branch_name.outputs.branchName}}" | ||
| git checkout -b ${{steps.identify_branch_name.outputs.branchName}} | ||
| fi | ||
|
|
||
| - name: Update OAS version of the spec yaml files | ||
| run: | | ||
| for file in xero_accounting.yaml xero_assets.yaml xero_bankfeeds.yaml xero_files.yaml xero-app-store.yaml xero-finance.yaml xero-identity.yaml xero-payroll-au.yaml xero-payroll-nz.yaml xero-payroll-uk.yaml xero-projects.yaml; do | ||
| yq eval --no-colors --prettyPrint ".info.version = \"${{steps.get_latest_release_number.outputs.releaseVersion}}\"" -i "$file" | ||
| echo "updated version in $file" | ||
| done | ||
|
|
||
| - name: Staging & commiting | ||
| id: detect-changes | ||
| run: | | ||
| CHANGES_DETECTED=$(git diff) | ||
| if [ -z "$CHANGES_DETECTED" ]; then | ||
| echo "no new changes, nothing to commit" | ||
| echo "changes_detected=false" >> $GITHUB_OUTPUT | ||
| else | ||
| echo "changes_detected=true" >> $GITHUB_OUTPUT | ||
| echo "running the git commands......" | ||
|
|
||
| git branch | ||
|
|
||
| echo "git status 1" | ||
| git status | ||
|
|
||
| echo 'staging the changes' | ||
| git add --all | ||
|
|
||
| echo 'git status' | ||
| git diff | ||
|
|
||
| echo "git config setup" | ||
| git config --global user.name "Github Actions" | ||
| git config --global user.email "actions@github.com" | ||
|
|
||
| echo 'commiting changes....' | ||
| git commit -m "chore: version update for all the yaml files" | ||
| fi | ||
|
|
||
| - name: Pushing the Branch | ||
| run: | | ||
| if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then | ||
| echo "pushing the code to ${{steps.identify_branch_name.outputs.branchName}}" | ||
| git branch | ||
| git push origin ${{steps.identify_branch_name.outputs.branchName}} | ||
| else | ||
| echo "branch is already up to date" | ||
| fi | ||
|
|
||
| - name: Create PR | ||
| run: | | ||
| if [ "${{steps.detect-changes.outputs.changes_detected}}" == "true" ]; then | ||
| echo "Creating PR in ${{steps.identify_branch_name.outputs.branchName}}" | ||
| gh pr create \ | ||
| --title "OAS version update - ${{steps.get_latest_release_number.outputs.releaseVersion}}" \ | ||
| --base master \ | ||
| --head ${{steps.identify_branch_name.outputs.branchName}} \ | ||
| --body "chore: version update for all the yaml files" | ||
| else | ||
| echo "PR is already up to date" | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{steps.get_access_token.outputs.result}} | ||
|
|
||
| - name: Find PR number to merge | ||
| id: identify_PR_number | ||
| run: | | ||
| BRANCH_NAME=${{steps.identify_branch_name.outputs.branchName}} | ||
| PR_NUMBER=$(gh pr list --head "$BRANCH_NAME" --json number --jq '. [0].number') | ||
| echo "PR number: $PR_NUMBER" | ||
| echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_OUTPUT | ||
| env: | ||
| GH_TOKEN: ${{steps.get_access_token.outputs.result}} | ||
|
|
||
| - name: Verify PR is merged | ||
| run: | | ||
| pr_state=$(gh pr view ${{steps.identify_PR_number.outputs.PR_NUMBER}} --json state --jq '.state') | ||
|
|
||
| echo "pr state: $pr_state" | ||
|
|
||
| if [ $pr_state == "MERGED" ]; then | ||
| echo "PR ${{steps.identify_PR_number.outputs.PR_NUMBER}} has been merged" | ||
| else | ||
| echo "PR ${{steps.identify_PR_number.outputs.PR_NUMBER}} is not merged" | ||
| exit 1 | ||
| fi | ||
| env: | ||
| GH_TOKEN: ${{steps.get_access_token.outputs.result}} | ||
|
ryanNexus marked this conversation as resolved.
Outdated
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| registry=https://registry.npmjs.org/ |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.