2021-10-20 11:18:23 +11:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
# vim: set ft=sh sw=4 :
|
|
|
|
|
|
|
|
|
|
load helper_print-info
|
|
|
|
|
|
|
|
|
|
export repo=".tmp_testing/repo"
|
|
|
|
|
|
|
|
|
|
function init_repo {
|
|
|
|
|
rm -rf "${repo}" &&
|
|
|
|
|
mkdir -p "${repo}" &&
|
|
|
|
|
cd "${repo}" &&
|
|
|
|
|
git init &&
|
|
|
|
|
git checkout -b main &&
|
|
|
|
|
touch README.md &&
|
|
|
|
|
git add README.md &&
|
|
|
|
|
git config user.email test@example.com &&
|
|
|
|
|
git config user.name Tester &&
|
|
|
|
|
git commit -m "README" &&
|
|
|
|
|
export GITHUB_REF="refs/heads/main"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "fails if no current_version given" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
2021-10-21 23:38:24 +11:00
|
|
|
[ "$status" -eq 8 ] &&
|
2021-10-20 11:18:23 +11:00
|
|
|
[[ "$output" = *"Environment variable 'current_version' is unset or empty"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "fails if invalid current_version given" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.3.5-prerelease
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
2021-10-21 23:38:24 +11:00
|
|
|
[ "$status" -eq 8 ] &&
|
2021-10-20 11:18:23 +11:00
|
|
|
[[ "$output" = *"Environment variable 'current_version' is not a valid normal version"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "fails if invalid scheme given" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
2021-10-22 11:49:04 +11:00
|
|
|
export scheme="foover"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 8 ] &&
|
|
|
|
|
[[ "$output" = *"Value of 'scheme' is not valid"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "fails if invalid increment given" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
2021-10-22 11:49:04 +11:00
|
|
|
export increment="critical"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
2021-10-21 23:38:24 +11:00
|
|
|
[ "$status" -eq 8 ] &&
|
2021-10-20 11:18:23 +11:00
|
|
|
[[ "$output" = *"Value of 'increment' is not valid, choose from 'major', 'minor', or 'patch'"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-19 08:51:44 +11:00
|
|
|
@test "no deprecated set-output calls made" {
|
|
|
|
|
run grep -q "::set-output" version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 1 ]
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-20 11:18:23 +11:00
|
|
|
@test "increments the patch digit correctly (semver)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
2021-10-22 11:49:04 +11:00
|
|
|
export increment="patch"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"MAJOR_VERSION=1"* ]] &&
|
|
|
|
|
[[ "$output" = *"MINOR_VERSION=2"* ]] &&
|
|
|
|
|
[[ "$output" = *"PATCH_VERSION=4"* ]] &&
|
|
|
|
|
[[ "$output" = *"VERSION=1.2.4"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "increments the minor digit correctly (semver)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
2021-10-22 11:49:04 +11:00
|
|
|
export increment="minor"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"MAJOR_VERSION=1"* ]] &&
|
|
|
|
|
[[ "$output" = *"MINOR_VERSION=3"* ]] &&
|
|
|
|
|
[[ "$output" = *"PATCH_VERSION=0"* ]] &&
|
|
|
|
|
[[ "$output" = *"VERSION=1.3.0"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "increments the major digit correctly (semver)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
2021-10-22 11:49:04 +11:00
|
|
|
export increment="major"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"MAJOR_VERSION=2"* ]] &&
|
|
|
|
|
[[ "$output" = *"MINOR_VERSION=0"* ]] &&
|
|
|
|
|
[[ "$output" = *"PATCH_VERSION=0"* ]] &&
|
|
|
|
|
[[ "$output" = *"VERSION=2.0.0"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
2023-04-26 15:18:48 +10:00
|
|
|
@test "increments the major digit correctly (pep440)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
|
|
|
|
export scheme="pep440"
|
|
|
|
|
export increment="major"
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
|
|
|
|
[[ "$output" = *"MAJOR_VERSION=2"* ]] &&
|
|
|
|
|
[[ "$output" = *"MINOR_VERSION=0"* ]] &&
|
|
|
|
|
[[ "$output" = *"PATCH_VERSION=0"* ]] &&
|
|
|
|
|
[[ "$output" = *"VERSION=2.0.0"* ]]
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-15 06:54:21 +11:00
|
|
|
@test "prefixes with v" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
|
|
|
|
export increment="major"
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"VERSION=2.0.0"* ]] &&
|
|
|
|
|
[[ "$output" = *"MAJOR_V_VERSION=v2"* ]] &&
|
|
|
|
|
[[ "$output" = *"MINOR_V_VERSION=v0"* ]] &&
|
|
|
|
|
[[ "$output" = *"PATCH_V_VERSION=v0"* ]] &&
|
|
|
|
|
[[ "$output" = *"V_VERSION=v2.0.0"* ]]
|
2021-11-15 06:54:21 +11:00
|
|
|
}
|
|
|
|
|
|
2021-10-20 11:18:23 +11:00
|
|
|
@test "increments to a new month (calver)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=2020.6.4
|
2021-10-22 11:49:04 +11:00
|
|
|
export scheme="calver"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"VERSION=$(date +%Y.%-m.1)"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "increments the patch digit within a month (calver)" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version="$(date +%Y.%-m.123)"
|
2021-10-22 11:49:04 +11:00
|
|
|
export scheme="calver"
|
2021-10-20 11:18:23 +11:00
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"VERSION=$(date +%Y.%-m.124)"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@test "appends prerelease information if on a branch" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=1.2.3
|
|
|
|
|
export GITHUB_REF="refs/heads/super-awesome-feature"
|
|
|
|
|
export short_ref="$(git rev-parse --short HEAD | sed 's/0*//')"
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
2022-10-19 08:51:44 +11:00
|
|
|
[[ "$output" = *"PRE_RELEASE_LABEL=pre.${short_ref}"* ]]
|
|
|
|
|
[[ "$output" = *"VERSION=1.2.4-pre.${short_ref}"* ]]
|
2021-10-20 11:18:23 +11:00
|
|
|
}
|
2023-04-26 15:18:48 +10:00
|
|
|
|
|
|
|
|
@test "appends prerelease information in pep440 compatible way if on a branch and scheme is pep440" {
|
|
|
|
|
init_repo
|
|
|
|
|
|
|
|
|
|
export current_version=10.20.30
|
|
|
|
|
export scheme="pep440"
|
|
|
|
|
export GITHUB_REF="refs/heads/super-awesome-python"
|
|
|
|
|
export short_ref="$(git rev-parse --short HEAD | sed 's/0*//')"
|
|
|
|
|
|
|
|
|
|
run ../../version-increment.sh
|
|
|
|
|
|
|
|
|
|
print_run_info
|
|
|
|
|
[ "$status" -eq 0 ] &&
|
|
|
|
|
[[ "$output" = *"PRE_RELEASE_LABEL=pre.${short_ref}"* ]]
|
|
|
|
|
[[ "$output" = *"VERSION=10.20.31+pre.${short_ref}"* ]]
|
|
|
|
|
}
|