Skip to content

[PETOSS-829] Add codegen testing and replace linters #1

[PETOSS-829] Add codegen testing and replace linters

[PETOSS-829] Add codegen testing and replace linters #1

Workflow file for this run

name: PR Validation
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- master
jobs:
validation:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
- name: Install commitlint dependencies
working-directory: .github/commitlint
run: npm ci
- name: Install Spectral dependencies
working-directory: .github/spectral
run: npm ci
- name: Run commitlint
working-directory: .github/commitlint
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
- name: Run Spectral (OpenAPI linting)
working-directory: .github/spectral
run: npm run lint
yaml-validation:
runs-on: ubuntu-latest
steps:
- name: YAML Lint
uses: ibiqlik/action-yamllint@v3
with:
file_or_dir: xero_accounting.yaml xero_assets.yaml xero_bankfeeds.yaml xero_files.yaml xero-app-store.yaml xero-identity.yaml xero-payroll-au.yaml xero-payroll-nz.yaml xero-payroll-uk.yaml xero-projects.yaml xero-webhooks.yaml
config_data: |
extends: default
rules:
line-length:
level: warning
trailing-spaces:
level: warning
indentation:
level: warning
colons:
level: warning
commas:
level: warning
new-line-at-end-of-file:
level: warning
codegen-validation:
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 get-access-token dependencies
run: npm ci
working-directory: ${{ github.workspace }}/.github/get-access-token
- 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/get-access-token/index.js')
const token = await getAccessToken()
return token
- name: Trigger validation workflow in codegen repo
id: codegen_workflow
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: Check status of codegen validation workflow
uses: Codex-/[email protected]
with:
token: ${{ steps.get_access_token.outputs.result }}
repo: xeroapi-sdk-codegen
owner: xero-internal
run_id: ${{ steps.codegen_workflow.outputs.run_id }}
run_timeout_seconds: 420 # 7 minutes