Skip to content

Commit 2653f3e

Browse files
committed
chore: fix CI/CD tasks and apply some basic hardening
1 parent 9d69ee2 commit 2653f3e

9 files changed

Lines changed: 200 additions & 19 deletions

File tree

.github/workflows/publish-typescript.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ jobs:
2626
node-version: "24"
2727
registry-url: "https://registry.npmjs.org"
2828

29+
- name: Configure npm release age gate
30+
run: echo "NPM_CONFIG_BEFORE=$(date -u -d '7 days ago' +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV"
31+
2932
- name: Install dependencies
3033
run: npm ci
3134

.github/workflows/validate.yml

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@ jobs:
1616
with:
1717
node-version: "20"
1818

19+
- name: Configure npm release age gate
20+
run: echo "NPM_CONFIG_BEFORE=$(date -u -d '7 days ago' +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV"
21+
22+
- name: Install validation dependencies
23+
run: npm ci
24+
1925
- name: Validate models YAML against schema
20-
run: |
21-
npm install ajv ajv-cli
22-
npx ajv validate \
23-
-s model-metadata.schema.json \
24-
-d "models/*.yaml" \
25-
--spec=draft2020 \
26-
--all-errors || exit 1
26+
run: npm run validate:models
2727

2828
- name: Validate providers YAML against schema
29-
run: |
30-
npx ajv validate \
31-
-s provider.schema.json \
32-
-d "providers/*.yaml" \
33-
--spec=draft2020 \
34-
--all-errors || exit 1
29+
run: npm run validate:providers
3530

3631
codegen:
3732
runs-on: ubuntu-latest
@@ -48,7 +43,7 @@ jobs:
4843
- name: Check for changes
4944
run: |
5045
git diff --exit-code packages/typescript/src/generated/
51-
git diff --exit-code packages/python/model_metadata/generated/
46+
git diff --exit-code packages/python/model_metadata_central/generated/
5247
5348
typescript:
5449
runs-on: ubuntu-latest
@@ -63,6 +58,9 @@ jobs:
6358
node-version: "20"
6459
registry-url: "https://registry.npmjs.org"
6560

61+
- name: Configure npm release age gate
62+
run: echo "NPM_CONFIG_BEFORE=$(date -u -d '7 days ago' +'%Y-%m-%dT%H:%M:%SZ')" >> "$GITHUB_ENV"
63+
6664
- name: Install deps and type-check
6765
run: npm ci && npm run lint
6866

@@ -81,15 +79,15 @@ jobs:
8179
python-version: "3.10"
8280

8381
- name: Install dependencies
84-
run: uv sync
82+
run: uv sync --locked
8583

8684
- name: Build registry from YAML sources
8785
run: uv run python scripts/build_registry.py
8886

8987
- name: Type-check generated models
9088
run: |
9189
uv run python -c "
92-
from model_metadata.generated.models import ModelMetadata, ProviderMetadata
90+
from model_metadata_central.generated.models import ModelMetadata, ProviderMetadata
9391
m = ModelMetadata.model_validate({
9492
'model_id': 'test',
9593
'model_type': 'chat',
@@ -103,4 +101,4 @@ jobs:
103101
'routing_priority': 'direct'
104102
})
105103
print('ProviderMetadata valid:', p.provider_id)
106-
"
104+
"

.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
min-release-age=7
2+
save-exact=true

package-lock.json

Lines changed: 111 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
{
22
"name": "model-metadata-central",
33
"private": true,
4+
"packageManager": "npm@11.16.0",
5+
"engines": {
6+
"node": ">=20",
7+
"npm": ">=11.16.0"
8+
},
49
"scripts": {
5-
"generate": "node scripts/codegen.mjs"
10+
"generate": "node scripts/codegen.mjs",
11+
"validate:models": "node scripts/validate-yaml-schema.mjs model-metadata.schema.json models",
12+
"validate:providers": "node scripts/validate-yaml-schema.mjs provider.schema.json providers"
13+
},
14+
"devDependencies": {
15+
"ajv": "8.20.0",
16+
"ajv-formats": "3.0.1",
17+
"yaml": "3.0.0-0"
618
}
7-
}
19+
}

packages/typescript/.npmrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
min-release-age=7
2+
save-exact=true

packages/typescript/package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/typescript/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"type": "module",
1111
"main": "./dist/index.js",
1212
"types": "./dist/index.d.ts",
13+
"engines": {
14+
"node": ">=20"
15+
},
1316
"exports": {
1417
".": {
1518
"import": "./dist/index.js",

scripts/validate-yaml-schema.mjs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
import process from "node:process";
4+
import Ajv2020 from "ajv/dist/2020.js";
5+
import addFormats from "ajv-formats";
6+
import { parse } from "yaml";
7+
8+
const [schemaPath, dataDir] = process.argv.slice(2);
9+
10+
if (!schemaPath || !dataDir) {
11+
console.error("Usage: node scripts/validate-yaml-schema.mjs <schema.json> <data-dir>");
12+
process.exit(2);
13+
}
14+
15+
const schema = JSON.parse(fs.readFileSync(schemaPath, "utf8"));
16+
const ajv = new Ajv2020({ allErrors: true });
17+
addFormats(ajv);
18+
19+
const validate = ajv.compile(schema);
20+
const yamlFiles = fs
21+
.readdirSync(dataDir)
22+
.filter((file) => file.endsWith(".yaml") || file.endsWith(".yml"))
23+
.sort();
24+
25+
let hasErrors = false;
26+
27+
for (const file of yamlFiles) {
28+
const filePath = path.join(dataDir, file);
29+
const data = parse(fs.readFileSync(filePath, "utf8"));
30+
31+
if (validate(data)) {
32+
console.log(`${filePath} valid`);
33+
continue;
34+
}
35+
36+
hasErrors = true;
37+
console.error(`${filePath} invalid`);
38+
39+
for (const error of validate.errors ?? []) {
40+
const location = error.instancePath || "/";
41+
console.error(` ${location} ${error.message}`);
42+
}
43+
}
44+
45+
if (hasErrors) {
46+
process.exit(1);
47+
}

0 commit comments

Comments
 (0)