name: OMNL reconcile anchor

on:
  workflow_dispatch:
  schedule:
    # Weekly Monday 07:05 UTC — adjust as needed
    - cron: '5 7 * * 1'
  pull_request:
    branches: [main, develop]
    paths:
      - 'config/omnl-ipsas-gl-registry.json'
      - 'config/omnl-journal-matrix.json'
      - 'config/deployment-omnl.example.env'
      - 'services/token-aggregation/scripts/omnl-reconcile-report.mjs'
      - 'services/token-aggregation/package.json'
      - 'scripts/hybx-omnl/omnl-reconcile-artifact.sh'
      - '.github/workflows/omnl-reconcile.yml'
      - '.github/workflows/hybx-omnl-ts.yml'
  push:
    branches: [main, develop]
    paths:
      - 'config/omnl-ipsas-gl-registry.json'
      - 'config/omnl-journal-matrix.json'
      - 'config/deployment-omnl.example.env'
      - 'services/token-aggregation/scripts/omnl-reconcile-report.mjs'
      - 'services/token-aggregation/package.json'
      - 'scripts/hybx-omnl/omnl-reconcile-artifact.sh'
      - '.github/workflows/omnl-reconcile.yml'
      - '.github/workflows/hybx-omnl-ts.yml'

permissions:
  contents: read

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

jobs:
  reconcile:
    name: Run omnl:reconcile and upload artifacts
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

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

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '20'

      - name: Generate reconcile artifacts
        env:
          GITHUB_SHA: ${{ github.sha }}
          GITHUB_RUN_ID: ${{ github.run_id }}
          GITHUB_REPOSITORY: ${{ github.repository }}
        run: bash scripts/hybx-omnl/omnl-reconcile-artifact.sh

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