Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8bbf8e4
PETOSS 588 | Pipeline | OAS version update for all spec yaml files (#…
sangeet-joy-tw Oct 15, 2024
f1f4f35
PETOSS 536 | Open API pipeline workflow on PR raise (#678)
sangeet-joy-tw Oct 17, 2024
800cd7a
ci: commitlint step added in PR
Oct 17, 2024
8a3c151
Merge pull request #681 from XeroAPI/PETOSS-588-commitlinting-pipeline
sangeet-joy-tw Oct 18, 2024
98d2e71
ci: updated PR health check trigger condition
Oct 21, 2024
e2bf471
Merge pull request #682 from XeroAPI/PETOSS-588-update-trigger-condition
sangeet-joy-tw Oct 21, 2024
a468fc6
feat: request format has been updated from byte to binary for applica…
Sep 25, 2024
b4cb026
ci: updated the read me typo
Nov 4, 2024
5836221
ci: updated the read me.
sangeet-joy-tw Nov 4, 2024
fdc5a80
ci: typo fix read me
Nov 4, 2024
65430af
ci: typo fix read me
sangeet-joy-tw Nov 4, 2024
14b86c9
Merge branch 'master' into fix/byte-to-binary-changes
vigneshk-tw Nov 4, 2024
9d78edc
Merge pull request #683 from XeroAPI/fix/byte-to-binary-changes
vigneshk-tw Nov 4, 2024
eca2128
feat: trigger commitlint check only on pr
vigneshk-tw Nov 5, 2024
e949a3f
feat: testing commit to trigger on local branch
vigneshk-tw Nov 5, 2024
5294023
feat: revert testing commit to trigger on local branch
vigneshk-tw Nov 5, 2024
e8c221a
Merge pull request #692 from XeroAPI/fix/trigger-commitlint-on-pr-1
vigneshk-tw Nov 5, 2024
6ff4a91
feat: format open api using yq
vigneshk-tw Nov 6, 2024
15e691b
feat: remove unused formatting in yq
vigneshk-tw Nov 6, 2024
e3f4d1b
feat: use pretty print for proper formatting
vigneshk-tw Nov 6, 2024
429bfd6
feat: removed additional tab added
vigneshk-tw Nov 6, 2024
34213f6
Merge pull request #693 from XeroAPI/fix/yq-formatting
vigneshk-tw Nov 6, 2024
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
27 changes: 27 additions & 0 deletions .github/octokit/index.js
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
}
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"
}
}
107 changes: 107 additions & 0 deletions .github/workflows/pr-health-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
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

- name: Install dependencies
run: npm ci

- name: Run commitlint on PR commits
if: github.event_name == 'pull_request'
run: |
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose

# ***** YAML Linting steps are disabled for now *****



# - name: Install Open API yaml linter
# run: npm i -g @quobix/vacuum

# - name: Run open API validation for yamls
# run: |
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero_accounting.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero_assets.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero_bankfeeds.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero_files.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-app-store.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-finance.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-identity.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-payroll-au.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-payroll-nz.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-payroll-uk.yaml
# docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v4.3.1 validate -i /local/xero-projects.yaml
# working-directory: ${{ github.workspace }}

# - name: Run linting
# run: |
# vacuum lint -d -e 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



# ****** Linting steps are disabled for now *******

- 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
uses: codex-/return-dispatch@v2
id: return_dispatch
with:
token: ${{ steps.get_access_token.outputs.result }}
repo: xeroapi-sdk-codegen
owner: xero-internal
workflow: pr.yml
ref: refs/heads/master
workflow_inputs: >
{
"branch_name": "${{ github.event_name == 'pull_request' && github.head_ref || 'master' }}"
}

- name: Checking SDK health status
uses: Codex-/[email protected]
with:
token: ${{ steps.get_access_token.outputs.result }}
repo: xeroapi-sdk-codegen
owner: xero-internal
run_id: ${{ steps.return_dispatch.outputs.run_id }}

166 changes: 166 additions & 0 deletions .github/workflows/update-OAS-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
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 "[email protected]"

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: Auto Merge PR & delete branch
run: |

if [ -z "${{steps.identify_PR_number.outputs.PR_NUMBER}}" ]; then
echo "No PR found for branch: ${{steps.identify_branch_name.outputs.branchName}}"
exit 1
fi

echo "Merging the PR: ${{steps.identify_PR_number.outputs.PR_NUMBER}}....."

gh pr merge ${{steps.identify_PR_number.outputs.PR_NUMBER}} --merge --admin --delete-branch --repo ${{github.repository}}

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}}
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,54 @@ In Release (used for one or more SDKs)
* [Payroll NZ](https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/master/xero-payroll-nz.yaml)
* [Files](https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/master/xero_files.yaml)


## Contribution guide

:loudspeaker: Announcement for all active contributors for Xero-OpenAPI repo :loudspeaker:

We have enabled [commit linting](https://github.com/conventional-changelog/commitlint/#what-is-commitlint) in this repo to ensure that all commit messages follow the conventional commits standards. Please make sure your commit messages are properly formatted or the PR checks will fail. :no_entry_sign:

You can refer to the [conventional commits documentation](https://www.conventionalcommits.org/en/v1.0.0/#summary) for better understanding.

**Context:**

We have automated the release process in xero-OpenAPI using [semantic-release package](https://github.com/semantic-release/semantic-release). In brief this package analyses all the commits in the repo to determine the next version number, generate the release notes and publish the package, hence the commit message is important for the release to happen successfully. Please read more on the conventional commit [documentation](https://www.conventionalcommits.org/en/v1.0.0/#summary) before landing your commits, each commit message will determine the release notes !


**Example:**

If your commit message is - ``feat: added a new parameter in the get_account method`` - It will do a **minor version update**.

Following release notes will be generated -

```
Release notes

Feature -
- added a new parameter in the get_account method
```

If your commit message is - ``fix: fixed the null issue with get_invoice method`` - It will do a **patch version update**.

Following release notes will be generated -

```
Release notes

Fix -
- fixed the null issue with get_invoice method
```


if your commit message is as below it will do a **major version update** (Breaking change)

```
chore!: drop support for Node 6

BREAKING CHANGE: use JavaScript features not available in Node 6
```


## Code Generators
We are using [OpenAPI generator](https://github.com/OpenAPITools/openapi-generator) along with these OAS yaml files to generate our new SDKs.

Expand Down
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional']
}
Loading
Loading