Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/actions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@
"@actions/artifact": "^2.3.2",
"@actions/core": "^1.11.1",
"@actions/exec": "^1.1.1",
"@yarnpkg/cli": "^4.12.0",
"@yarnpkg/core": "^4.5.0",
"@yarnpkg/fslib": "^3.1.4",
"lodash": "^4.17.21",
"snyk-nodejs-lockfile-parser": "^2.4.2"
},
"scripts": {
"build": "node ./build.js",
"build": "node ./build.js --dev",
"postinstall": "yarn build",
"test": "vitest",
"tsc": "tsc --project ./tsconfig.json"
Expand Down
64 changes: 1 addition & 63 deletions .github/actions/src/__tests__/commons.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as exec from '@actions/exec';
import { describe, expect, it, test, vi } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import * as commons from '../commons.js';

vi.mock(import('lodash/memoize.js'), () => ({
Expand Down Expand Up @@ -28,65 +28,3 @@ describe(commons.checkDirForChanges, () => {
expect(mockedExecOutput).toHaveBeenCalledOnce();
});
});

describe(commons.isPackageRecord, () => {
test('no bundleName or tabName property is ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false
})).toEqual(true);
});

test('string bundleName property is ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false,
bundleName: ''
})).toEqual(true);
});

test('non-string bundleName property is not ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false,
bundleName: 0
})).toEqual(false);
});

test('string tabName property is ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false,
tabName: ''
})).toEqual(true);
});

test('non-string tabName property is not ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false,
tabName: 0
})).toEqual(false);
});

test('having both bundleName and tabName property is not ok', () => {
expect(commons.isPackageRecord({
directory: '',
name: '',
changes: false,
needsPlaywright: false,
tabName: '',
bundleName: ''
})).toEqual(false);
});
});
62 changes: 2 additions & 60 deletions .github/actions/src/commons.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,6 @@
import { getExecOutput } from '@actions/exec';
import memoize from 'lodash/memoize.js';

export interface RawPackageRecord {
directory: string;
hasChanges: boolean;
package: {
name: string;
devDependencies: Record<string, string>;
dependencies: Record<string, string>;
};
}

interface BasePackageRecord {
/**
* Directory within which the `package.json` file was found
*/
directory: string;

/**
* Full scoped package name
*/
name: string;
/**
* `true` if git detected changes from within the package's subdirectories,
* `false` otherwise
*/
changes: boolean;
/**
* `true` if playwright is present under devDependencies. This means that the package
* might need playwright for its tests
*/
needsPlaywright: boolean;
}

export interface BundlePackageRecord extends BasePackageRecord {
bundleName: string;
}

export interface TabPackageRecord extends BasePackageRecord {
tabName: string;
}

export type PackageRecord = BundlePackageRecord | TabPackageRecord | BasePackageRecord;

export function isPackageRecord(obj: unknown): obj is PackageRecord {
if (typeof obj !== 'object' || obj === null) return false;

if (!('directory' in obj) || typeof obj.directory !== 'string') return false;
if (!('name' in obj) || typeof obj.name !== 'string') return false;
if (!('changes' in obj) || typeof obj.changes !== 'boolean') return false;
if (!('needsPlaywright' in obj) || typeof obj.needsPlaywright !== 'boolean') return false;

if ('bundleName' in obj) {
if ('tabName' in obj || typeof obj.bundleName !== 'string') return false;
} else if ('tabName' in obj) {
if (typeof obj.tabName !== 'string') return false;
}

return true;
}

/**
* Returns `true` if there are changes present in the given directory relative to
* the master branch\
Expand All @@ -71,7 +12,8 @@ export const checkDirForChanges = memoize(async (directory: string) => {
['--no-pager', 'diff', '--quiet', 'origin/master', '--', directory],
{
failOnStdErr: false,
ignoreReturnCode: true
ignoreReturnCode: true,
silent: true
}
);
return exitCode !== 0;
Expand Down
Loading