name: CI
on: push
jobs:
  build:
    runs-on: warp-integration-tests
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18'
      - uses: jetli/wasm-pack-action@v0.4.0
        with:
          version: 'latest'
      - name: Install modules
        run: yarn
      - name: Lint
        run: yarn lint
      - name: Build package
        run: yarn build
      - name: Run unit tests
        run: yarn test:unit
      - name: Run integration tests [basic]
        run: yarn test:integration:basic
      - name: Run integration tests [internal-writes]
        run: yarn test:integration:internal-writes
      - name: Run integration tests [wasm]
        run: yarn test:integration:wasm
      - name: Test example rust contracts
        run: yarn build:test:wasm
      - name: Trigger integration tests
        if: github.ref_name == 'main'
        run: >
          curl
          -X POST
          -H "Accept: application/vnd.github+json"
          -H "Authorization: Bearer ${{secrets.PAT_TRIGGER_INTEGRATION_TESTS}}"
          -H "X-GitHub-Api-Version: 2022-11-28"
          https://api.github.com/repos/warp-contracts/warp-integration-tests/dispatches
          -d '{"event_type":"sdk_push","client_payload":{"ref":"${{github.ref}}","sha":"${{github.sha}}"}}'
