Skip to content

Commit

Permalink
Remove dead code from split-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryNguyen5 committed Sep 20, 2023
1 parent 467934b commit 91c1c3f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 161 deletions.
51 changes: 0 additions & 51 deletions .github/actions/split-tests/src/handlers/golang.mts

This file was deleted.

83 changes: 10 additions & 73 deletions .github/actions/split-tests/src/index.mts
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
import {$, cd, glob, fs} from "zx";
import { $, cd, glob, fs } from "zx";
import path from "node:path";
import {summary, setOutput} from "@actions/core";
import {
GolangConfig,
SolidityConfig,
GoSplits,
Tests,
SoliditySplit,
TestsBySplit,
} from "./types.mjs";
import {sieveSlowTests} from "./sieve.mjs";
import {simpleSplit} from "./splitter.mjs";
import { getPackageList, GetGoPackagesReturn } from "../src/handlers/golang.mjs";
import { setOutput } from "@actions/core";
import { SolidityConfig, SoliditySplit } from "./types.mjs";
import { sieveSlowTests } from "./sieve.mjs";
import { simpleSplit } from "./splitter.mjs";

/**
* Get a JSON formatted config file
*
* @param path The path to the config relative to the git root
*/
function getConfigFrom(path?: string): GolangConfig | SolidityConfig {
function getConfigFrom(path?: string): SolidityConfig {
if (!path) {
throw Error("No config path given, specify a path via $CONFIG");
}
Expand All @@ -37,33 +29,25 @@ async function main() {
await runAtGitRoot();
const configPath = process.env.CONFIG;
const config = getConfigFrom(configPath);
if (config.type === "golang") {
await handleGolang(config);
} else if (config.type === "solidity") {
if (config.type === "solidity") {
await handleSolidity(config);
} else {
throw Error(`Invalid config given`);
}
}
main();

async function handleGolang(config: GolangConfig) {
const p: GetGoPackagesReturn = getPackageList(config)
setOutput("splits", p.serializedSplits);
createSummary(p.packages, p.testsBySplit, p.splits);
}

async function handleSolidity(config: SolidityConfig) {
const {basePath, splits: configBySplit} = config;
const { basePath, splits: configBySplit } = config;
const splits = await Promise.all(
configBySplit.map(
async ({dir, numOfSplits, slowTests: slowTestMatchers}) => {
async ({ dir, numOfSplits, slowTests: slowTestMatchers }) => {
const globPath = path.join(basePath, dir, "/**/*.test.ts");
const rawTests = await glob(globPath);
const pathMappedTests = rawTests.map((r) =>
r.replace("contracts/", "")
);
const {filteredTests, slowTests} = sieveSlowTests(
const { filteredTests, slowTests } = sieveSlowTests(
pathMappedTests,
slowTestMatchers
);
Expand All @@ -84,53 +68,6 @@ async function handleSolidity(config: SolidityConfig) {
setOutput("splits", serializedSplits);
}

function createSummary(
packages: Tests,
packagesBySplit: TestsBySplit,
splits: GoSplits
) {
if (!process.env.CI) {
return;
}
const numberOfPackages = packages.length;
const numberOfSplits = packagesBySplit.length;
const postProcessedNumberOfPackages = packagesBySplit.flat().length;

summary
.addHeading("Spliting Summary")
.addHeading(
`Number of packages from "go list ./...": ${numberOfPackages}`,
3
)
.addHeading(
`Number of packages placed into splits: ${postProcessedNumberOfPackages}`,
3
)
.addHeading(`Number of splits created: ${numberOfSplits}`, 3)
.addBreak()
.addTable([
[
{data: "Split Number", header: true},
{data: "Packages Tested", header: true},
],
...splits.map((p) => {
const mappedPackages = p.pkgs
.split(" ")
.map(
(packageName) =>
`<li> ${packageName.replace(
"github.com/smartcontractkit/",
""
)} </li>`
)
.join("\n");

return [p.id, mappedPackages];
}),
])
.write();
}

async function runAtGitRoot() {
const gitRoot = await $`git rev-parse --show-toplevel`;
cd(gitRoot.stdout.trimEnd());
Expand Down
37 changes: 0 additions & 37 deletions .github/actions/split-tests/src/types.mts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ export interface Split {
id: string;
}

export interface GoSplit extends Split {
/**
* A space delimited list of packages to run within this split
*/
pkgs: string;
}

export interface SoliditySplit extends Split {
/**
* A string that contains a whitespace delimited list of tests to run
Expand All @@ -47,19 +40,6 @@ export interface SoliditySplit extends Split {
coverageTests: string;
}

export type GoSplits = GoSplit[];

/**
* Configuration file for golang tests
*/
export interface GolangConfig {
type: "golang";
/**
* The number of splits to run tests across
*/
numOfSplits: number;
}

/**
* Configuration file for solidity tests
*/
Expand Down Expand Up @@ -93,20 +73,3 @@ export interface SolidityConfig {
slowTests?: string[];
}[];
}

export interface GoPackageData {
/**
* The package path
*/
ImportPath: string;
/**
* The list of go files asociated with the package
*/
TestGoFiles: string[] | undefined;
/**
* The list of go files not associated with a specific package
* Things like integration tests
*/
XTestGoFiles: string[] | undefined;
// there are many other variables in the data but they are not needed yet
}

0 comments on commit 91c1c3f

Please sign in to comment.