-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.clog.yaml
More file actions
144 lines (137 loc) · 5.1 KB
/
Copy path.clog.yaml
File metadata and controls
144 lines (137 loc) · 5.1 KB
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
134
135
136
137
138
139
140
141
142
143
144
# ____ _ _
# _ __ _ _ __ __ ___ __ |__ / ___ | |_ | |__
# | ' \ | '_| \ \ / |___| / _| |_ \ |___| | _| | / /
# |_|_|_| |_| /_\_\ \__| |___/ \__| |_\_\
clog:
# path to the yaml file defining release history - see semver package
releases-path: "releases.yaml"
snippets:
# --- build commands --------------------------------------------------------
build: |
eval "$(clog Crayon)"
clog BC is build prod && IS_PROD=1 || IS_PROD=0
[ "$IS_PROD" -eq 1 ] && clog Log -I "Production Build" || clog Log -I "Dev Build ($(clog BC releases build),$(clog BC releases flow))"
# check all tools required by this build script are available
check_tools() {
local _missing=0
for _tool in clog diff pnpm go sudo; do
command -v "$_tool" >/dev/null 2>&1 || { clog Log -W "$_tool tool not installed"; _missing=1; }
done
return $_missing
}
check_tools || exit 1
# check for drift between root config/ and embedded defaults
check_config_drift() {
local _n
_n=$(diff -rq config c3-lib/embedfilesystem/config 2>/dev/null | wc -l | tr -d ' ')
[ "$_n" -gt 0 ] && clog Log -W "$_n config file(s) differ — view: diff -rq config c3-lib/embedfilesystem/config" || clog Log -S "config embed is in sync with root config"
}
check_config_drift
# check for drift between docs/ and embedded copy in c3-app/ui/docs/
check_docs_drift() {
local _embed_dir="c3-app/ui/docs"
if [ ! -d "$_embed_dir" ]; then
if [ "$IS_PROD" -eq 1 ]; then
clog Log -E "docs not embedded — run 'clog clonedocs' first"
exit 1
fi
clog Log -W "docs not embedded — run 'clog clonedocs' to populate $_embed_dir/"
return
fi
local _n=0
for _f in docs/*.md; do
diff -q "$_f" "$_embed_dir/$(basename "$_f")" >/dev/null 2>&1 || _n=$((_n+1))
done
if [ "$_n" -gt 0 ]; then
if [ "$IS_PROD" -eq 1 ]; then
clog Log -E "$_n doc(s) differ from embedded copy — run 'clog clonedocs'"
exit 1
fi
clog Log -W "$_n doc(s) differ — view: diff -rq docs/ $_embed_dir/"
clog Log -W " fix: clog clonedocs"
else
clog Log -S "docs embed is in sync"
fi
}
check_docs_drift
# 1. build svelte app first
_SVELTE_LOG="svelte/tmp-build.log"
scan_svelte_log() {
local _first
_first=$(grep -i 'error\|failed' "tmp-build.log" 2>/dev/null | grep -vim1 '[./]error')
if [ -n "$_first" ]; then
clog Log -E "$_first [$_SVELTE_LOG]"
return
fi
_first=$(grep -i 'warn' "tmp-build.log" 2>/dev/null | grep -vim1 '[./]warn')
if [ -n "$_first" ]; then
clog Log -W "$_first [$_SVELTE_LOG]"
return
fi
clog Log -S "success [$_SVELTE_LOG]"
}
cd "svelte"
clog Log -I "building svelte in folder $cF$(pwd)"
pnpm install > tmp-build.log 2>&1
_rc=$? ; [ $_rc -gt 0 ] && clog Log -E "pnpm install failed" && exit 1
pnpm run build >> tmp-build.log 2>&1
_rc=$? ; [ $_rc -gt 0 ] && clog Log -E "svelte build failed"
scan_svelte_log
[ $_rc -gt 0 ] && exit 1
clog Log -I "Continuing..."
if [ "$IS_PROD" -eq 1 ]; then
clog Log -I "running svelte tests"
pnpm run test
[ $? -gt 0 ] && clog Log -E "svelte tests failed" && exit 1
fi
cd ..
# 2. build go app
cd "c3-app"
clog Log -I "building in folder $cF$(pwd)"
if [ "$IS_PROD" -eq 1 ]; then
clog Log -I "running go vet"
go vet ./...
[ $? -gt 0 ] && clog Log -E "go vet failed" && exit 1
clog Log -I "running go tests"
go test ./...
[ $? -gt 0 ] && clog Log -E "go tests failed" && exit 1
fi
go build -o c3 .
[ $? -gt 0 ] && clog Log -E "build failed" && exit 1
sudo install -m 755 c3 /usr/local/bin/c3
clog Log -I "$cF/usr/local/bin/c3$cX updated"
cd ..
fmt: |
eval "$(clog Crayon)"
cd c3-app
clog Log -I "formatting golang in folder $cF$(pwd)"
go fmt ./...
cd ..
clonedocs: |
eval "$(clog Crayon)"
clog Log -I "cloning docs/*.md to c3-app/ui/docs/"
rm -rf c3-app/ui/docs && mkdir -p c3-app/ui/docs
cp docs/*.md c3-app/ui/docs/
clog Log -S "docs cloned to c3-app/ui/docs/"
project:
config: |
# make some variables for standard build scripts
export PROJECT="$(basename $(pwd))" # project you're building
has:
git-lfs: |
git lfs version 2>/dev/null|grep -oE '[0-9]+\.[0-9]+\.[0-9]+'|head -1
golang: go version|grep -oE '[0-9]+\.[0-9]+\.[0-9]+'
needs:
git-lfs: echo "3.7.0"
# grab the golang version from go.mod
golang: cat go.mod|grep '^go '|grep -oE '[0-9]\.[0-9]+\.[0-9]+'
# hunt for the hugo version
hugo: |
# grab the version from configuration
if [ -f hugo.yaml ];then
yq -r '.module.hugoVersion.min' hugo.yaml
elif [ -f config/_default/module.yaml ];then
yq -r '.hugoVersion.min' config/_default/module.yaml
else
echo "hugo config not found"
fi