Skip to content
Closed
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
12 changes: 12 additions & 0 deletions .github/workflows/check-branch-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: check branch name
on: push

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: check branch name
run: chmod +x packages/ci/src/shell/branch-name.sh && packages/ci/src/shell/branch-name.sh ${GITHUB_REF#refs/heads/}
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@
"@commitlint/config-conventional": "^12.1.4",
"@commitlint/types": "^12.1.4",
"@types/jest": "^26.0.23",
"@types/shelljs": "^0.8.8",
"commitlint-config-wizardoc": "^1.0.0",
"husky": "^6.0.0",
"jest": "^27.0.1",
"jest-config": "^27.0.1",
"lerna": "^4.0.0",
"ts-jest": "^27.0.0",
"typescript": "3.8.3",
"husky": "^6.0.0"
"typescript": "3.8.3"
},
"workspaces": [
"commitlint-config-wizardoc",
"commitlint-plugin-wizardoc-rules",
"commitlint-wizardoc-e2e-tests"
],
"dependencies": {}
"dependencies": {
"shelljs": "^0.8.4"
}
}
6 changes: 6 additions & 0 deletions packages/ci/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "ci",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}
8 changes: 8 additions & 0 deletions packages/ci/src/shell/branch-name.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
branch_type="feature|hotfix|improve|chore"

if [[ $1 =~ ^($branch_type)/[a-z]+(-[a-z]+)*$ ]];then
exit 0
else
exit 1
fi
89 changes: 89 additions & 0 deletions packages/ci/src/test/branch-name.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* eslint-disable import/no-extraneous-dependencies */
import { exec } from "shelljs";

const SUCCESS_SIGNAL = 0;
const BRANCH_NAME_CHECKER = "packages/ci/src/shell/branch-name.sh";
const checkBranchName = (branchName: string) =>
exec(
`chmod +x ${BRANCH_NAME_CHECKER} && ${BRANCH_NAME_CHECKER} ${branchName}`
).code;

describe("branchNameTest", () => {
it("correct branch name", () => {
const code = checkBranchName("feature/git-rebase-test");

expect(code).toEqual(SUCCESS_SIGNAL);
});

it("type error", () => {
const code = checkBranchName("test/git-rebase-test");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("underline suffix", () => {
const code = checkBranchName("feature/git-rebase-test_");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("dash suffix", () => {
const code = checkBranchName("feature/git-rebase-test-");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("mixin camel case branch name", () => {
const code = checkBranchName("feature/git-rebase-branchName");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("mixin dash case branch name", () => {
const code = checkBranchName("feature/git-rebase-xxx_xxx");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("missing type", () => {
const code = checkBranchName("/git-rebase-xxx_xxx");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("missing branch name", () => {
const code = checkBranchName("feature/");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("missing separator", () => {
const code = checkBranchName("featurexxxxxx");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("include space", () => {
const code = checkBranchName("feature/ ssss-ssss");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("invalid symbol", () => {
const code = checkBranchName("feature/xx&xx");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("dash case branch name error", () => {
const code = checkBranchName("feature/brach_name");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});

it("camel case branch name error", () => {
const code = checkBranchName("feature/brachName");

expect(code).not.toEqual(SUCCESS_SIGNAL);
});
});
5 changes: 5 additions & 0 deletions packages/ci/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../tsconfig.base",
"include": ["src"],
"exclude": ["node_modules"]
}
Loading