forked from stylemistake/runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunnerfile.sh
85 lines (72 loc) · 1.74 KB
/
runnerfile.sh
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
#!/usr/bin/env bash
source_files=(bin/runner src/*.sh runnerfile.sh)
publish_files=(bin completion src LICENSE.md README.md VERSION)
task_default() {
runner_parallel shellcheck test
}
task_shellcheck() {
runner_run shellcheck --exclude=SC2016,SC2155,SC2164 "${source_files[@]}"
}
task_test() {
bash test/test.sh >/dev/null
}
task_readme() {
doctoc README.md
}
task_clean() {
git clean -dxf
}
task_update-version() {
# $1 should be "--major", "--minor", or "--patch"
local level="patch"
case "${1}" in
--major) level="major" ;;
--minor) level="minor" ;;
--patch) level="patch" ;;
esac
local awk_prog='{
fields["major"]=$1;
fields["minor"]=$2;
fields["patch"]=$3;
fields["'${level}'"]++;
} END {
print fields["major"] + 0 "." fields["minor"] "." fields["patch"];
}'
local next_tag
next_tag="$(awk -F '.' "${awk_prog}" < VERSION)"
runner_log "Next version: ${next_tag}"
## Write VERSION file
runner_log "Updating VERSION"
echo "${next_tag}" > VERSION;
## Update package.json
if runner_is_defined npm; then
runner_log "Updating package.json"
enter-dir distrib/npm
runner_run npm version "${next_tag}"
leave-dir
else
runner_log_warning "Missing 'npm', skipping..."
fi
}
task_publish-npm() {
runner_sequence clean
rsync -a --relative "${publish_files[@]}" distrib/npm
enter-dir distrib/npm
npm publish || return "${?}"
leave-dir
}
## Utility functions
## --------------------------------------------------------
dir_stack=()
enter-dir() {
local path="${1}"
dir_stack+=("${path}")
runner_log "Entering '${path}'"
pushd "${path}" >/dev/null
}
leave-dir() {
local path="${dir_stack[-1]}"
unset 'dir_stack[-1]'
runner_log "Leaving '${path}'"
popd >/dev/null
}