Skip to content

Commit 25d1222

Browse files
authored
Merge pull request #8 from compilerla/feat/tests
Basic tests and GitHub workflow for PRs
2 parents 5d071da + 5de79c1 commit 25d1222

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

.github/workflows/tests.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
branches: [ "*" ]
6+
7+
jobs:
8+
tests:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v2
12+
- uses: actions/setup-python@v2
13+
- name: Install pre-commit
14+
run: |
15+
python -m pip install --upgrade pip
16+
pip install pre-commit
17+
- name: Run tests
18+
run: ./tests.sh

tests.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
this_dir="$PWD"
4+
test_dir=""
5+
result=0
6+
7+
setup () {
8+
test_dir=$(mktemp -d)
9+
10+
cp "$this_dir/.pre-commit-config.yaml" "$test_dir/"
11+
cp "$this_dir/conventional-pre-commit.sh" "$test_dir/"
12+
13+
cd "$test_dir"
14+
15+
git init
16+
17+
git branch -m main
18+
git config user.email "conventional-pre-commit@compiler.la"
19+
git config user.name "conventional-pre-commit"
20+
21+
pre-commit install --hook-type commit-msg
22+
git add .
23+
}
24+
25+
teardown () {
26+
cd "$this_dir"
27+
rm -rf "$test_dir"
28+
}
29+
30+
# test a failure
31+
32+
setup
33+
34+
fail="$(git commit -m 'bad: conventional-pre-commit' 2>&1 > /dev/null)"
35+
36+
teardown
37+
38+
echo "$fail" | grep -Eq "Your commit message does not follow Conventional Commits formatting"
39+
40+
(( result += "$?" ))
41+
42+
# test a success
43+
44+
setup
45+
46+
pass="$(git commit -m 'test: conventional-pre-commit')"
47+
48+
teardown
49+
50+
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit"
51+
52+
(( result += "$?" ))
53+
54+
exit "$result"

0 commit comments

Comments
 (0)