// oxygenhub-vscode's pipeline (OxygenFlow, docs in the oxygenflow repository):
// typecheck, bundle, tests and packaging, offline in a Firecracker microVM on
// Earth for every push. The hub client tests need a hub binary and skip here.
schema-version 1

// The OxygenFlow build image (oxygenflow/images/rust), with an npm cache of
// this repository's package-lock.json. Rebuild and re-pin it when that changes.
sandbox "node" {
    runtime "microvm"
    rootfs "cas://blob/e52c41a173956b6bacc270eb81208a1b118b652412b84d15fa24708e6f8ec392"
    memory-limit "2GiB"
    cpu-limit 2
    network "loopback"
}

job "check" {
    sandbox "node"
    exec "sh" "-euc" "npm ci --offline --cache /opt/npm-cache --no-audit --no-fund && npm run typecheck && npm run build && npm run test:ci"
    // A JUnit report (kept whether or not the tests pass) and line coverage
    // of src/ through esbuild's source maps, for the hub's Tests and
    // Coverage tabs.
    output {
        artifact "junit" {
            path "/src/out/junit.xml"
            when "always"
        }
        artifact "coverage" {
            path "/src/out/lcov.info"
        }
    }
}

job "package" {
    sandbox "node"
    depends-on "check"
    // A fresh workspace: nothing from check carries over, so build first.
    exec "sh" "-euc" "npm ci --offline --cache /opt/npm-cache --no-audit --no-fund && npm run build && npm run package"
}
