Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(TypeScript): Add the workflow file for CI check #1280

Merged
merged 18 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/typescript.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: TypeScript

on:
push:
branches: ['main']
paths: ['codes/typescript/**/*.ts']
pull_request:
branches: ['main']
paths: ['codes/typescript/**/*.ts']
workflow_dispatch:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20.x
- uses: denoland/setup-deno@v1
with:
deno-version: v1.x
- name: Install TypeScript Execute (tsx)
run: npm install tsx --global
- name: Test typescript code
run: deno run -A codes/typescript/test_all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { TreeNode } from '../modules/TreeNode';
import { printTree } from '../modules/PrintUtil';

/* 函数 */
function constFunc(): number {
function constFunc(): numer {
// 执行某些操作
return 0;
}
Expand Down
40 changes: 40 additions & 0 deletions codes/typescript/test_all.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expandGlob, type WalkEntry } from 'jsr:@std/fs';
import { relative } from 'jsr:@std/path';

const entries = [] as WalkEntry[];

for await (const entry of expandGlob('codes/typescript/chapter_*/*.ts')) {
entries.push(entry);
}

const errors = [] as ReadableStream<Uint8Array>[];

for (const file of entries) {
const command = new Deno.Command('tsx', {
args: [relative(import.meta.dirname!, file.path)],
cwd: import.meta.dirname,
stdin: 'piped',
stdout: 'piped',
stderr: 'piped',
});

const process = command.spawn();
const { success } = await process.status;
if (!success) errors.push(process.stderr);
}

console.log(`Tested ${entries.length} files`);
console.log(`Found exception in ${errors.length} files`);

if (errors.length) {
console.log();

for (const error of errors) {
const reader = error.getReader();
const { value } = await reader.read();
const decoder = new TextDecoder();
console.error(decoder.decode(value));
}

throw new Error('Test failed');
}