Skip to content

Commit 726f867

Browse files
committed
pass more information and copy noxfile
1 parent 940668b commit 726f867

File tree

4 files changed

+38
-22
lines changed

4 files changed

+38
-22
lines changed

.github/testing/src/config.ts

+28-14
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,27 @@
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';
21+
22+
type RunTestsAll = {
23+
root: string
24+
path: string
25+
}
26+
27+
type RunTestsSome = {
28+
root: string
29+
path: string
30+
tests: Map<TestPath, Set<TestName>>;
31+
}
2132

2233
export class Config {
2334
match: List<string>;
2435
ignore: List<string>;
2536
packageFile: List<string>;
26-
testAll: () => void;
27-
testSome: (tests: Map<TestPath, Set<TestName>>) => void;
37+
testAll: (_: RunTestsAll) => void;
38+
testSome: (_: RunTestsSome) => void;
2839

2940
constructor({
3041
match,
@@ -36,16 +47,14 @@ export class Config {
3647
match?: string[];
3748
ignore?: string[];
3849
packageFile?: string[];
39-
testAll?: () => void;
40-
testSome?: (tests: Map<TestPath, Set<TestName>>) => void;
50+
testAll?: (_: RunTestsAll) => void;
51+
testSome?: (_: RunTestsSome) => void;
4152
}) {
4253
this.match = List(match || ['**']);
4354
this.ignore = List(ignore);
4455
this.packageFile = List(packageFile);
45-
this.testAll = testAll || (() => {});
46-
this.testSome =
47-
testSome ||
48-
(_ => {}); /* eslint-disable @typescript-eslint/no-unused-vars */
56+
this.testAll = testAll || (_ => { });
57+
this.testSome = testSome || (_ => { });
4958
}
5059

5160
affected = (head: string, main: string): List<Affected> =>
@@ -61,14 +70,19 @@ export class Config {
6170

6271
test = (affected: Affected) => {
6372
const cwd = process.cwd();
64-
const dir = path.join(git.root(), affected.path);
73+
const root = git.root();
74+
const dir = path.join(root, affected.path);
6575
console.log(`>> cd ${dir}`);
6676
process.chdir(dir);
6777
if ('TestAll' in affected) {
68-
this.testAll();
78+
this.testAll({ root: root, path: affected.path });
6979
}
7080
if ('TestSome' in affected) {
71-
this.testSome(affected.TestSome);
81+
this.testSome({
82+
root: root,
83+
path: affected.path,
84+
tests: affected.TestSome,
85+
});
7286
}
7387
process.chdir(cwd);
7488
};

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import * as path from 'path'
1516
import * as subprocess from '../subprocess';
16-
import {Config} from '../config';
17+
import { Config } from '../config';
1718

1819
export const python = new Config({
1920
match: ['**'],
@@ -25,10 +26,12 @@ export const python = new Config({
2526
'setup.py',
2627
'setup.cfg',
2728
],
28-
testAll: () => {
29+
testAll: args => {
30+
subprocess.run('cp', [path.join(args.root, 'noxfile-template.py'), 'noxfile.py'])
2931
subprocess.run('nox', ['-s', 'py-3.11']);
3032
},
31-
testSome: tests => {
32-
throw `TODO: config/python.ts testSome ${JSON.stringify(tests)}`;
33+
testSome: args => {
34+
subprocess.run('cp', [path.join(args.root, 'noxfile-template.py'), 'noxfile.py'])
35+
throw `TODO: config/python.ts testSome ${JSON.stringify(args)}`;
3336
},
3437
});

.github/testing/src/git.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { List } from 'immutable';
15+
import {List} from 'immutable';
1616
import * as subprocess from './subprocess';
1717

1818
export type Diff = {

.github/testing/src/subprocess.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import { spawnSync } from 'child_process';
15+
import {spawnSync} from 'child_process';
1616

1717
export function run(cmd: string, args: string[]) {
18-
const p = spawnSync(cmd, args, { stdio: 'inherit' });
18+
const p = spawnSync(cmd, args, {stdio: 'inherit'});
1919
process.exitCode = p.status || undefined;
2020
}
2121

@@ -24,4 +24,3 @@ export function output(cmd: string, args: string[]): string {
2424
process.exitCode = p.status || undefined;
2525
return p.stdout.toString().trim();
2626
}
27-

0 commit comments

Comments
 (0)