forked from stratum-mining/stratum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sv2-header-check.sh
executable file
·45 lines (39 loc) · 1.34 KB
/
sv2-header-check.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
#! /usr/bin/sh
#
# This program ensures that the `sv2.h` file generated by `build_header.sh` for the submitted PR is
# in sync with the `sv2.h` file committed to `protocols/v2/sv2-ffi`. If they are out of sync, the
# GitHub Action will fail, preventing the PR from being merged.
#
# This script does the following:
# (1) installs `cbindgen` which is a dependency of `build_header.sh`
# (2) takes the SHA1 hash of the `sv2.h` file in `protocols/v2/sv2-ffi`
# (3) executes `build_header.sh` to generate the `sv2.h` based on the contents of the PR
# (4) takes the SHA1 hash of the `sv2.h` file generated by `build_header.sh`
# (5) compares the hashes of each `sv2.h`, if they are equal then the GitHub Action passes, otherwise
# the GitHub Action fails
#
# This script is called by `.github/workflows/sv2-header-check.yaml` on every PR onto the main branch.
#
cargo install --version 0.20.0 cbindgen
set -ex
# cargo install cbindgen --force bts
# cbindgen -V
cd ./protocols/v2/sv2-ffi
SHA1_1=$(sha1sum sv2.h)
cd ../../..
BUILD_SCRIPT="./build_header.sh"
sh ./"$BUILD_SCRIPT"
SHA1_2=$(sha1sum sv2.h)
if [ "$SHA1_1" = "$SHA1_2" ];
then
echo "Success. sv2.h files match."
echo $SHA1_1
exit 0
else
echo "Fail. sv2.h files do not match."
echo "./protocols/v2/sv2-ffi/sv2.h hash:"
echo $SHA1_1
echo "./sv2.h hash:"
echo $SHA1_2
exit -1
fi