Skip to content
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
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,31 @@ jobs:
exit 1
fi

test-bats:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: '0'

- name: Install Dependencies
run: npm install -g semver

- name: Setup Bats
id: setup-bats
uses: bats-core/bats-action@3.0.1
with:
support-path: "${{ github.workspace }}/tests/bats-support"
assert-path: "${{ github.workspace }}/tests/bats-assert"
detik-install: false
file-install: false

- name: Run tests
shell: bash
env:
BATS_LIB_PATH: ${{ steps.setup-bats.outputs.lib-path }}
run: |
echo "Prefix Tests:"
bats test/test_prefix.bats
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# macOS
.DS_Store

# VSCode
.vscode/

# Rider/JetBrains IDE
.idea/
*.sln.iml
*.user
*.suo
*.sln.docstates
.idea_modules/
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ if [ -z "$tagPrefix" ]
then
current_tag=${tag}
else
current_tag="$(echo ${tag}| sed "s/${tagPrefix}//g")"
current_tag="$(echo ${tag}| sed "s;${tagPrefix};;g")"
fi
case "$log" in
*$major_string_token* ) new=${tagPrefix}$(semver -i major "${current_tag}"); part="major";;
Expand Down
126 changes: 126 additions & 0 deletions test/test_prefix.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#!/usr/bin/env bats
export BATS_LIB_PATH=${BATS_LIB_PATH:-"/usr/lib"}
bats_load_library bats-support
bats_load_library bats-assert

setup() {
TMP=$(mktemp -d)
cd "$TMP"
git init -b main >/dev/null
git config user.name "Test"
git config user.email "test@example.com"
touch README && git add README && git commit -m "initial" >/dev/null

SOURCE="../../../../..$(pwd)" # Workaround for "GITHUB_WORKSPACE" prefix in script
}

teardown() {
rm -rf "$TMP"
}

run_entry() {
bash "$BATS_TEST_DIRNAME/../entrypoint.sh"
}

@test "Creates a new tag with default settings (no prefix)" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag 0.0.0 - New tag 0.1.0"
}

@test "Bumps a tag with default settings (no prefix)" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
git tag "1.0.0" && git commit -m "bump" --allow-empty >/dev/null

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag 1.0.0 - New tag 1.1.0"
}

@test "Creates a new tag with 'v' prefix" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
export TAG_PREFIX="v"

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag v0.0.0 - New tag v0.1.0"
}

@test "Bumps a tag with 'v' prefix" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
export TAG_PREFIX="v"
git tag "v1.0.0" && git commit -m "bump" --allow-empty >/dev/null

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag v1.0.0 - New tag v1.1.0"
}

@test "Creates a new tag with '/' prefix" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
export TAG_PREFIX="infra/"

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag infra/0.0.0 - New tag infra/0.1.0"
}

@test "Bumps a tag with '/' prefix" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
export TAG_PREFIX="infra/"
git tag "infra/1.0.0" && git commit -m "bump" --allow-empty >/dev/null

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag infra/1.0.0 - New tag infra/1.1.0"
}

@test "Bumps only matching prefix tag" {
# Arrange
export SOURCE="$SOURCE"
export DRY_RUN="true"
export TAG_PREFIX="infra/"
git tag "2.0.0" && git commit -m "bump-no-prefix-1" --allow-empty >/dev/null
git tag "infra/1.7.0" && git commit -m "bump-prefix-1" --allow-empty >/dev/null
git tag "2.1.0" && git commit -m "bump-no-prefix-2" --allow-empty >/dev/null

# Act
run run_entry

# Assert
assert_success
assert_line "Bumping tag infra/1.7.0 - New tag infra/1.8.0"
refute_line "Bumping tag 2.1.0 - New tag 2.2.0"
}
Loading