-
Notifications
You must be signed in to change notification settings - Fork 0
/
tusk.yml
155 lines (132 loc) · 4.32 KB
/
tusk.yml
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
145
146
147
148
149
150
151
152
153
154
155
interpreter: bash -c
name: devtool
usage: conveniences and ergonomics for chaintrap-contracts
# tusk is for things that are useful to clients of this repository. or any
# script like things that *usually* can't avoid sort of optionality. Any time
# you think of writing a script with options make a task instead.
options:
node-hostname:
default: "0.0.0.0"
node-port:
default: "8545"
node-address:
short: "a"
default: "http://localhost:8545"
localdir:
short: d
default: .local/hh
launchdir:
# this is a go-tusk quirk
environment: PWD
tasks:
version-update:
usage: |
increates the version number in package.json
options:
minor:
short: m
type: bool
message:
default: ""
nocommit:
short: C
type: bool
nopush:
short: P
type: bool
run:
- command:
exec: |
CUR_VERSION=$(cat <<PYEND | python3
import json
pkg = json.load(open('package.json', 'r'))
print(pkg['version'])
PYEND
)
VERSION=$(cat <<PYEND | python3
import json
pkg = json.load(open('package.json', 'r'))
ver = list(map(int, pkg['version'].split('.')))
which = -1
if "${minor}" == "true":
which = 1
ver[which] = ver[which] + 1
if which == 1:
ver[2] = 0
VERSION='.'.join(map(str, ver))
with open('package.json.new', 'w') as f:
pkg['version'] = VERSION
json.dump(pkg, f, indent=2)
print(VERSION)
PYEND
)
cp package.json.new package.json
rm package.json.new
git status -s | egrep "^\?\?" && echo "untracked files" && exit 1
git add .
echo ".........................."
echo "v$CUR_VERSION => v$VERSION ${message}"
echo ".........................."
${nocommit} && exit 0
git commit -m "release:v$VERSION ${message}"
git tag -a v$VERSION -m "release:v$VERSION ${message}"
! ${nopush} && git push --tags
stop-node:
usage: |
stop (if possible) the hardhat node started via start-node
run:
- command:
exec: |
LOCALDIR=$(cd ${launchdir} && pwd)/${localdir}
[ ! -f $LOCALDIR/hh-pid ] && exit 0
kill -KILL $(cat $LOCALDIR/hh-pid) || true
start-node:
usage: |
start (if necessary) a hardhat node listenting on ${node-address}
options:
gasprice:
short: g
default: 0
localdir:
short: d
default: .local/hh
run:
- command:
exec: |
LOCALDIR=$(cd ${launchdir} && pwd)/${localdir}
HOSTNAME=${node-hostname}
PORT=${node-port}
mkdir -p ${LOCALDIR}
# Start the hardhat node
if ! lsof -i -P -n | grep LISTEN | grep :$PORT >> /dev/null 2>&1; then
npx hardhat node --hostname "$HOSTNAME" --port $PORT >> ${LOCALDIR}/hh-log & 2>&1
else
echo "re-using service"
fi
# Wait for hardhat to be ready (assumes it is hardhat on the port)
while ! lsof -i -P -n | grep LISTEN | grep :$PORT >> /dev/null 2>&1; do
echo "waiting for the hardhat node to listen on :$PORT"
sleep "5";
done
PID=$(lsof -i -P -n | grep LISTEN | grep :$PORT | tr -s ' ' | cut -d ' ' -f2)
echo "service up on $PORT (PID: $PID)"
echo $PID > ${LOCALDIR}/hh-pid
deploy-local:
usage: |
deploy contracts to local hardhat node
and generate a browser localstorage value containing the contracts abi and
localnode provider address
options:
hhexport:
usage: filename for --export argument to npx hardhat deploy
short: "f"
default: "tests/hh-deploy.json"
run:
- command:
exec: |
set -e
# interperet files on the command line relative to the launchdir
STORAGEFILE=$(cd ${launchdir} && pwd)/${hhexport}
mkdir -p $(dirname $STORAGEFILE)
npx hardhat deploy --export $STORAGEFILE >> /dev/null 2>&1
echo "Wrote: $STORAGEFILE"