Skip to content

Commit 24379a6

Browse files
committed
[Add::workflow] perfect branch name action and add test for workflow
1 parent 402a2ac commit 24379a6

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

.github/shell/branchName.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if [[ $1 =~ ^([a-z]+)/[a-z]+(-[a-z]+)+$ ]];then
2+
if [[ ${BASH_REMATCH[1]} =~ ^(feature|fix)$ ]]; then
3+
echo "success"
4+
exit 0
5+
else
6+
echo "error"
7+
exit 1
8+
fi
9+
else
10+
echo "erroe"
11+
exit 1
12+
fi

.github/workflows/checkBranchName.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ jobs:
99
- uses: actions/checkout@v2
1010

1111
- name: check branch name
12-
run: echo "${GITHUB_REF#refs/heads/}" |grep -q "feature/" && exit 0 || exit 1
12+
run: ./.github/shell/branchName.sh ${GITHUB_REF#refs/heads/}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/* eslint-disable import/no-extraneous-dependencies */
2+
import { $ } from "../utils/shell";
3+
4+
const SUCCESS_SIGNAL = 0;
5+
const ERROR_SIGNAL = 1;
6+
7+
describe("branchNameTest", () => {
8+
it("success branch name", () => {
9+
const res = $`sh ./.github/shell/branchName.sh feature/git-rebase-test`;
10+
11+
expect(res.code).toEqual(SUCCESS_SIGNAL);
12+
});
13+
14+
it("type error", () => {
15+
const res = $`sh ./.github/shell/branchName.sh test/git-rebase-test`;
16+
17+
expect(res.code).toEqual(ERROR_SIGNAL);
18+
});
19+
20+
it("empty branch name error", () => {
21+
const res = $`sh ./.github/shell/branchName.sh feature/`;
22+
23+
expect(res.code).toEqual(ERROR_SIGNAL);
24+
});
25+
26+
it("separator branch name error", () => {
27+
const res = $`sh ./.github/shell/branchName.sh feature/brach_name`;
28+
29+
expect(res.code).toEqual(ERROR_SIGNAL);
30+
});
31+
32+
it("upper Case branch name error", () => {
33+
const res = $`sh ./.github/shell/branchName.sh feature/brachName`;
34+
35+
expect(res.code).toEqual(ERROR_SIGNAL);
36+
});
37+
});

0 commit comments

Comments
 (0)