Skip to content

Commit e2a81d2

Browse files
committed
add test and use multiple ci scripts
1 parent 50238e0 commit e2a81d2

File tree

6 files changed

+138
-45
lines changed

6 files changed

+138
-45
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/deploy.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@ on:
88
required: true
99
default: "dev"
1010
type: string
11-
# workflow_run:
12-
# workflows: ["ci"]
13-
# types:
14-
# - completed
15-
# branches:
16-
# - dev
1711

1812
concurrency: ${{ github.workflow }}-${{ github.ref }}
1913

@@ -30,7 +24,7 @@ jobs:
3024
bun-version: latest
3125

3226
- name: Install dependencies
33-
run: bun install --frozen-lockfile
27+
run: bun install
3428

3529
- run: bun sst deploy --stage=${{ inputs.stage }}
3630
env:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: license-check
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- dev
8+
pull_request:
9+
branches:
10+
- dev
11+
12+
jobs:
13+
license-check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup Bun
19+
uses: oven-sh/setup-bun@v1
20+
21+
- name: Install dependencies
22+
run: bun install --frozen-lockfile
23+
24+
- name: Audit licenses
25+
run: bun run script/license-check.ts

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: test
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- dev
8+
pull_request:
9+
branches:
10+
- dev
11+
12+
jobs:
13+
license-check:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Setup Bun
19+
uses: oven-sh/setup-bun@v1
20+
21+
- name: Install dependencies
22+
run: bun install --frozen-lockfile
23+
24+
- name: Test
25+
run: bun run test

.github/workflows/validate.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: validate
2+
on:
3+
pull_request:
4+
branches:
5+
- dev
6+
push:
7+
branches:
8+
- dev
9+
workflow_dispatch:
10+
11+
jobs:
12+
validate:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Setup Bun
20+
uses: oven-sh/setup-bun@v1
21+
with:
22+
bun-version: latest
23+
24+
- name: Install dependencies
25+
run: bun install
26+
27+
- name: Run validation script
28+
run: script/validate.ts

script/license-check.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bun
2+
3+
/*
4+
* A tighter license-audit helper that:
5+
* 1. Runs license-checker in JSON mode (production deps only).
6+
* 2. Fails the script (exit 1) if any package’s license isn’t in the allow-list.
7+
*
8+
* The allow-list can be overridden via the ALLOWED_LICENSES env var
9+
* (semicolon-delimited SPDX identifiers).
10+
*/
11+
12+
import { $ } from "bun";
13+
14+
const DEFAULT_ALLOW = [
15+
"MIT",
16+
"Apache-2.0",
17+
"ISC",
18+
"BSD-2-Clause",
19+
"BSD-3-Clause",
20+
];
21+
22+
const allowList = new Set(
23+
(process.env.ALLOWED_LICENSES ?? DEFAULT_ALLOW.join(";")).split(/\s*;\s*/)
24+
);
25+
26+
const { stdout } = await $`bunx license-checker --json --production`;
27+
const jsonStr = stdout.toString();
28+
interface LicenseInfo {
29+
licenses: string | string[];
30+
}
31+
32+
const parsed: Record<string, LicenseInfo> = JSON.parse(jsonStr);
33+
34+
const violations: Array<{ pkg: string; license: string | string[] }> = [];
35+
36+
for (const [pkg, info] of Object.entries(parsed)) {
37+
const licArray = Array.isArray(info.licenses)
38+
? info.licenses
39+
: [info.licenses];
40+
const bad = licArray.filter((l) => {
41+
if (/UNKNOWN/.test(l)) {
42+
console.warn(` • ${pkg}${l}`);
43+
return false;
44+
}
45+
return !allowList.has(l);
46+
});
47+
if (bad.length) violations.push({ pkg, license: bad.join(", ") });
48+
}
49+
50+
if (violations.length) {
51+
console.error("\n🚫 Disallowed licenses found:\n");
52+
for (const v of violations) {
53+
console.error(` • ${v.pkg}${v.license}`);
54+
}
55+
console.error("\n✖ License audit failed\n");
56+
process.exit(1);
57+
}
58+
59+
console.log("✅ License audit passed");

0 commit comments

Comments
 (0)