Skip to content

Commit 3e814a2

Browse files
committed
ci: attempting to use centralized CI in MatrixAI/.github
1 parent ff2437f commit 3e814a2

File tree

7 files changed

+149
-227
lines changed

7 files changed

+149
-227
lines changed

.github/workflows/ci.yaml

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

.github/workflows/feature.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: "CI / Feature"
2+
3+
on:
4+
push:
5+
branches:
6+
- feature*
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
use-library-js-feature:
15+
permissions:
16+
packages: read
17+
contents: read
18+
actions: write
19+
checks: write
20+
uses: MatrixAI/.github/.github/workflows/library-js-feature.yml@feature-workflows

.github/workflows/staging.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "CI / Staging"
2+
3+
on:
4+
push:
5+
branches:
6+
- staging
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.ref }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
use-library-js-staging:
15+
permissions:
16+
packages: read
17+
contents: read
18+
actions: write
19+
checks: write
20+
pull-requests: write
21+
uses: MatrixAI/.github/.github/workflows/library-js-staging.yml@feature-workflows

.github/workflows/tag.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "CI / Tag"
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
workflow_dispatch:
8+
9+
jobs:
10+
use-library-js-tag:
11+
permissions:
12+
packages: read
13+
contents: read
14+
actions: write
15+
uses: MatrixAI/.github/.github/workflows/library-js-tag.yml@feature-workflows

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ npm run build
2121
npm run tsx
2222
# run the tests
2323
npm run test
24-
# lint the source code
24+
# lint code, markdown, scripts
2525
npm run lint
26-
# automatically fix the source
26+
# automatically fix linting errors
2727
npm run lintfix
2828
```
2929

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@
3030
"postversion": "npm install --package-lock-only --ignore-scripts --silent",
3131
"tsx": "tsx",
3232
"test": "node ./scripts/test.mjs",
33-
"lint": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}'",
34-
"lintfix": "eslint '{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}' --fix",
35-
"lintcontent": "prettier --check ./README.md",
36-
"lintcontentfix": "prettier --write ./README.md",
37-
"lint-shell": "find ./src ./tests ./scripts -type f -regextype posix-extended -regex '.*\\.(sh)' -exec shellcheck {} +",
33+
"lint": "node ./scripts/lint.mjs",
34+
"lintfix": "node ./scripts/lint.mjs --fix",
3835
"docs": "shx rm -rf ./docs && typedoc --gitRevision master --tsconfig ./tsconfig.build.json --out ./docs src",
3936
"bench": "tsc -p ./tsconfig.build.json && shx rm -rf ./benches/results && tsx ./benches/index.ts"
4037
},

scripts/lint.mjs

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env node
2+
3+
import os from 'node:os';
4+
import path from 'node:path';
5+
import url from 'node:url';
6+
import process from 'node:process';
7+
import childProcess from 'node:child_process';
8+
9+
const projectPath = path.dirname(
10+
path.dirname(url.fileURLToPath(import.meta.url)),
11+
);
12+
13+
const platform = os.platform();
14+
15+
/* eslint-disable no-console */
16+
async function main(argv = process.argv) {
17+
argv = argv.slice(2);
18+
let fix = false;
19+
const restArgs = [];
20+
while (argv.length > 0) {
21+
const option = argv.shift();
22+
if (option === '--fix') {
23+
fix = true;
24+
argv.shift();
25+
} else {
26+
restArgs.push(option);
27+
}
28+
}
29+
// Linting code
30+
const eslintArgs = [
31+
'{src,tests,scripts,benches}/**/*.{js,mjs,ts,mts,jsx,tsx,json}',
32+
];
33+
if (fix) {
34+
eslintArgs.push('--fix');
35+
}
36+
console.error('Running eslint:');
37+
console.error(['eslint', ...eslintArgs].join(' '));
38+
childProcess.execFileSync('eslint', eslintArgs, {
39+
stdio: ['inherit', 'inherit', 'inherit'],
40+
windowsHide: true,
41+
encoding: 'utf-8',
42+
shell: platform === 'win32' ? true : false,
43+
cwd: projectPath,
44+
});
45+
// Linting shell scripts (this does not have auto-fixing)
46+
const shellCheckArgs = [
47+
'./src',
48+
'./tests',
49+
'./scripts',
50+
'-type',
51+
'f',
52+
'-regextype',
53+
'posix-extended',
54+
'-regex',
55+
'.*\\.(sh)',
56+
'-exec',
57+
'shellcheck',
58+
'{}',
59+
'+',
60+
];
61+
console.error('Running shellcheck:');
62+
console.error(['find', ...shellCheckArgs].join(' '));
63+
childProcess.execFileSync('find', shellCheckArgs, {
64+
stdio: ['inherit', 'inherit', 'inherit'],
65+
windowsHide: true,
66+
encoding: 'utf-8',
67+
shell: platform === 'win32' ? true : false,
68+
cwd: projectPath,
69+
});
70+
// Linting markdown
71+
const prettierArgs = [!fix ? '--check' : '--write', './README.md'];
72+
console.error('Running prettier:');
73+
console.error(['prettier', ...prettierArgs].join(' '));
74+
childProcess.execFileSync('prettier', prettierArgs, {
75+
stdio: ['inherit', 'inherit', 'inherit'],
76+
windowsHide: true,
77+
encoding: 'utf-8',
78+
shell: platform === 'win32' ? true : false,
79+
cwd: projectPath,
80+
});
81+
}
82+
/* eslint-enable no-console */
83+
84+
if (import.meta.url.startsWith('file:')) {
85+
const modulePath = url.fileURLToPath(import.meta.url);
86+
if (process.argv[1] === modulePath) {
87+
void main();
88+
}
89+
}

0 commit comments

Comments
 (0)