File: run.sh

package info (click to toggle)
python-semantic-release 10.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 3,112 kB
  • sloc: python: 36,523; sh: 340; makefile: 156
file content (133 lines) | stat: -rw-r--r-- 3,797 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash

set -eu

if ! command -v realpath &>/dev/null; then
    realpath() {
        readlink -f "$1"
    }
fi

TEST_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"
PROJ_DIR="$(realpath "$(dirname "$TEST_DIR")/..")"
EXAMPLE_PROJECT_BASE_DIR="${EXAMPLE_PROJECT_BASE_DIR:-"$TEST_DIR/example_project"}"

if [ -z "${UTILS_LOADED:-}" ]; then
    # shellcheck source=tests/utils.sh
    source "$TEST_DIR/utils.sh"
fi

create_example_project() {
    local EXAMPLE_PROJECT_DIR="$1"

    log "Creating example project in: $EXAMPLE_PROJECT_DIR"
    mkdir -vp "$(dirname "$EXAMPLE_PROJECT_DIR")"
    cp -r "${EXAMPLE_PROJECT_BASE_DIR}" "$EXAMPLE_PROJECT_DIR"

    log "Constructing git history in repository"
    pushd "$EXAMPLE_PROJECT_DIR" >/dev/null || return 1

    # Initialize and configure git (remove any signature requirements)
    git init
    git config --local user.email "developer@users.noreply.github.com"
    git config --local user.name "developer"
    git config --local commit.gpgSign false
    git config --local tag.gpgSign false
    git remote add origin "https://github.com/python-semantic-release/example-project.git"

    # Create initial commit and tag
    git add .
    git commit -m "Initial commit"

    # set default branch to main
    git branch -m main

    # Create the first release (with commit & tag)
    cat <<EOF >pyproject.toml
[project]
name = "example"
version = "1.0.0"
description = "Example project"
EOF
    git commit -am '1.0.0'
    git tag -a v1.0.0 -m "v1.0.0"

    popd >/dev/null || return 1
    log "Example project created successfully"
}

# ------------------------------
# TEST SUITE DRIVER
# ------------------------------

run_test_suite() {
    local ALL_TEST_FNS

    # Dynamically import all test scripts
    for test_script in "$TEST_DIR"/suite/test_*.sh; do
        if [ -f "$test_script" ]; then
            if ! source "$test_script"; then
                error "Failed to load test script: $test_script"
            fi
        fi
    done

    # Extract all test functions
    tests_in_env="$(compgen -A function | grep "^test_")"
    read -r -a ALL_TEST_FNS <<< "$(printf '%s' "$tests_in_env" | tr '\n' ' ')"

    log ""
    log "************************"
    log "*  Running test suite  *"
    log "************************"

    # Incrementally run all test functions and flag if any fail
    local test_index=1
    local test_failures=0
    for test_fn in "${ALL_TEST_FNS[@]}"; do
        if command -v "$test_fn" &>/dev/null; then
            if ! "$test_fn" "$test_index"; then
                ((test_failures++))
            fi
        fi
        log "--------------------------------------------------------------------------------"
        ((test_index++))
    done

    log ""
    log "************************"
    log "*     Test Summary     *"
    log "************************"
    log ""
    log "Total tests executed: ${#ALL_TEST_FNS[@]}"
    log "Successes: $((${#ALL_TEST_FNS[@]} - test_failures))"
    log "Failures: $test_failures"

    if [ "$test_failures" -gt 0 ]; then
        return 1
    fi
}

# ------------------------------
# MAIN
# ------------------------------

log "================================================================================"
log "||                      PSR Version Action Test Runner                        ||"
log "================================================================================"
log "Initializing..."

# Make absolute path to project directory
PROJECT_MOUNT_DIR="${PROJ_DIR:?}/${PROJECT_MOUNT_DIR:?}"

log ""
log "******************************"
log "*  Running test suite setup  *"
log "******************************"
log ""

# Setup project environment
create_example_project "$PROJECT_MOUNT_DIR"
trap 'rm -rf "${PROJECT_MOUNT_DIR:?}"' EXIT

run_test_suite