aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/.ci/local/test.sh
blob: e7cd2c70134a6a3b200ca5e32553e4eb100acf8d (plain) (blame)
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
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail

local_repo_path=
readonly cgitize_conf_path="$HOME/etc/cgitize/cgitize.conf"
readonly my_repos_path="$HOME/etc/cgitize/my_repos.py"
readonly output_path="$HOME/var/cgitize/output"

cleanup() {
    echo
    echo ----------------------------------------------------------------------
    echo Cleaning up
    echo ----------------------------------------------------------------------

    rm -rf -- "$local_repo_path"
}

setup_local_repo() {
    echo
    echo ----------------------------------------------------------------------
    echo Setting up upstream repository
    echo ----------------------------------------------------------------------

    local_repo_path="$( mktemp -d )"
    pushd -- "$local_repo_path" > /dev/null

    git init
    echo '1' > 1.txt
    git add .
    git commit -m 'first commit'
    echo '2' > 2.txt
    git add .
    git commit -m 'second commit'

    popd > /dev/null
}

setup_cgitize_conf() {
    echo
    echo ----------------------------------------------------------------------
    echo cgitize.conf
    echo ----------------------------------------------------------------------

    local conf_dir
    conf_dir="$( dirname -- "$cgitize_conf_path" )"
    mkdir -p -- "$conf_dir"

    cat <<EOF | tee "$cgitize_conf_path"
[DEFAULT]

my_repos = $( basename -- "$my_repos_path" )
output = $output_path
EOF
}

setup_my_repos_py() {
    echo
    echo ----------------------------------------------------------------------
    echo my_repos.py
    echo ----------------------------------------------------------------------

    local conf_dir
    conf_dir="$( dirname -- "$my_repos_path" )"
    mkdir -p -- "$conf_dir"

    cat <<EOF | tee "$my_repos_path"
from cgitize.repo import Repo


MY_REPOS = (
    Repo('test_repo', clone_url='$local_repo_path'),
)
EOF
}

setup_cgitize() {
    setup_cgitize_conf
    setup_my_repos_py
}

setup() {
    setup_local_repo
    setup_cgitize
}

run() {
    echo
    echo ----------------------------------------------------------------------
    echo Pulling repository from upstream
    echo ----------------------------------------------------------------------

    python3 -m cgitize.main --config "$cgitize_conf_path"
}

verify() {
    echo
    echo ----------------------------------------------------------------------
    echo Checking the pulled repository
    echo ----------------------------------------------------------------------

    pushd -- "$output_path" > /dev/null
    cd -- test_repo
    git log --oneline
    popd > /dev/null
}

main() {
    trap cleanup EXIT
    setup
    run
    verify
}

main