Skip to content

Commit e8ac065

Browse files
committed
chore: manage also RC releases
Signed-off-by: Gabriele Bartolini <gabriele.bartolini@enterprisedb.com>
1 parent 25df4d9 commit e8ac065

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

hack/create_http_redirects.sh

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,53 @@
11
#!/bin/bash
22

33
# 1. Capture the version from the first argument
4-
VERSION=$1
4+
INPUT_VERSION=$1
55

66
# 2. Check if a version was provided
7-
if [ -z "$VERSION" ]; then
7+
if [ -z "$INPUT_VERSION" ]; then
88
echo "Usage: $0 <version>"
99
echo "Example: $0 1.28"
10+
echo "Example: $0 current"
1011
exit 1
1112
fi
1213

13-
# 3. Define paths relative to this script's location
14-
# $(dirname "$0") is the 'hack' folder. /.. moves up to the root.
14+
# 3. Handle specific redirection mapping logic
15+
if [ "$INPUT_VERSION" == "current" ]; then
16+
# Map 'current' to 'devel'
17+
DEST_VERSION="devel"
18+
elif [[ "$INPUT_VERSION" =~ -rc[0-9]+$ ]]; then
19+
# Strip -rc suffix (e.g., 1.27.0-rc1 -> 1.27.0)
20+
DEST_VERSION=$(echo "$INPUT_VERSION" | sed -E 's/-rc[0-9]+$//')
21+
else
22+
# Keep as is
23+
DEST_VERSION="$INPUT_VERSION"
24+
fi
25+
26+
# 4. Define paths relative to this script's location
1527
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
1628
ROOT_DIR="$SCRIPT_DIR/.."
17-
BASE_DIR="$ROOT_DIR/assets/documentation/$VERSION"
18-
BASE_URL="https://cloudnative-pg.io/docs/$VERSION"
29+
BASE_DIR="$ROOT_DIR/assets/documentation/$INPUT_VERSION"
30+
BASE_URL="https://cloudnative-pg.io/docs/$DEST_VERSION"
1931

20-
# Special handling of "current"
21-
if [ $VERSION = "current" ]
22-
then
23-
BASE_URL="https://cloudnative-pg.io/docs/devel"
24-
fi
25-
26-
# The message displayed to users
32+
# The message requested
2733
MSG_TITLE="CloudNativePG documentation has moved"
2834
MSG_BODY="CloudNativePG has changed the way we build and organize our documentation to provide a better experience."
2935

30-
# 4. Check if the target directory exists
36+
# 5. Check if the target directory exists
3137
if [ ! -d "$BASE_DIR" ]; then
3238
echo "Error: Directory not found at $BASE_DIR"
33-
echo "Make sure you are passing the correct version and the assets folder exists."
3439
exit 1
3540
fi
3641

37-
echo "Searching for index.html files in: $BASE_DIR"
42+
echo "Source Version: $INPUT_VERSION"
43+
echo "Target URL Version: $DEST_VERSION"
44+
echo "Searching for index.html files..."
3845

39-
# 5. Find and process files
46+
# 6. Find and process files
4047
find "$BASE_DIR" -type f -name "index.html" | while read -r file; do
4148

4249
# Calculate the slug
43-
# We strip the absolute path to the base directory to get the relative piece
4450
rel_path=${file#"$BASE_DIR/"}
45-
46-
# Remove the filename suffix (/index.html)
4751
slug=${rel_path%/index.html}
4852

4953
# Handle the root index.html case
@@ -53,9 +57,6 @@ find "$BASE_DIR" -type f -name "index.html" | while read -r file; do
5357
new_url="$BASE_URL/$slug"
5458
fi
5559

56-
echo "Updating: assets/documentation/$VERSION/$rel_path"
57-
echo " -> $new_url"
58-
5960
# Overwrite the file
6061
cat <<EOF > "$file"
6162
<!DOCTYPE html>
@@ -76,4 +77,4 @@ EOF
7677
done
7778

7879
echo "------------------------------------------------"
79-
echo "Success: All files in $VERSION updated from the hack folder."
80+
echo "Success: All files in $INPUT_VERSION have been updated."

0 commit comments

Comments
 (0)