Skip to content

Commit 0240432

Browse files
committed
add linter
1 parent 9d71fbc commit 0240432

File tree

5 files changed

+63
-15
lines changed

5 files changed

+63
-15
lines changed

.github/testing/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"lint": "gts lint",
99
"fix": "gts fix",
1010
"affected": "bun run ./src/main.ts affected",
11+
"linter": "bun run ./src/main.ts linter",
1112
"tests": "bun run ./src/main.ts tests"
1213
},
1314
"dependencies": {

.github/testing/src/config.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
import * as fs from 'node:fs';
1616
import * as git from './git';
1717
import * as path from 'path';
18-
import {List, Map, Set} from 'immutable';
19-
import {minimatch} from 'minimatch'; /* eslint-disable @typescript-eslint/no-explicit-any */
20-
import {Affected, TestAll, TestName, TestPath, mergeAffected} from './affected';
18+
import { List, Map, Set } from 'immutable';
19+
import { minimatch } from 'minimatch'; /* eslint-disable @typescript-eslint/no-explicit-any */
20+
import { Affected, TestAll, TestName, TestPath, mergeAffected } from './affected';
2121

22-
type RunTestsAll = {
22+
type Args = {
2323
root: string;
2424
path: string;
2525
};
2626

27-
type RunTestsSome = {
27+
type ArgsTestSome = {
2828
root: string;
2929
path: string;
3030
tests: Map<TestPath, Set<TestName>>;
@@ -36,27 +36,31 @@ export class Config {
3636
match: List<string>;
3737
ignore: List<string>;
3838
packageFile: List<string>;
39-
testAll: (_: RunTestsAll) => void;
40-
testSome: (_: RunTestsSome) => void;
39+
_lint: (_: Args) => void;
40+
_testAll: (_: Args) => void;
41+
_testSome: (_: ArgsTestSome) => void;
4142

4243
constructor({
4344
match,
4445
ignore,
4546
packageFile,
47+
lint,
4648
testAll,
4749
testSome,
4850
}: {
4951
match?: string[];
5052
ignore?: string[];
5153
packageFile?: string[];
52-
testAll?: (_: RunTestsAll) => void;
53-
testSome?: (_: RunTestsSome) => void;
54+
lint?: (_: Args) => void;
55+
testAll?: (_: Args) => void;
56+
testSome?: (_: ArgsTestSome) => void;
5457
}) {
5558
this.match = List(match || ['**']);
5659
this.ignore = List(ignore);
5760
this.packageFile = List(packageFile);
58-
this.testAll = testAll || (_ => {});
59-
this.testSome = testSome || (_ => {});
61+
this._lint = lint || (_ => { });
62+
this._testAll = testAll || (_ => { });
63+
this._testSome = testSome || (_ => { });
6064
}
6165

6266
affected = (head: string, main: string): List<Affected> =>
@@ -71,17 +75,27 @@ export class Config {
7175
.values()
7276
);
7377

78+
lint = (affected: Affected) => {
79+
const cwd = process.cwd();
80+
const root = git.root();
81+
const dir = path.join(root, affected.path);
82+
console.log(`> cd ${dir}`);
83+
process.chdir(dir);
84+
this._lint({ root: root, path: affected.path });
85+
process.chdir(cwd);
86+
};
87+
7488
test = (affected: Affected) => {
7589
const cwd = process.cwd();
7690
const root = git.root();
7791
const dir = path.join(root, affected.path);
7892
console.log(`> cd ${dir}`);
7993
process.chdir(dir);
8094
if ('TestAll' in affected) {
81-
this.testAll({root: root, path: affected.path});
95+
this._testAll({ root: root, path: affected.path });
8296
}
8397
if ('TestSome' in affected) {
84-
this.testSome({
98+
this._testSome({
8599
root: root,
86100
path: affected.path,
87101
tests: affected.TestSome,

.github/testing/src/config/python.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import * as path from 'path';
1616
import * as subprocess from '../subprocess';
17-
import {Config} from '../config';
17+
import { Config } from '../config';
1818

1919
export const python = (version = '3.11') =>
2020
new Config({
@@ -27,6 +27,11 @@ export const python = (version = '3.11') =>
2727
'setup.py',
2828
'setup.cfg',
2929
],
30+
lint: args => {
31+
const noxfile = path.join(args.root, 'noxfile-template.py');
32+
subprocess.run('cp', [noxfile, 'noxfile.py']);
33+
subprocess.run('nox', ['-s', 'lint']);
34+
},
3035
testAll: args => {
3136
const noxfile = path.join(args.root, 'noxfile-template.py');
3237
subprocess.run('cp', [noxfile, 'noxfile.py']);

.github/testing/src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ function main(command: string) {
4444
console.log(JSON.stringify(affected));
4545
return;
4646
}
47+
case 'linter': {
48+
const config = getConfig(process.argv[3]);
49+
const affected: Affected = JSON.parse(process.env[process.argv[4]] || '');
50+
config.lint(affected);
51+
return;
52+
}
4753
case 'tests': {
4854
const config = getConfig(process.argv[3]);
4955
const affected: Affected = JSON.parse(process.env[process.argv[4]] || '');

.github/workflows/test.yaml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,30 @@ jobs:
4545
echo "$AFFECTED_PYTHON"
4646
echo "affected=$AFFECTED_PYTHON" >> "$GITHUB_OUTPUT"
4747
48+
python-lint:
49+
name: Lint Python
50+
needs: affected
51+
runs-on: ubuntu-latest
52+
strategy:
53+
matrix:
54+
affected: ${{fromJson(needs.affected.outputs.python)}}
55+
defaults:
56+
run:
57+
working-directory: .github/testing
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: oven-sh/setup-bun@v2
61+
- uses: actions/setup-python@v5
62+
with:
63+
python-version: '3.12'
64+
- run: pip install nox
65+
- run: bun install
66+
- run: bun run linter python AFFECTED
67+
env:
68+
AFFECTED: ${{toJson(matrix.affected)}}
69+
4870
python-test:
49-
name: Test Python ${{matrix.python-version}}
71+
name: Test Python
5072
needs: affected
5173
runs-on: ubuntu-latest
5274
strategy:

0 commit comments

Comments
 (0)