jekyll-theme-zer0 0.7.2 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +72 -0
  3. data/README.md +33 -4
  4. data/_plugins/preview_image_generator.rb +258 -0
  5. data/_plugins/theme_version.rb +88 -0
  6. data/assets/images/previews/git-workflow-best-practices-for-modern-teams.png +0 -0
  7. data/scripts/README.md +443 -0
  8. data/scripts/analyze-commits.sh +313 -0
  9. data/scripts/build +115 -0
  10. data/scripts/build.sh +33 -0
  11. data/scripts/build.sh.legacy +174 -0
  12. data/scripts/example-usage.sh +102 -0
  13. data/scripts/fix-markdown-format.sh +265 -0
  14. data/scripts/gem-publish.sh +42 -0
  15. data/scripts/gem-publish.sh.legacy +700 -0
  16. data/scripts/generate-preview-images.sh +846 -0
  17. data/scripts/install-preview-generator.sh +531 -0
  18. data/scripts/lib/README.md +263 -0
  19. data/scripts/lib/changelog.sh +313 -0
  20. data/scripts/lib/common.sh +154 -0
  21. data/scripts/lib/gem.sh +226 -0
  22. data/scripts/lib/git.sh +205 -0
  23. data/scripts/lib/preview_generator.py +646 -0
  24. data/scripts/lib/test/run_tests.sh +140 -0
  25. data/scripts/lib/test/test_changelog.sh +87 -0
  26. data/scripts/lib/test/test_gem.sh +68 -0
  27. data/scripts/lib/test/test_git.sh +82 -0
  28. data/scripts/lib/test/test_validation.sh +72 -0
  29. data/scripts/lib/test/test_version.sh +96 -0
  30. data/scripts/lib/validation.sh +139 -0
  31. data/scripts/lib/version.sh +178 -0
  32. data/scripts/release +240 -0
  33. data/scripts/release.sh +33 -0
  34. data/scripts/release.sh.legacy +342 -0
  35. data/scripts/setup.sh +155 -0
  36. data/scripts/test-auto-version.sh +260 -0
  37. data/scripts/test-mermaid.sh +251 -0
  38. data/scripts/test.sh +156 -0
  39. data/scripts/version.sh +152 -0
  40. metadata +37 -1
@@ -0,0 +1,140 @@
1
+ #!/bin/bash
2
+
3
+ # Test runner for library unit tests
4
+ # Usage: ./scripts/lib/test/run_tests.sh
5
+
6
+ set -euo pipefail
7
+
8
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
10
+
11
+ # Colors
12
+ RED='\033[0;31m'
13
+ GREEN='\033[0;32m'
14
+ YELLOW='\033[1;33m'
15
+ BLUE='\033[0;34m'
16
+ NC='\033[0m'
17
+
18
+ # Test counters
19
+ TESTS_RUN=0
20
+ TESTS_PASSED=0
21
+ TESTS_FAILED=0
22
+
23
+ # Test result tracking
24
+ declare -a FAILED_TESTS=()
25
+
26
+ # Test assertions
27
+ assert_equals() {
28
+ local expected="$1"
29
+ local actual="$2"
30
+ local message="${3:-}"
31
+
32
+ ((TESTS_RUN++))
33
+
34
+ if [[ "$expected" == "$actual" ]]; then
35
+ ((TESTS_PASSED++))
36
+ echo -e "${GREEN}✓${NC} $message"
37
+ return 0
38
+ else
39
+ ((TESTS_FAILED++))
40
+ echo -e "${RED}✗${NC} $message"
41
+ echo -e " Expected: ${YELLOW}$expected${NC}"
42
+ echo -e " Actual: ${YELLOW}$actual${NC}"
43
+ FAILED_TESTS+=("$message")
44
+ return 1
45
+ fi
46
+ }
47
+
48
+ assert_true() {
49
+ local condition="$1"
50
+ local message="${2:-}"
51
+
52
+ ((TESTS_RUN++))
53
+
54
+ if eval "$condition"; then
55
+ ((TESTS_PASSED++))
56
+ echo -e "${GREEN}✓${NC} $message"
57
+ return 0
58
+ else
59
+ ((TESTS_FAILED++))
60
+ echo -e "${RED}✗${NC} $message"
61
+ echo -e " Condition failed: ${YELLOW}$condition${NC}"
62
+ FAILED_TESTS+=("$message")
63
+ return 1
64
+ fi
65
+ }
66
+
67
+ assert_false() {
68
+ local condition="$1"
69
+ local message="${2:-}"
70
+
71
+ ((TESTS_RUN++))
72
+
73
+ if ! eval "$condition"; then
74
+ ((TESTS_PASSED++))
75
+ echo -e "${GREEN}✓${NC} $message"
76
+ return 0
77
+ else
78
+ ((TESTS_FAILED++))
79
+ echo -e "${RED}✗${NC} $message"
80
+ echo -e " Condition should have failed: ${YELLOW}$condition${NC}"
81
+ FAILED_TESTS+=("$message")
82
+ return 1
83
+ fi
84
+ }
85
+
86
+ # Test suite header
87
+ print_suite_header() {
88
+ echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
89
+ echo -e "${BLUE}Testing: $1${NC}"
90
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}\n"
91
+ }
92
+
93
+ # Run test files
94
+ run_test_file() {
95
+ local test_file="$1"
96
+
97
+ if [[ -f "$test_file" && -x "$test_file" ]]; then
98
+ bash "$test_file"
99
+ else
100
+ echo -e "${YELLOW}Skipping $test_file (not found or not executable)${NC}"
101
+ fi
102
+ }
103
+
104
+ # Main test execution
105
+ main() {
106
+ echo -e "${BLUE}╔═══════════════════════════════════════╗${NC}"
107
+ echo -e "${BLUE}║ Library Unit Test Suite ║${NC}"
108
+ echo -e "${BLUE}╚═══════════════════════════════════════╝${NC}"
109
+
110
+ # Export test functions for use in test files
111
+ export -f assert_equals assert_true assert_false print_suite_header
112
+ export RED GREEN YELLOW BLUE NC
113
+ export LIB_DIR
114
+
115
+ # Run individual test files (sourced, not executed)
116
+ source "$SCRIPT_DIR/test_version.sh"
117
+ source "$SCRIPT_DIR/test_validation.sh"
118
+ source "$SCRIPT_DIR/test_git.sh"
119
+ source "$SCRIPT_DIR/test_changelog.sh"
120
+ source "$SCRIPT_DIR/test_gem.sh" # Summary
121
+ echo -e "\n${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
122
+ echo -e "${BLUE}Test Summary${NC}"
123
+ echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
124
+ echo -e "Total: $TESTS_RUN"
125
+ echo -e "${GREEN}Passed: $TESTS_PASSED${NC}"
126
+ echo -e "${RED}Failed: $TESTS_FAILED${NC}"
127
+
128
+ if [[ $TESTS_FAILED -gt 0 ]]; then
129
+ echo -e "\n${RED}Failed tests:${NC}"
130
+ for test in "${FAILED_TESTS[@]}"; do
131
+ echo -e " ${RED}✗${NC} $test"
132
+ done
133
+ exit 1
134
+ else
135
+ echo -e "\n${GREEN}All tests passed! 🎉${NC}"
136
+ exit 0
137
+ fi
138
+ }
139
+
140
+ main "$@"
@@ -0,0 +1,87 @@
1
+ #!/bin/bash
2
+
3
+ # Unit tests for changelog.sh library
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
7
+
8
+ # Set up test environment
9
+ export DRY_RUN=true
10
+ export INTERACTIVE=false
11
+ export VERBOSE=false
12
+
13
+ # Source the library
14
+ source "$LIB_DIR/changelog.sh"
15
+
16
+ print_suite_header "changelog.sh"
17
+
18
+ # Test: clean_commit_message
19
+ echo "Testing clean_commit_message..."
20
+
21
+ result=$(clean_commit_message "feat: add new feature")
22
+ assert_equals "Add new feature" "$result" "Clean 'feat:' prefix"
23
+
24
+ result=$(clean_commit_message "fix: resolve bug")
25
+ assert_equals "Resolve bug" "$result" "Clean 'fix:' prefix"
26
+
27
+ result=$(clean_commit_message "feat(scope): add scoped feature")
28
+ assert_equals "Add scoped feature" "$result" "Clean 'feat(scope):' prefix"
29
+
30
+ result=$(clean_commit_message "chore: update dependencies")
31
+ assert_equals "Update dependencies" "$result" "Clean 'chore:' prefix"
32
+
33
+ result=$(clean_commit_message "docs: improve readme")
34
+ assert_equals "Improve readme" "$result" "Clean 'docs:' prefix and capitalize"
35
+
36
+ result=$(clean_commit_message "regular commit message")
37
+ assert_equals "Regular commit message" "$result" "Capitalize regular message"
38
+
39
+ # Test: categorize_commit (requires git, so we test the logic patterns)
40
+ echo -e "\nTesting commit categorization patterns..."
41
+
42
+ # Simulate commit subjects for categorization
43
+ test_categorization() {
44
+ local subject="$1"
45
+ local expected="$2"
46
+
47
+ # Create temporary test function that returns category based on patterns
48
+ local subject_lower=$(echo "$subject" | tr '[:upper:]' '[:lower:]')
49
+ local category="other"
50
+
51
+ case "$subject_lower" in
52
+ feat:*|feature:*|add:*|new:*)
53
+ category="added"
54
+ ;;
55
+ fix:*|bugfix:*|bug:*|patch:*)
56
+ category="fixed"
57
+ ;;
58
+ *breaking*)
59
+ category="breaking"
60
+ ;;
61
+ perf:*|performance:*|refactor:*|style:*|docs:*|doc:*|test:*|chore:*|ci:*|build:*)
62
+ category="changed"
63
+ ;;
64
+ revert:*|remove:*|delete:*)
65
+ category="removed"
66
+ ;;
67
+ deprecate:*|deprecated:*)
68
+ category="deprecated"
69
+ ;;
70
+ security:*|sec:*)
71
+ category="security"
72
+ ;;
73
+ esac
74
+
75
+ assert_equals "$expected" "$category" "Categorize: '$subject' → $expected"
76
+ }
77
+
78
+ test_categorization "feat: new feature" "added"
79
+ test_categorization "fix: bug fix" "fixed"
80
+ test_categorization "chore: update" "changed"
81
+ test_categorization "docs: improve" "changed"
82
+ test_categorization "remove: old code" "removed"
83
+ test_categorization "security: patch vulnerability" "security"
84
+ test_categorization "BREAKING: major change" "breaking"
85
+ test_categorization "random commit" "other"
86
+
87
+ echo -e "\n${GREEN}changelog.sh tests complete${NC}"
@@ -0,0 +1,68 @@
1
+ #!/bin/bash
2
+
3
+ # Unit tests for gem.sh library
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
7
+
8
+ # Set up test environment
9
+ export DRY_RUN=true
10
+ export INTERACTIVE=false
11
+ export VERBOSE=false
12
+
13
+ # Source the library
14
+ source "$LIB_DIR/gem.sh"
15
+
16
+ print_suite_header "gem.sh"
17
+
18
+ # Test: gem_version_exists
19
+ echo "Testing gem_version_exists..."
20
+
21
+ # Test with a version that should exist (v1.0.0 is common)
22
+ if gem_version_exists "1.0.0" 2>/dev/null; then
23
+ echo -e "${YELLOW}ℹ${NC} Version 1.0.0 exists on RubyGems"
24
+ else
25
+ echo -e "${YELLOW}ℹ${NC} Version 1.0.0 does not exist on RubyGems"
26
+ fi
27
+
28
+ # Test with a version that definitely shouldn't exist
29
+ if gem_version_exists "999.999.999" 2>/dev/null; then
30
+ assert_false "true" "Non-existent version not found"
31
+ else
32
+ assert_false "false" "Non-existent version not found"
33
+ fi
34
+
35
+ # Test: Gem operations (dry run)
36
+ echo -e "\nTesting gem operations in dry run mode..."
37
+
38
+ # Test build_gem in dry run
39
+ if build_gem "1.0.0" 2>/dev/null; then
40
+ assert_true "true" "Dry run: build_gem"
41
+ else
42
+ assert_true "false" "Dry run: build_gem"
43
+ fi
44
+
45
+ # Test publish_gem in dry run
46
+ if publish_gem "1.0.0" 2>/dev/null; then
47
+ assert_true "true" "Dry run: publish_gem"
48
+ else
49
+ # May fail due to missing gem file, that's ok in dry run
50
+ echo -e "${YELLOW}ℹ${NC} Dry run: publish_gem (skipped - no gem file)"
51
+ fi
52
+
53
+ # Test create_github_release in dry run
54
+ if create_github_release "1.0.0" 2>/dev/null; then
55
+ assert_true "true" "Dry run: create_github_release"
56
+ else
57
+ # May fail if gh CLI not available, that's ok
58
+ echo -e "${YELLOW}ℹ${NC} Dry run: create_github_release (skipped - gh CLI may not be available)"
59
+ fi
60
+
61
+ # Test run_tests in dry run
62
+ if run_tests 2>/dev/null; then
63
+ assert_true "true" "Dry run: run_tests"
64
+ else
65
+ assert_true "false" "Dry run: run_tests"
66
+ fi
67
+
68
+ echo -e "\n${GREEN}gem.sh tests complete${NC}"
@@ -0,0 +1,82 @@
1
+ #!/bin/bash
2
+
3
+ # Unit tests for git.sh library
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
7
+
8
+ # Set up test environment
9
+ export DRY_RUN=true
10
+ export INTERACTIVE=false
11
+ export VERBOSE=false
12
+
13
+ # Source the library
14
+ source "$LIB_DIR/git.sh"
15
+
16
+ print_suite_header "git.sh"
17
+
18
+ # Test: get_current_branch
19
+ echo "Testing get_current_branch..."
20
+
21
+ current_branch=$(get_current_branch)
22
+ if [[ -n "$current_branch" ]]; then
23
+ assert_true "true" "Get current branch: $current_branch"
24
+ else
25
+ assert_true "false" "Get current branch"
26
+ fi
27
+
28
+ # Test: get_remote_url
29
+ echo -e "\nTesting get_remote_url..."
30
+
31
+ remote_url=$(get_remote_url "origin" 2>/dev/null)
32
+ if [[ -n "$remote_url" ]]; then
33
+ assert_true "true" "Get remote URL: $remote_url"
34
+ else
35
+ echo -e "${YELLOW}ℹ${NC} No remote URL found (may not be in git repo)"
36
+ fi
37
+
38
+ # Test: get_repo_info
39
+ echo -e "\nTesting get_repo_info..."
40
+
41
+ if [[ -n "$remote_url" ]]; then
42
+ repo_info=$(get_repo_info "origin" 2>/dev/null)
43
+ if [[ -n "$repo_info" ]]; then
44
+ assert_true "true" "Extract repo info: $repo_info"
45
+ else
46
+ echo -e "${YELLOW}ℹ${NC} Could not extract repo info from URL"
47
+ fi
48
+ fi
49
+
50
+ # Test: tag_exists
51
+ echo -e "\nTesting tag_exists..."
52
+
53
+ # Test with a tag that likely doesn't exist
54
+ if tag_exists "v999.999.999"; then
55
+ assert_false "true" "Non-existent tag not found"
56
+ else
57
+ assert_false "false" "Non-existent tag not found"
58
+ fi
59
+
60
+ # Test: get_last_version_tag
61
+ echo -e "\nTesting get_last_version_tag..."
62
+
63
+ last_tag=$(get_last_version_tag 2>/dev/null)
64
+ if [[ -n "$last_tag" ]]; then
65
+ assert_true "true" "Get last version tag: $last_tag"
66
+ else
67
+ echo -e "${YELLOW}ℹ${NC} No version tags found (using initial commit)"
68
+ fi
69
+
70
+ # Test: count_commits_since
71
+ echo -e "\nTesting count_commits_since..."
72
+
73
+ if [[ -n "$last_tag" ]]; then
74
+ commit_count=$(count_commits_since "$last_tag" 2>/dev/null)
75
+ if [[ "$commit_count" =~ ^[0-9]+$ ]]; then
76
+ assert_true "true" "Count commits since $last_tag: $commit_count"
77
+ else
78
+ assert_true "false" "Count commits returns number"
79
+ fi
80
+ fi
81
+
82
+ echo -e "\n${GREEN}git.sh tests complete${NC}"
@@ -0,0 +1,72 @@
1
+ #!/bin/bash
2
+
3
+ # Unit tests for validation.sh library
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
7
+
8
+ # Set up test environment
9
+ export DRY_RUN=true
10
+ export INTERACTIVE=false
11
+ export VERBOSE=false
12
+
13
+ # Source the library
14
+ source "$LIB_DIR/validation.sh"
15
+
16
+ print_suite_header "validation.sh"
17
+
18
+ # Test: validate_git_repo (should pass since we're in a git repo)
19
+ echo "Testing validate_git_repo..."
20
+
21
+ if validate_git_repo 2>/dev/null; then
22
+ assert_true "true" "Detects git repository"
23
+ else
24
+ assert_true "false" "Detects git repository"
25
+ fi
26
+
27
+ # Test: validate_required_files
28
+ echo -e "\nTesting validate_required_files..."
29
+
30
+ # This will fail if we're not in the project root, but that's expected for tests
31
+ if validate_required_files 2>/dev/null; then
32
+ assert_true "true" "Required files exist"
33
+ else
34
+ # If files don't exist (running from test dir), that's ok for unit tests
35
+ echo -e "${YELLOW}ℹ${NC} Required files check skipped (not in project root)"
36
+ fi
37
+
38
+ # Test: command_exists (from common.sh)
39
+ echo -e "\nTesting command_exists..."
40
+
41
+ if command_exists "git"; then
42
+ assert_true "true" "Git command exists"
43
+ else
44
+ assert_true "false" "Git command exists"
45
+ fi
46
+
47
+ if command_exists "bash"; then
48
+ assert_true "true" "Bash command exists"
49
+ else
50
+ assert_true "false" "Bash command exists"
51
+ fi
52
+
53
+ if command_exists "nonexistent_command_xyz"; then
54
+ assert_false "true" "Nonexistent command not found"
55
+ else
56
+ assert_false "false" "Nonexistent command not found"
57
+ fi
58
+
59
+ # Test: validate_dependencies
60
+ echo -e "\nTesting validate_dependencies..."
61
+
62
+ # Test that common dependencies are found
63
+ common_commands=("git" "ruby" "bundle" "jq")
64
+ for cmd in "${common_commands[@]}"; do
65
+ if command_exists "$cmd"; then
66
+ assert_true "true" "Required command exists: $cmd"
67
+ else
68
+ echo -e "${YELLOW}ℹ${NC} Optional command not found: $cmd (skipping)"
69
+ fi
70
+ done
71
+
72
+ echo -e "\n${GREEN}validation.sh tests complete${NC}"
@@ -0,0 +1,96 @@
1
+ #!/bin/bash
2
+
3
+ # Unit tests for version.sh library
4
+
5
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
+ LIB_DIR="$(dirname "$SCRIPT_DIR")"
7
+
8
+ # Set up test environment
9
+ export DRY_RUN=true
10
+ export INTERACTIVE=false
11
+ export VERBOSE=false
12
+
13
+ # Source the library
14
+ source "$LIB_DIR/version.sh"
15
+
16
+ print_suite_header "version.sh"
17
+
18
+ # Test: validate_version_format
19
+ echo "Testing validate_version_format..."
20
+
21
+ valid_versions=("0.0.1" "1.0.0" "10.20.30" "999.999.999")
22
+ for version in "${valid_versions[@]}"; do
23
+ if validate_version_format "$version" 2>/dev/null; then
24
+ assert_true "true" "Valid version format accepted: $version"
25
+ else
26
+ assert_true "false" "Valid version format accepted: $version"
27
+ fi
28
+ done
29
+
30
+ invalid_versions=("1.0" "1.0.0.0" "v1.0.0" "1.0.0-beta" "abc.def.ghi")
31
+ for version in "${invalid_versions[@]}"; do
32
+ if validate_version_format "$version" 2>/dev/null; then
33
+ assert_false "true" "Invalid version format rejected: $version"
34
+ else
35
+ assert_false "false" "Invalid version format rejected: $version"
36
+ fi
37
+ done
38
+
39
+ # Test: calculate_new_version
40
+ echo -e "\nTesting calculate_new_version..."
41
+
42
+ result=$(calculate_new_version "1.2.3" "patch")
43
+ assert_equals "1.2.4" "$result" "Patch bump: 1.2.3 → 1.2.4"
44
+
45
+ result=$(calculate_new_version "1.2.3" "minor")
46
+ assert_equals "1.3.0" "$result" "Minor bump: 1.2.3 → 1.3.0"
47
+
48
+ result=$(calculate_new_version "1.2.3" "major")
49
+ assert_equals "2.0.0" "$result" "Major bump: 1.2.3 → 2.0.0"
50
+
51
+ result=$(calculate_new_version "0.0.9" "patch")
52
+ assert_equals "0.0.10" "$result" "Patch bump with digit rollover: 0.0.9 → 0.0.10"
53
+
54
+ result=$(calculate_new_version "0.9.9" "minor")
55
+ assert_equals "0.10.0" "$result" "Minor bump resets patch: 0.9.9 → 0.10.0"
56
+
57
+ result=$(calculate_new_version "9.9.9" "major")
58
+ assert_equals "10.0.0" "$result" "Major bump resets minor and patch: 9.9.9 → 10.0.0"
59
+
60
+ # Test: version_less_than
61
+ echo -e "\nTesting version_less_than..."
62
+
63
+ if version_less_than "1.0.0" "2.0.0"; then
64
+ assert_true "true" "1.0.0 < 2.0.0"
65
+ else
66
+ assert_true "false" "1.0.0 < 2.0.0"
67
+ fi
68
+
69
+ if version_less_than "1.2.3" "1.2.4"; then
70
+ assert_true "true" "1.2.3 < 1.2.4"
71
+ else
72
+ assert_true "false" "1.2.3 < 1.2.4"
73
+ fi
74
+
75
+ if version_less_than "2.0.0" "1.0.0"; then
76
+ assert_false "true" "2.0.0 not < 1.0.0"
77
+ else
78
+ assert_false "false" "2.0.0 not < 1.0.0"
79
+ fi
80
+
81
+ if version_less_than "1.2.3" "1.2.3"; then
82
+ assert_false "true" "1.2.3 not < 1.2.3 (equal)"
83
+ else
84
+ assert_false "false" "1.2.3 not < 1.2.3 (equal)"
85
+ fi
86
+
87
+ # Test: get_version_from_tag
88
+ echo -e "\nTesting get_version_from_tag..."
89
+
90
+ result=$(get_version_from_tag "v1.2.3")
91
+ assert_equals "1.2.3" "$result" "Remove 'v' prefix: v1.2.3 → 1.2.3"
92
+
93
+ result=$(get_version_from_tag "1.2.3")
94
+ assert_equals "1.2.3" "$result" "No prefix to remove: 1.2.3 → 1.2.3"
95
+
96
+ echo -e "\n${GREEN}version.sh tests complete${NC}"
@@ -0,0 +1,139 @@
1
+ #!/bin/bash
2
+
3
+ # Validation library for zer0-mistakes release scripts
4
+ # Provides environment, git, and dependency validation functions
5
+
6
+ # Source common utilities
7
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
+ source "$SCRIPT_DIR/common.sh"
9
+
10
+ # Validate git repository
11
+ validate_git_repo() {
12
+ debug "Validating git repository..."
13
+
14
+ if ! git rev-parse --git-dir > /dev/null 2>&1; then
15
+ error "Not in a git repository"
16
+ fi
17
+
18
+ debug "✓ Git repository validated"
19
+ }
20
+
21
+ # Validate working directory is clean
22
+ validate_clean_working_dir() {
23
+ debug "Validating clean working directory..."
24
+
25
+ if [[ -n $(git status --porcelain) ]]; then
26
+ error "Working directory is not clean. Please commit or stash changes first."
27
+ fi
28
+
29
+ debug "✓ Working directory is clean"
30
+ }
31
+
32
+ # Validate required files exist
33
+ validate_required_files() {
34
+ debug "Validating required files..."
35
+
36
+ local required_files=(
37
+ "lib/jekyll-theme-zer0/version.rb"
38
+ "jekyll-theme-zer0.gemspec"
39
+ "CHANGELOG.md"
40
+ )
41
+
42
+ for file in "${required_files[@]}"; do
43
+ require_file "$file"
44
+ done
45
+
46
+ debug "✓ All required files present"
47
+ }
48
+
49
+ # Validate required commands
50
+ validate_dependencies() {
51
+ debug "Validating dependencies..."
52
+
53
+ require_command "git" "Install from https://git-scm.com/"
54
+ require_command "ruby" "Install from https://www.ruby-lang.org/"
55
+ require_command "gem" "Comes with Ruby"
56
+ require_command "bundle" "Install with: gem install bundler"
57
+ require_command "jq" "Install with: brew install jq (macOS) or apt-get install jq (Linux)"
58
+
59
+ debug "✓ All dependencies available"
60
+ }
61
+
62
+ # Validate RubyGems authentication
63
+ validate_rubygems_auth() {
64
+ local skip_publish="${1:-false}"
65
+
66
+ if [[ "$skip_publish" == "true" ]]; then
67
+ debug "Skipping RubyGems auth validation (publish not required)"
68
+ return 0
69
+ fi
70
+
71
+ debug "Validating RubyGems authentication..."
72
+
73
+ if [[ ! -f ~/.gem/credentials ]]; then
74
+ error "Not authenticated with RubyGems. Run 'gem signin' first."
75
+ fi
76
+
77
+ debug "✓ RubyGems authentication present"
78
+ }
79
+
80
+ # Validate gemspec can be parsed
81
+ validate_gemspec() {
82
+ debug "Validating gemspec..."
83
+
84
+ if ! ruby -c jekyll-theme-zer0.gemspec > /dev/null 2>&1; then
85
+ error "Invalid gemspec: jekyll-theme-zer0.gemspec"
86
+ fi
87
+
88
+ debug "✓ Gemspec is valid"
89
+ }
90
+
91
+ # Validate GitHub CLI availability
92
+ validate_github_cli() {
93
+ local required="${1:-false}"
94
+
95
+ if command_exists "gh"; then
96
+ debug "✓ GitHub CLI (gh) available"
97
+ return 0
98
+ fi
99
+
100
+ if [[ "$required" == "true" ]]; then
101
+ error "GitHub CLI (gh) is required. Install from https://cli.github.com/"
102
+ else
103
+ warn "GitHub CLI (gh) not found. GitHub releases will be skipped."
104
+ return 1
105
+ fi
106
+ }
107
+
108
+ # Comprehensive environment validation
109
+ validate_environment() {
110
+ local skip_publish="${1:-false}"
111
+ local require_gh="${2:-false}"
112
+
113
+ step "Validating environment..."
114
+
115
+ validate_git_repo
116
+ validate_clean_working_dir
117
+ validate_required_files
118
+ validate_dependencies
119
+ validate_gemspec
120
+ validate_rubygems_auth "$skip_publish"
121
+
122
+ if [[ "$require_gh" == "true" ]]; then
123
+ validate_github_cli true
124
+ else
125
+ validate_github_cli false
126
+ fi
127
+
128
+ success "Environment validation complete"
129
+ }
130
+
131
+ # Export functions
132
+ export -f validate_git_repo
133
+ export -f validate_clean_working_dir
134
+ export -f validate_required_files
135
+ export -f validate_dependencies
136
+ export -f validate_rubygems_auth
137
+ export -f validate_gemspec
138
+ export -f validate_github_cli
139
+ export -f validate_environment