name: quickjs

on:
  pull_request:
  push:
    branches:
      - master
  schedule:
    # Prime the caches every Monday
    - cron: 0 1 * * MON

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
  cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
  quickjs:
    name: QuickJS-NG / Ubuntu / Tests
    runs-on: ubuntu-latest

    steps:
      - name: Update apt cache
        run: sudo apt-get update

      - name: Checkout tree
        uses: actions/checkout@v6

      - name: Set-up Node.js
        uses: actions/setup-node@v6
        with:
          node-version: latest

      - name: Set-up OCaml
        uses: ocaml/setup-ocaml@v3
        with:
          ocaml-compiler: "5.4.0"

      - name: Set-up Binaryen
        uses: Aandreba/setup-binaryen@v1.0.0
        with:
          token: ${{ github.token }}

      - name: Build and install QuickJS-NG
        run: |
          git clone --depth 1 https://github.com/quickjs-ng/quickjs.git "$RUNNER_TEMP/quickjs-ng"
          cd "$RUNNER_TEMP/quickjs-ng"
          cmake -B build -DCMAKE_BUILD_TYPE=Release
          cmake --build build -j --target qjs_exe
          sudo install -m 0755 build/qjs /usr/local/bin/qjs
          qjs --help | head -1

      - run: opam install . --deps-only --with-test

      - run: opam install .

      - run: opam exec -- make all

      - run: opam exec -- make tests-quickjs
