Skip to content

Commit f529928

Browse files
totorigolocarllerche
authored andcommitted
chore: script updating versions in links to docs.rs (tokio-rs#1249)
1 parent 461eebe commit f529928

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

bin/publish

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ while [[ $# -gt 0 ]]
6161
do
6262

6363
case "$1" in
64+
-h|--help)
65+
echo "$USAGE"
66+
exit 0
67+
;;
6468
-v|--verbose)
6569
VERBOSE="--verbose"
6670
set +x

bin/update-doc

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
USAGE="Update links to docs.rs in a tokio crate
4+
5+
USAGE:
6+
$(basename "$0") [OPTIONS] [CRATE] [VERSION]
7+
8+
OPTIONS:
9+
-d, --dry-run Perform a dry run (do not modify any file)
10+
-h, --help Show this help text and exit"
11+
12+
err() {
13+
echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2;
14+
}
15+
16+
status() {
17+
WIDTH=12
18+
printf "\e[32m\e[1m%${WIDTH}s\e[0m %s\n" "$1" "$2"
19+
}
20+
21+
c1grep() { grep "$@" || test $? = 1; }
22+
23+
update_versions_in_doc() {
24+
# Print what is being/would be done
25+
if [ -n "$DRY_RUN" ]; then
26+
local MSG="Would change:"
27+
else
28+
local MSG="Updating:"
29+
fi
30+
git grep -lr "docs.rs/$CRATE/" \
31+
| xargs sed --quiet \
32+
-E "s|docs.rs/$CRATE/[0-9.]+|docs.rs/$CRATE/$VERSION|gp" \
33+
| sed -e "s/^/$MSG /"
34+
35+
# Apply changes if not in dry run
36+
if [ -z "$DRY_RUN" ]; then
37+
git grep -lr "docs.rs/$CRATE/" \
38+
| xargs sed -i \
39+
-E "s|docs.rs/$CRATE/[0-9.]+|docs.rs/$CRATE/$VERSION|g"
40+
fi
41+
}
42+
43+
update() {
44+
update_versions_in_doc
45+
}
46+
47+
show_outdated() {
48+
OUTDATED=$(git grep -rn "docs.rs/$CRATE/" \
49+
| c1grep -v "$VERSION" \
50+
| sed -e 's/^/ - /')
51+
if [[ -n "$OUTDATED" ]]; then
52+
echo "Found the following links to docs.rs with an outdated version:"
53+
echo "$OUTDATED"
54+
echo
55+
else
56+
echo "Nothing to do."
57+
exit 1
58+
fi
59+
}
60+
61+
while [[ $# -gt 0 ]]
62+
do
63+
64+
case "$1" in
65+
-h|--help)
66+
echo "$USAGE"
67+
exit 0
68+
;;
69+
-d|--dry-run)
70+
DRY_RUN="--dry-run"
71+
shift
72+
;;
73+
-*)
74+
err "unknown flag \"$1\""
75+
echo "$USAGE"
76+
exit 1
77+
;;
78+
*) # crate or version
79+
if [ -z "$CRATE" ]; then
80+
CRATE="$1"
81+
elif [ -z "$VERSION" ]; then
82+
VERSION="$1"
83+
else
84+
err "unknown positional argument \"$1\""
85+
echo "$USAGE"
86+
exit 1
87+
fi
88+
shift
89+
;;
90+
esac
91+
done
92+
# set -- "${POSITIONAL[@]}"
93+
94+
if [ -z "$VERSION" ]; then
95+
err "no version specified!"
96+
HELP=1
97+
fi
98+
99+
if [ -n "$CRATE" ]; then
100+
TAG="$CRATE-$VERSION"
101+
else
102+
err "no crate specified!"
103+
HELP=1
104+
fi
105+
106+
if [ -n "$HELP" ]; then
107+
echo "$USAGE"
108+
exit 1
109+
fi
110+
111+
if [ -d "$CRATE" ]; then
112+
# Does not cd in order to update everywhere
113+
show_outdated && update
114+
else
115+
err "no such crate \"$CRATE\""
116+
exit 1
117+
fi
118+

0 commit comments

Comments
 (0)