# TypeScript build + IPSAS/journal anchor (no Forge — keeps PR feedback fast).
name: HYBX OMNL TypeScript & anchor

on:
  workflow_dispatch:
  pull_request:
    branches: [main, develop]
    paths:
      - 'contracts/hybx-omnl/**'
      - 'services/token-aggregation/**'
      - 'config/omnl-*.json'
      - 'config/hybx-omnl-*.json'
      - 'config/deployment-omnl.example.env'
      - 'scripts/hybx-omnl/**'
      - 'test/hybx-omnl/**'
      - '.github/workflows/hybx-omnl-ts.yml'
      - '.github/workflows/omnl-reconcile.yml'
  push:
    branches: [main, develop]
    paths:
      - 'contracts/hybx-omnl/**'
      - 'services/token-aggregation/**'
      - 'config/omnl-*.json'
      - 'config/hybx-omnl-*.json'
      - 'config/deployment-omnl.example.env'
      - 'scripts/hybx-omnl/**'
      - 'test/hybx-omnl/**'
      - '.github/workflows/hybx-omnl-ts.yml'
      - '.github/workflows/omnl-reconcile.yml'

permissions:
  contents: read

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  ts-and-anchor:
    name: token-aggregation build + reconcile artifact
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Validate cross-chain OMNL config
        run: node scripts/hybx-omnl/validate-cross-chain-config.mjs

      - uses: actions/setup-node@v4
        with:
          node-version: '20'
          cache: npm
          cache-dependency-path: services/token-aggregation/package-lock.json

      - name: Install token-aggregation dependencies
        working-directory: services/token-aggregation
        run: npm ci

      - name: OMNL reconcile artifact
        run: bash scripts/hybx-omnl/omnl-reconcile-artifact.sh

      - name: Build token-aggregation
        working-directory: services/token-aggregation
        run: npm run build

      - name: Upload reconcile artifacts
        uses: actions/upload-artifact@v4
        with:
          name: omnl-reconcile-pr-${{ github.run_id }}
          path: artifacts/omnl-reconcile/
          if-no-files-found: error
          retention-days: 14
