on:
  push:
    branches:
      - main
  pull_request: {}

name: Test

jobs:
  build_and_test:
    name: Test
    runs-on: ubuntu-latest
    permissions:
      checks: write
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4

      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: yarn

      - uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: nightly
          components: clippy

      - uses: Swatinem/rust-cache@v2

      - run: cargo test
      - run: cargo run --bin cr calcit/editor/compact.cirru --once
      - run: cargo run --bin cr calcit/test.cirru --once

      - uses: giraffate/clippy-action@v1
        with:
          reporter: 'github-pr-review'
          github_token: ${{ secrets.GITHUB_TOKEN }}

      - name: "try js"
        run: >
          yarn
          && yarn tsc
          && cargo run --bin cr calcit/test.cirru --once js
          && ln -s ../../ node_modules/@calcit/procs
          && cp -v scripts/main.mjs js-out/
          && node js-out/main.mjs
