-
Notifications
You must be signed in to change notification settings - Fork 8
/
bdocs
executable file
·121 lines (107 loc) · 3.37 KB
/
bdocs
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
#!/bin/bash
# This is a wrapper script for interacting with the files in './scripts/'.
#
# Usage: ./bdocs [option]
set -e
# The project's root directory and redirect file.
export PROJECT_ROOT="$(dirname "$(realpath "$0")")"
export REDIRECT_FILE="./assets/js/broken_redirect_list.js"
export REDIRECT_MATCHES="./scripts/temp/redirect_matches.json"
# All scripts exported so they can source bdocs and call each other if needed.
export DEPLOY="$PROJECT_ROOT/scripts/create_deploy_text.sh"
export RELEASE="$PROJECT_ROOT/scripts/create_release_text.sh"
export TLINKS="$PROJECT_ROOT/scripts/transform_reference_links.py"
export RLINKS="$PROJECT_ROOT/scripts/remove_unused_reference_links.rb"
export ULINKS="$PROJECT_ROOT/scripts/update_old_links.py"
export LREDIRECTS="$PROJECT_ROOT/scripts/list_new_redirect_urls.sh"
# Utility scripts that are not directly used in bdocs:
export MRD="$PROJECT_ROOT/scripts/utils/merge_redirect_descendants.py"
export TEMP_DIR="$PROJECT_ROOT/scripts/temp"
# Displays usage for bdocs
display_help() {
cat << EOF
bdocs is a CLI tool for executing Braze Docs scripts.
USAGE:
./bdocs [option]
OPTIONS:
deploy Create the deploy body text for weekly deployments
release Create the release body text for monthly releases
tlinks Transform reference links to inline links on 1 or more pages
rlinks Remove unused reference links on 1 or more pages
ulinks Update old links using newest redirect on 1 or more pages
lredirects Test new redirects by listing old URLs in this branch
help Display this help message and exit
EOF
}
# If no './scripts/temp' directory, create one.
if [ ! -d "$TEMP_DIR" ]; then
mkdir "$TEMP_DIR"
fi
# If a file or directory is required, pass or fail.
require_path_or_file() {
if [[ -z "$1" ]]; then
echo "Error: A file or directory path is required."
exit 1
fi
}
# If new merges into 'develop' are required, pass or fail.
require_new_merges() {
LATEST_COMMIT_HASH=$(git log --max-count=1 --format="%H" origin/master ^origin/develop)
COMMIT_LOGS=$(git log --first-parent "$LATEST_COMMIT_HASH"..origin/develop)
if [ -z "$COMMIT_LOGS" ]; then
echo "Error: No new merges into 'develop' since the last deployment."
exit 1
fi
}
# Check if no arguments were provided
if [[ $# -eq 0 ]]; then
display_help
exit 1
fi
# Fetch the latest changes from the remote quietly.
git fetch origin develop --quiet
# Argument parsing
case $1 in
deploy)
require_new_merges
if [[ $# -eq 3 ]]; then
"$DEPLOY" "$2" "$3"
else
"$DEPLOY"
fi
;;
release)
require_new_merges
"$RELEASE"
;;
tlinks)
require_path_or_file "$2"
"$TLINKS" "$2"
"$RLINKS" "$2" # Run rlinks next, to clean up unused reference links.
;;
rlinks)
require_path_or_file "$2"
"$RLINKS" "$2"
;;
ulinks)
require_path_or_file "$2"
touch "$REDIRECT_MATCHES"
"$MRD"
"$ULINKS" "$2"
# rm "$REDIRECT_MATCHES"
;;
lredirects)
if [[ $# -eq 2 ]]; then
"$LREDIRECTS" "$2"
else
"$LREDIRECTS"
fi
;;
help)
display_help
;;
*)
echo "Error: Invalid choice: '$1'. To see all options, run: ./bdocs help"
exit 1
;;
esac