ci: Delete .github/workflows/check-tests.yml (#12255)

This commit is contained in:
Tomi Turtiainen 2024-12-17 10:39:58 +02:00 committed by GitHub
parent f44e4904c8
commit 5129865528
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 1 additions and 135 deletions

View file

@ -1,103 +0,0 @@
import { readFile } from 'fs/promises';
import path from 'path';
import util from 'util';
import { exec } from 'child_process';
import { glob } from 'glob';
import ts from 'typescript';
const execAsync = util.promisify(exec);
const filterAsync = async (asyncPredicate, arr) => {
const filterResults = await Promise.all(
arr.map(async (item) => ({
item,
shouldKeep: await asyncPredicate(item),
})),
);
return filterResults.filter(({ shouldKeep }) => shouldKeep).map(({ item }) => item);
};
const isAbstractClass = (node) => {
if (ts.isClassDeclaration(node)) {
return (
node.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword) || false
);
}
return false;
};
const isAbstractMethod = (node) => {
return (
ts.isMethodDeclaration(node) &&
Boolean(node.modifiers?.find((modifier) => modifier.kind === ts.SyntaxKind.AbstractKeyword))
);
};
// Function to check if a file has a function declaration, function expression, object method or class
const hasFunctionOrClass = async (filePath) => {
const fileContent = await readFile(filePath, 'utf-8');
const sourceFile = ts.createSourceFile(filePath, fileContent, ts.ScriptTarget.Latest, true);
let hasFunctionOrClass = false;
const visit = (node) => {
if (
ts.isFunctionDeclaration(node) ||
ts.isFunctionExpression(node) ||
ts.isArrowFunction(node) ||
(ts.isMethodDeclaration(node) && !isAbstractMethod(node)) ||
(ts.isClassDeclaration(node) && !isAbstractClass(node))
) {
hasFunctionOrClass = true;
}
node.forEachChild(visit);
};
visit(sourceFile);
return hasFunctionOrClass;
};
const main = async () => {
// Run a git command to get a list of all changed files in the branch (branch has to be up to date with master)
const changedFiles = await execAsync(
'git diff --name-only --diff-filter=d origin/master..HEAD',
).then(({ stdout }) => stdout.trim().split('\n').filter(Boolean));
// Get all .spec.ts and .test.ts files from the packages
const specAndTestTsFiles = await glob('packages/*/**/{test,__tests__}/**/*.{spec,test}.ts');
const specAndTestTsFilesNames = specAndTestTsFiles.map((file) =>
path.parse(file).name.replace(/\.(test|spec)/, ''),
);
// Filter out the .ts and .vue files from the changed files
const changedVueFiles = changedFiles.filter((file) => file.endsWith('.vue'));
// .ts files with any kind of function declaration or class and not in any of the test folders
const changedTsFilesWithFunction = await filterAsync(
async (filePath) =>
filePath.endsWith('.ts') &&
!(await glob('packages/*/**/{test,__tests__}/*.ts')).includes(filePath) &&
(await hasFunctionOrClass(filePath)),
changedFiles,
);
// For each .ts or .vue file, check if there's a corresponding .test.ts or .spec.ts file in the repository
const missingTests = changedVueFiles
.concat(changedTsFilesWithFunction)
.reduce((filesList, nextFile) => {
const fileName = path.parse(nextFile).name;
if (!specAndTestTsFilesNames.includes(fileName)) {
filesList.push(nextFile);
}
return filesList;
}, []);
if (missingTests.length) {
console.error(`Missing tests for:\n${missingTests.join('\n')}`);
process.exit(1);
}
};
main();

View file

@ -7,7 +7,6 @@
"p-limit": "3.1.0",
"picocolors": "1.0.1",
"semver": "7.5.4",
"tempfile": "5.0.0",
"typescript": "*"
"tempfile": "5.0.0"
}
}

View file

@ -1,30 +0,0 @@
name: Check Test Files
on:
pull_request:
branches:
- '**'
- '!release/*'
pull_request_target:
branches:
- master
jobs:
check-tests:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v4.1.1
with:
fetch-depth: 0
- name: Use Node.js
uses: actions/setup-node@v4.0.2
with:
node-version: 20.x
- run: npm install --prefix=.github/scripts --no-package-lock
- name: Check for test files
run: node .github/scripts/check-tests.mjs