Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(actions): remove needless "commitlint" workflow if exists #1263

Merged
merged 1 commit into from
May 11, 2022
Merged
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
16 changes: 15 additions & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ const initCommand = (baseDir, logger) => {
logger(`=> ${emphasize(relative(baseDir, file))} was updated`);
};

/**
* @param {string} firstPath
* @param {string[]} restPath
*/
const removeForcibly = async (firstPath, ...restPath) => {
await rm(currentPath(firstPath, ...restPath), { force: true });
};

return {
// eslint-disable-next-line max-statements, max-lines-per-function
async updatePackageFile() {
Expand Down Expand Up @@ -128,7 +136,12 @@ const initCommand = (baseDir, logger) => {
// NOTE: husky v7 no longer requires `.husky/.gitignore`.
// See https://github.com/typicode/husky/releases/tag/v7.0.0
async removeNeedlessHuskyIgnore() {
await rm(currentPath(".husky", ".gitignore"), { force: true });
await removeForcibly(".husky", ".gitignore");
},

// See https://github.com/ybiquitous/ybiq/pull/1257
async removeNeedlessCommitlintWorkflow() {
await removeForcibly(".github", "workflows", "commitlint.yml");
},
};
};
Expand All @@ -150,6 +163,7 @@ export async function init({ cwd = process.cwd(), logger = defaultLogger } = {})
await cmd.writePackageFile(".husky", "pre-commit");

await cmd.removeNeedlessHuskyIgnore();
await cmd.removeNeedlessCommitlintWorkflow();
}

export const command = "init";
Expand Down
11 changes: 11 additions & 0 deletions test/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,14 @@ test("Remove `.husky/.gitignore` if exists", () =>

expect(existsSync(join(ctx.workDir, ".husky", ".gitignore"))).toEqual(false);
}));

test("Remove `.github/workflows/commitlint.yml` if exists", () =>
sandbox(async (ctx) => {
mkdirSync(join(ctx.workDir, ".github", "workflows"), { recursive: true });
writeFileSync(join(ctx.workDir, ".github", "workflows", "commitlint.yml"), "dummy: 1");
writeFileSync(join(ctx.workDir, "package.json"), "{}");

await init(ctx.initArgs);

expect(existsSync(join(ctx.workDir, ".github", "workflows", "commitlint.yml"))).toEqual(false);
}));