-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdiff_check.sh
executable file
·95 lines (89 loc) · 2.85 KB
/
diff_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
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
#!/bin/bash
set -eu
if [[ $1 == "--help" ]]; then
grep -e '^##' $0 | cut -d ' ' -f 2-
exit 0
fi
deleteContent="yes"
if [[ "$1" == "-c" ]]; then
echo "Branch content will not be deleted"
deleteContent="no"
branchName=$2
gardenerRemote=$3
websitePath=$4
else
branchName=$1
gardenerRemote=$2
websitePath=$3
fi
# check if branch exists
if [[ -z $(git branch | grep -e "[[:space:]]${branchName}$") ]]; then
echo "Branch does not exist"
exit 1
fi
if [[ -z $(git remote | grep -x "${gardenerRemote}") ]]; then
echo "Remote does not exist"
exit 1
fi
if [[ ! -d "${websitePath}/hugo" ]]; then
echo "Website path does not exits or does not contain hugo folder"
exit 1
fi
# get current branch
currentBranch=$(git rev-parse --abbrev-ref HEAD)
# building branch docforge
git checkout $branchName
make build-local
mv bin/docforge /usr/local/bin
# building branch content
cd $websitePath
make build
# deleting old branchContent
rm -rf hugo/branchContent
mv hugo/content hugo/branchContent
# fetch latest origin/master
cd -
git fetch --all
# building master docforge
git checkout "${gardenerRemote}/master"
make build-local
mv bin/docforge /usr/local/bin
# building master content
cd $websitePath
make build
# comparing contents
echo "-------------------------------"
echo "Diff results"
find hugo/content -type f -exec sed -E -i 's@_.{6}\.(png|jpg|jpeg|svg|gif)@.\1@g' {} \;
find hugo/branchContent -type f -exec sed -E -i 's@_.{6}\.(png|jpg|jpeg|svg|gif)@.\1@g' {} \;
diff -r --exclude=__resources hugo/content hugo/branchContent
echo "-------------------------------"
# dele branch content if needed
if [[ "$deleteContent" == "yes" ]]; then
rm -rf hugo/branchContent
fi
# return to current branch
cd -
git checkout "$currentBranch"
## A tool for MacOS/Linux(not tested on linux) that compares the differences between generated content of a local docforge PR branch and the master branch:
##
##
## ./diff_check.sh [-c] <local_PR_branch> <remote_name_of_gardener_repo> <path_to_website_generator>
##
##
## With following parameters:
##
## -c
## Optional flag. If present hugo/branchContent directory will not be deleted from website generator folder after tool execution. If flag is omitted the directory will be deleted
##
## local_PR_branch
## The branch name of the PR
##
## remote_name_of_gardener_repo
## Depending from where you have cloned docforge (gardener or your github fork) this most like will be 'origin' or 'upstream'
##
## path_to_website_generator
## Local path of website generator where content will be generated from 'make build'. Note that the path should contain a 'hugo' folder with a 'content' subfolder and have a 'make build' command defined
##
## Note: after tool execution docforge binary in /usr/local/bin will be overwritten with the binary of the gardener master branch
##