Skip to content

Commit 4ed4496

Browse files
authored
Merge pull request #347 from TheYorkshireDev/bugfix/support-forward-slash
Support Escapable Characters in Prefix With BATs Testing
2 parents 6353aab + 32cc67b commit 4ed4496

File tree

4 files changed

+173
-1
lines changed

4 files changed

+173
-1
lines changed

.github/workflows/test.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,31 @@ jobs:
202202
exit 1
203203
fi
204204
205+
test-bats:
206+
runs-on: ubuntu-latest
207+
steps:
208+
- name: Checkout
209+
uses: actions/checkout@v4
210+
with:
211+
ref: ${{ github.event.pull_request.head.sha }}
212+
fetch-depth: '0'
213+
214+
- name: Install Dependencies
215+
run: npm install -g semver
216+
217+
- name: Setup Bats
218+
id: setup-bats
219+
uses: bats-core/[email protected]
220+
with:
221+
support-path: "${{ github.workspace }}/tests/bats-support"
222+
assert-path: "${{ github.workspace }}/tests/bats-assert"
223+
detik-install: false
224+
file-install: false
225+
226+
- name: Run tests
227+
shell: bash
228+
env:
229+
BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }}
230+
run: |
231+
echo "Prefix Tests:"
232+
bats test/test_prefix.bats

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# macOS
2+
.DS_Store
3+
4+
# VSCode
5+
.vscode/
6+
7+
# Rider/JetBrains IDE
8+
.idea/
9+
*.sln.iml
10+
*.user
11+
*.suo
12+
*.sln.docstates
13+
.idea_modules/
14+
.idea/**/workspace.xml
15+
.idea/**/tasks.xml
16+
.idea/**/usage.statistics.xml
17+
.idea/**/dictionaries
18+
.idea/**/shelf

entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ if [ -z "$tagPrefix" ]
172172
then
173173
current_tag=${tag}
174174
else
175-
current_tag="$(echo ${tag}| sed "s/${tagPrefix}//g")"
175+
current_tag="$(echo ${tag}| sed "s;${tagPrefix};;g")"
176176
fi
177177
case "$log" in
178178
*$major_string_token* ) new=${tagPrefix}$(semver -i major "${current_tag}"); part="major";;

test/test_prefix.bats

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env bats
2+
export BATS_LIB_PATH=${BATS_LIB_PATH:-"/usr/lib"}
3+
bats_load_library bats-support
4+
bats_load_library bats-assert
5+
6+
setup() {
7+
TMP=$(mktemp -d)
8+
cd "$TMP"
9+
git init -b main >/dev/null
10+
git config user.name "Test"
11+
git config user.email "[email protected]"
12+
touch README && git add README && git commit -m "initial" >/dev/null
13+
14+
SOURCE="../../../../..$(pwd)" # Workaround for "GITHUB_WORKSPACE" prefix in script
15+
}
16+
17+
teardown() {
18+
rm -rf "$TMP"
19+
}
20+
21+
run_entry() {
22+
bash "$BATS_TEST_DIRNAME/../entrypoint.sh"
23+
}
24+
25+
@test "Creates a new tag with default settings (no prefix)" {
26+
# Arrange
27+
export SOURCE="$SOURCE"
28+
export DRY_RUN="true"
29+
30+
# Act
31+
run run_entry
32+
33+
# Assert
34+
assert_success
35+
assert_line "Bumping tag 0.0.0 - New tag 0.1.0"
36+
}
37+
38+
@test "Bumps a tag with default settings (no prefix)" {
39+
# Arrange
40+
export SOURCE="$SOURCE"
41+
export DRY_RUN="true"
42+
git tag "1.0.0" && git commit -m "bump" --allow-empty >/dev/null
43+
44+
# Act
45+
run run_entry
46+
47+
# Assert
48+
assert_success
49+
assert_line "Bumping tag 1.0.0 - New tag 1.1.0"
50+
}
51+
52+
@test "Creates a new tag with 'v' prefix" {
53+
# Arrange
54+
export SOURCE="$SOURCE"
55+
export DRY_RUN="true"
56+
export TAG_PREFIX="v"
57+
58+
# Act
59+
run run_entry
60+
61+
# Assert
62+
assert_success
63+
assert_line "Bumping tag v0.0.0 - New tag v0.1.0"
64+
}
65+
66+
@test "Bumps a tag with 'v' prefix" {
67+
# Arrange
68+
export SOURCE="$SOURCE"
69+
export DRY_RUN="true"
70+
export TAG_PREFIX="v"
71+
git tag "v1.0.0" && git commit -m "bump" --allow-empty >/dev/null
72+
73+
# Act
74+
run run_entry
75+
76+
# Assert
77+
assert_success
78+
assert_line "Bumping tag v1.0.0 - New tag v1.1.0"
79+
}
80+
81+
@test "Creates a new tag with '/' prefix" {
82+
# Arrange
83+
export SOURCE="$SOURCE"
84+
export DRY_RUN="true"
85+
export TAG_PREFIX="infra/"
86+
87+
# Act
88+
run run_entry
89+
90+
# Assert
91+
assert_success
92+
assert_line "Bumping tag infra/0.0.0 - New tag infra/0.1.0"
93+
}
94+
95+
@test "Bumps a tag with '/' prefix" {
96+
# Arrange
97+
export SOURCE="$SOURCE"
98+
export DRY_RUN="true"
99+
export TAG_PREFIX="infra/"
100+
git tag "infra/1.0.0" && git commit -m "bump" --allow-empty >/dev/null
101+
102+
# Act
103+
run run_entry
104+
105+
# Assert
106+
assert_success
107+
assert_line "Bumping tag infra/1.0.0 - New tag infra/1.1.0"
108+
}
109+
110+
@test "Bumps only matching prefix tag" {
111+
# Arrange
112+
export SOURCE="$SOURCE"
113+
export DRY_RUN="true"
114+
export TAG_PREFIX="infra/"
115+
git tag "2.0.0" && git commit -m "bump-no-prefix-1" --allow-empty >/dev/null
116+
git tag "infra/1.7.0" && git commit -m "bump-prefix-1" --allow-empty >/dev/null
117+
git tag "2.1.0" && git commit -m "bump-no-prefix-2" --allow-empty >/dev/null
118+
119+
# Act
120+
run run_entry
121+
122+
# Assert
123+
assert_success
124+
assert_line "Bumping tag infra/1.7.0 - New tag infra/1.8.0"
125+
refute_line "Bumping tag 2.1.0 - New tag 2.2.0"
126+
}

0 commit comments

Comments
 (0)