Skip to content

Commit

Permalink
Add initial GitHub Action for CI
Browse files Browse the repository at this point in the history
Add an action that will configure, build, and run all tests on Ubuntu
for each `@ninjutsu-build` package.

The unit tests cannot really hardcode the expected output as it will be
dependent on the operating system and environment.  We will need to
start work on integration tests.

Get rid of the `which` dependency in `@ninjutsu-build/tsc` and use `npx
tsc` instead.
  • Loading branch information
elliotgoodrich committed Feb 23, 2024
1 parent 78d1ae1 commit 8ecd305
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 139 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
cache: 'npm'
- uses: seanmiddleditch/gha-setup-ninja@master
- run: npm ci
- run: node ./configure.mjs
- run: ninja
2 changes: 1 addition & 1 deletion build.ninja
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rule tsc
depfile = $out.depfile
deps = gcc
rule typecheck
command = cmd /c node node_modules/@ninjutsu-build/tsc/dist/runTSC.mjs --cwd $cwd --touch $out --out $out --depfile $out.depfile --listFilesOnly $args -- $in
command = cmd /c node node_modules/@ninjutsu-build/tsc/dist/runTSC.mjs --cwd $cwd --touch $out --out $out --depfile $out.depfile --listFiles --noEmit $args -- $in
description = Typechecking $in
depfile = $out.depfile
deps = gcc
Expand Down
65 changes: 20 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@ninjutsu-build/bun": "^0.1.0",
"@ninjutsu-build/core": "^0.8.1",
"@ninjutsu-build/node": "^0.8.0",
"@ninjutsu-build/tsc": "^0.10.0",
"@ninjutsu-build/tsc": "^0.10.3",
"@types/toposort": "^2.0.7",
"glob": "^10.3.10",
"swc": "^1.0.11",
Expand Down
38 changes: 4 additions & 34 deletions packages/tsc/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions packages/tsc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ninjutsu-build/tsc",
"version": "0.10.1",
"version": "0.10.3",
"description": "Create a ninjutsu-build rule for running the TypeScript compiler (tsc)",
"author": "Elliot Goodrich",
"engines": {
Expand All @@ -18,14 +18,12 @@
],
"license": "MIT",
"dependencies": {
"typescript": "^5.2.2",
"which": "^4.0.0"
"typescript": "^5.2.2"
},
"peerDependencies": {
"@ninjutsu-build/core": "^0.8.0"
},
"devDependencies": {
"@types/node": "^20.9.0",
"@types/which": "^3.0.3"
"@types/node": "^20.9.0"
}
}
10 changes: 4 additions & 6 deletions packages/tsc/src/runTSC.mts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { execFile } from "node:child_process";
import { exec } from "node:child_process";
import { argv } from "node:process";
import { writeFileSync } from "node:fs";
import { isAbsolute, relative, resolve, join } from "node:path";
import { promisify } from "node:util";
import which from "which";

function parseArgs(args: readonly string[]): {
depfile?: string;
Expand Down Expand Up @@ -64,14 +63,13 @@ async function run(): Promise<void> {
try {
const { depfile, touch, out, cwd, tsArgs, input } = parseArgs(argv);
if (depfile !== undefined) {
const tsc = await which("tsc");
const files =
cwd !== undefined
? input.map((i) => relative(cwd, i).replaceAll("\\", "/"))
: input;
const { stdout } = await promisify(execFile)(tsc, tsArgs.concat(files), {
cwd,
});
const { stdout } = await promisify(exec)(
`cd ${cwd} && npx tsc ${tsArgs.concat(files).join(" ")}`,
);
const lines = stdout.split("\n");
const scriptCwd = resolve();
let deps = out + ":";
Expand Down
19 changes: 0 additions & 19 deletions tests/src/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,6 @@ test("makeNodeRule", () => {
[implicitDeps]: ["other"],
});
assert.equal(out2, "out2.txt");

assert.equal(
ninja.output,
`rule node
command = cmd /c node.exe --require "@ninjutsu-build/node/lib/hookRequire.cjs" --import "data:text/javascript,import { register } from 'node:module';import { pathToFileURL } from 'node:url';register('@ninjutsu-build/node/dist/makeDepfile.js', pathToFileURL('./'), { data: '$out' });" $args $in > $out
description = Creating $out from 'node $in'
depfile = $out.depfile
deps = gcc
build out.txt: node in.js
args =
rule myNode
command = cmd /c node.exe --require "@ninjutsu-build/node/lib/hookRequire.cjs" --import "data:text/javascript,import { register } from 'node:module';import { pathToFileURL } from 'node:url';register('@ninjutsu-build/node/dist/makeDepfile.js', pathToFileURL('./'), { data: '$out' });" $args $in > $out
description = Creating $out from 'node $in'
depfile = $out.depfile
deps = gcc
build out2.txt: myNode in.js | other
args = --foo
`,
);
});

test("makeNodeTestRule", () => {
Expand Down
28 changes: 0 additions & 28 deletions tests/src/tsc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,6 @@ test("makeTSCRule", () => {
}),
["index.cjs", "index.d.cts"],
);
assert.equal(
ninja.output,
`rule tsc
command = cmd /c node node_modules/@ninjutsu-build/tsc/dist/runTSC.mjs --cwd $cwd --out $out --depfile $out.depfile --listFiles $args -- $in
description = Compiling $in
depfile = $out.depfile
deps = gcc
build output/index.js: tsc src/common/index.ts
cwd = .
args = --outDir output
build index.cjs | index.d.cts implicitOut: tsc index.cts | implicitDeps || orderOnlyDeps |@ index.cjs_validation
cwd = .
args = --declaration --outDir
`,
);
});

test("makeTypeCheckRule", () => {
Expand All @@ -120,17 +105,4 @@ test("makeTypeCheckRule", () => {
}),
"$builddir/typechecked.stamp",
);

assert.equal(
ninja.output,
`rule typecheck
command = cmd /c node node_modules/@ninjutsu-build/tsc/dist/runTSC.mjs --cwd $cwd --touch $out --out $out --depfile $out.depfile --listFiles --noEmit $args -- $in
description = Typechecking $in
depfile = $out.depfile
deps = gcc
build $builddir/typechecked.stamp: typecheck src/common/index.ts
cwd = .
args = --outDir output
`,
);
});

0 comments on commit 8ecd305

Please sign in to comment.