From cf3a4e09a85bc9d073b517906a0b473f526d43aa Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Mon, 13 Oct 2025 14:49:06 -0400 Subject: Add test script, scripts/ folder, and use test script in ci --- .build.yml | 3 +- release.sh | 113 ----------------------------------------------------- scripts/release.sh | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/test.sh | 9 +++++ 4 files changed, 123 insertions(+), 115 deletions(-) delete mode 100755 release.sh create mode 100755 scripts/release.sh create mode 100755 scripts/test.sh diff --git a/.build.yml b/.build.yml index c74204e..702d2cc 100644 --- a/.build.yml +++ b/.build.yml @@ -7,5 +7,4 @@ sources: tasks: - test: | cd checkmate - go test -race -coverprofile=coverage.out -covermode=atomic ./... - go tool cover -func=coverage.out + ./scripts/test.sh diff --git a/release.sh b/release.sh deleted file mode 100755 index e19c244..0000000 --- a/release.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash -set -eou pipefail - -main() { - if [ $# -eq 0 ]; then - echo "Error: No version specified" >&2 - echo "Usage: $0 " >&2 - echo "Example: $0 0.5.0" >&2 - exit 1 - fi - - local version=$1 - local today - today=$(date +%Y-%m-%d) - - validate_version_format "$version" - ensure_on_main_branch - ensure_no_uncommitted_changes - ensure_tag_does_not_exist "$version" - - echo "Creating release v$version..." - - echo "Updating CHANGELOG.md..." - update_changelog "$version" "$today" - - echo "Updating README.md..." - update_readme_version_badge "$version" - - echo "Creating commit and tag..." - create_release_commit_and_tag "$version" - - echo "Pushing to remote..." - git push && git push --tags - - echo "Release v$version created and pushed successfully!" -} - -validate_version_format() { - local version=$1 - if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo "Error: Invalid version format: $version" >&2 - echo "Version must follow semantic versioning (e.g., 0.5.0)" >&2 - exit 1 - fi -} - -ensure_on_main_branch() { - local current_branch - current_branch=$(git branch --show-current) - if [ "$current_branch" != "main" ]; then - echo "Error: Not on main branch (current: $current_branch)" >&2 - exit 1 - fi -} - -ensure_no_uncommitted_changes() { - if ! git diff-index --quiet HEAD --; then - echo "Error: Uncommitted changes detected. Please commit or stash them first." >&2 - exit 1 - fi -} - -ensure_tag_does_not_exist() { - local version=$1 - if git rev-parse "v$version" >/dev/null 2>&1; then - echo "Error: Tag v$version already exists" >&2 - exit 1 - fi -} - -update_changelog() { - local version=$1 - local today=$2 - - if ! grep -q "## \[Unreleased\]" CHANGELOG.md; then - echo "Error: No [Unreleased] section found in CHANGELOG.md" >&2 - exit 1 - fi - - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "/## \[Unreleased\]/a\\ -\\ -## [$version] - $today -" CHANGELOG.md - else - sed -i "/## \[Unreleased\]/a\\\\n## [$version] - $today" CHANGELOG.md - fi -} - -update_readme_version_badge() { - local version=$1 - - if ! grep -q "version-.*-blue" README.md; then - echo "Error: Version badge not found in README.md" >&2 - exit 1 - fi - - if [[ "$OSTYPE" == "darwin"* ]]; then - sed -i '' "s/version-[0-9]*\.[0-9]*\.[0-9]*-blue/version-$version-blue/" README.md - else - sed -i "s/version-[0-9]*\.[0-9]*\.[0-9]*-blue/version-$version-blue/" README.md - fi -} - -create_release_commit_and_tag() { - local version=$1 - - git add CHANGELOG.md README.md - git commit -m "Release version v$version" - git tag "v$version" -} - -main "$@" diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..e19c244 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,113 @@ +#!/usr/bin/env bash +set -eou pipefail + +main() { + if [ $# -eq 0 ]; then + echo "Error: No version specified" >&2 + echo "Usage: $0 " >&2 + echo "Example: $0 0.5.0" >&2 + exit 1 + fi + + local version=$1 + local today + today=$(date +%Y-%m-%d) + + validate_version_format "$version" + ensure_on_main_branch + ensure_no_uncommitted_changes + ensure_tag_does_not_exist "$version" + + echo "Creating release v$version..." + + echo "Updating CHANGELOG.md..." + update_changelog "$version" "$today" + + echo "Updating README.md..." + update_readme_version_badge "$version" + + echo "Creating commit and tag..." + create_release_commit_and_tag "$version" + + echo "Pushing to remote..." + git push && git push --tags + + echo "Release v$version created and pushed successfully!" +} + +validate_version_format() { + local version=$1 + if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Invalid version format: $version" >&2 + echo "Version must follow semantic versioning (e.g., 0.5.0)" >&2 + exit 1 + fi +} + +ensure_on_main_branch() { + local current_branch + current_branch=$(git branch --show-current) + if [ "$current_branch" != "main" ]; then + echo "Error: Not on main branch (current: $current_branch)" >&2 + exit 1 + fi +} + +ensure_no_uncommitted_changes() { + if ! git diff-index --quiet HEAD --; then + echo "Error: Uncommitted changes detected. Please commit or stash them first." >&2 + exit 1 + fi +} + +ensure_tag_does_not_exist() { + local version=$1 + if git rev-parse "v$version" >/dev/null 2>&1; then + echo "Error: Tag v$version already exists" >&2 + exit 1 + fi +} + +update_changelog() { + local version=$1 + local today=$2 + + if ! grep -q "## \[Unreleased\]" CHANGELOG.md; then + echo "Error: No [Unreleased] section found in CHANGELOG.md" >&2 + exit 1 + fi + + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "/## \[Unreleased\]/a\\ +\\ +## [$version] - $today +" CHANGELOG.md + else + sed -i "/## \[Unreleased\]/a\\\\n## [$version] - $today" CHANGELOG.md + fi +} + +update_readme_version_badge() { + local version=$1 + + if ! grep -q "version-.*-blue" README.md; then + echo "Error: Version badge not found in README.md" >&2 + exit 1 + fi + + if [[ "$OSTYPE" == "darwin"* ]]; then + sed -i '' "s/version-[0-9]*\.[0-9]*\.[0-9]*-blue/version-$version-blue/" README.md + else + sed -i "s/version-[0-9]*\.[0-9]*\.[0-9]*-blue/version-$version-blue/" README.md + fi +} + +create_release_commit_and_tag() { + local version=$1 + + git add CHANGELOG.md README.md + git commit -m "Release version v$version" + git tag "v$version" +} + +main "$@" diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..61739ba --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -eou pipefail + +main() { + go test -race -coverprofile=coverage.out -covermode=atomic ./... + go tool cover -func=coverage.out +} + +main "$@" -- cgit v1.2.3