Skip to content

Commit 9f5e8b8

Browse files
committed
Merge commit '8405f6cbc4edc432b7215f04acae9f40d117436a' into workspaces-fix
# Conflicts: # .github/actions/src/gitRoot.ts # .github/actions/src/info/__tests__/index.test.ts # .github/actions/src/info/index.ts
2 parents 72f3f0a + 8405f6c commit 9f5e8b8

File tree

22 files changed

+428
-77
lines changed

22 files changed

+428
-77
lines changed

.github/actions/src/gitRoot.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { getExecOutput } from '@actions/exec';
22

33
// Not using the repotools version since this uses @action/exec instead of
44
// calling execFile from child_process
5-
export async function getGitRoot() {
5+
async function getGitRoot() {
66
const { stdout } = await getExecOutput('git rev-parse --show-toplevel');
77
return stdout.trim();
88
}

.github/actions/src/info/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function getRawPackages(gitRoot: string, maxDepth?: number) {
4343

4444
output[packageJson.name] = {
4545
directory: currentDir,
46-
hasChanges: hasChanges || packagesWithResolutionChanges.includes(packageJson.name),
46+
hasChanges: packagesWithResolutionChanges?.includes(packageJson.name) ?? hasChanges,
4747
package: packageJson
4848
};
4949
} catch (error) {
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import type fs from 'fs/promises';
2+
import type pathlib from 'path';
3+
import * as exec from '@actions/exec';
4+
import { describe, expect, it, vi } from 'vitest';
5+
import * as utils from '../utils.js';
6+
7+
vi.mock(import('../../gitRoot.js'), () => ({
8+
gitRoot: 'root'
9+
}));
10+
11+
const mockedExec = vi.spyOn(exec, 'getExecOutput');
12+
13+
describe(utils.extractPackageName, () => {
14+
it('works with packages that start with @', () => {
15+
expect(utils.extractPackageName('@sourceacademy/tab-Rune@workspace:^'))
16+
.toEqual('@sourceacademy/tab-Rune');
17+
});
18+
19+
it('works with regular package names', () => {
20+
expect(utils.extractPackageName('lodash@npm:^4.17.20'))
21+
.toEqual('lodash');
22+
});
23+
24+
it('throws an error on an invalid package name', () => {
25+
expect(() => utils.extractPackageName('something weird'))
26+
.toThrowError('Invalid package name: something weird');
27+
});
28+
});
29+
30+
describe(utils.getPackageReason, async () => {
31+
const { join }: typeof pathlib = await vi.importActual('path');
32+
const { readFile }: typeof fs = await vi.importActual('fs/promises');
33+
34+
const textPath = join(import.meta.dirname, 'sample_why.txt');
35+
const sampleText = await readFile(textPath, 'utf-8');
36+
37+
it('works', async () => {
38+
mockedExec.mockResolvedValueOnce({
39+
stdout: sampleText,
40+
stderr: '',
41+
exitCode: 0
42+
});
43+
44+
const retValue = await utils.getPackageReason('lodash');
45+
expect(retValue).toMatchInlineSnapshot(`
46+
[
47+
"@sourceacademy/bundle-ar",
48+
"@sourceacademy/bundle-arcade_2d",
49+
"@sourceacademy/bundle-binary_tree",
50+
"@sourceacademy/bundle-communication",
51+
"@sourceacademy/bundle-copy_gc",
52+
"@sourceacademy/bundle-csg",
53+
"@sourceacademy/bundle-curve",
54+
"@sourceacademy/bundle-game",
55+
"@sourceacademy/bundle-mark_sweep",
56+
"@sourceacademy/bundle-midi",
57+
"@sourceacademy/bundle-nbody",
58+
"@sourceacademy/bundle-painter",
59+
"@sourceacademy/bundle-physics_2d",
60+
"@sourceacademy/bundle-pix_n_flix",
61+
"@sourceacademy/bundle-plotly",
62+
"@sourceacademy/bundle-remote_execution",
63+
"@sourceacademy/bundle-repeat",
64+
"@sourceacademy/bundle-repl",
65+
"@sourceacademy/bundle-robot_simulation",
66+
"@sourceacademy/bundle-rune",
67+
"@sourceacademy/bundle-rune_in_words",
68+
"@sourceacademy/bundle-scrabble",
69+
"@sourceacademy/bundle-sound",
70+
"@sourceacademy/bundle-sound_matrix",
71+
"@sourceacademy/bundle-stereo_sound",
72+
"@sourceacademy/bundle-unittest",
73+
"@sourceacademy/bundle-unity_academy",
74+
"@sourceacademy/bundle-wasm",
75+
"@sourceacademy/lint-plugin",
76+
"@sourceacademy/markdown-plugin-directory-tree",
77+
"@sourceacademy/modules-buildtools",
78+
"@sourceacademy/modules-devserver",
79+
"@sourceacademy/modules-docserver",
80+
"@sourceacademy/modules-github-actions",
81+
"@sourceacademy/modules-lib",
82+
"@sourceacademy/modules-repotools",
83+
"@sourceacademy/modules",
84+
"@sourceacademy/tab-ArcadeTwod",
85+
"@sourceacademy/tab-AugmentedReality",
86+
"@sourceacademy/tab-CopyGc",
87+
"@sourceacademy/tab-Csg",
88+
"@sourceacademy/tab-Curve",
89+
"@sourceacademy/tab-Game",
90+
"@sourceacademy/tab-MarkSweep",
91+
"@sourceacademy/tab-Nbody",
92+
"@sourceacademy/tab-Painter",
93+
"@sourceacademy/tab-Physics2D",
94+
"@sourceacademy/tab-Pixnflix",
95+
"@sourceacademy/tab-Plotly",
96+
"@sourceacademy/tab-Repeat",
97+
"@sourceacademy/tab-Repl",
98+
"@sourceacademy/tab-RobotSimulation",
99+
"@sourceacademy/tab-Rune",
100+
"@sourceacademy/tab-Sound",
101+
"@sourceacademy/tab-SoundMatrix",
102+
"@sourceacademy/tab-StereoSound",
103+
"@sourceacademy/tab-Unittest",
104+
"@sourceacademy/tab-UnityAcademy",
105+
]
106+
`);
107+
expect(mockedExec).toHaveBeenCalledOnce();
108+
});
109+
});

0 commit comments

Comments
 (0)