-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrapids-upload-docs
executable file
·118 lines (103 loc) · 3.29 KB
/
rapids-upload-docs
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
#!/bin/bash
# This script uploads RAPIDS docs to S3.
# The docs are expected to be in the following directory structure:
# $RAPIDS_DOCS_DIR
# ├── cudf
# │ ├── html
# │ │ └── <html files>
# │ └── txt
# │ └── <txt files>
# └── dask-cudf
# ├── html
# │ └── <html files>
# └── txt
# └── <txt files>
# Required Environment Variables:
# - RAPIDS_DOCS_DIR - a path to a directory containing the docs to upload
# - RAPIDS_VERSION_NUMBER - the version number of the docs being uploaded
set -euo pipefail
source rapids-constants
checks() {
if [[ ! -d "${RAPIDS_DOCS_DIR}" ]]; then
echo "ERROR: RAPIDS_DOCS_DIR must be a directory."
exit 1
fi
if [[ "${GITHUB_ACTIONS:-false}" != "true" ]]; then
echo "Uploading docs from local builds is not supported."
echo "The docs are in ${RAPIDS_DOCS_DIR}."
echo "They can be viewed in a web browser by running:"
echo "python -m http.server --directory ${RAPIDS_DOCS_DIR}"
exit 0
fi
}
get_s3_dest() {
local PROJECT=$1
local FORMAT=$2
case "${RAPIDS_BUILD_TYPE}" in
pull-request)
echo -n "$(rapids-s3-path)docs/${PROJECT}/${FORMAT}"
return
;;
branch|nightly)
echo -n "s3://rapidsai-docs/${PROJECT}/${FORMAT}/${RAPIDS_VERSION_NUMBER}"
return
;;
*)
rapids-echo-stderr "please pass a valid RAPIDS_BUILD_TYPE"
exit 1
;;
esac
}
copy_docs_to_s3() {
local PROJECT_DIR PROJECT PROJECT_FORMAT_DIR FORMAT
if [[ "${RAPIDS_BUILD_TYPE}" == "pull-request" ]]; then
{
echo '# Documentation Preview:'
echo ''
echo '**Note:** NVIDIA VPN access is required to view these URLs.'
echo ''
} > "${GITHUB_STEP_SUMMARY}"
fi
for PROJECT_DIR in "${RAPIDS_DOCS_DIR}"/*; do
PROJECT=$(basename "${PROJECT_DIR}")
for PROJECT_FORMAT_DIR in "${PROJECT_DIR}"/*; do
FORMAT=$(basename "${PROJECT_FORMAT_DIR}")
if [[ ! "${FORMAT}" =~ ^(html|txt|xml_tar)$ ]]; then
echo "ERROR: FORMAT must be either 'html' or 'txt' or 'xml_tar'."
exit 1
fi
if [[ "${FORMAT}" == "xml_tar" ]]; then
NUM_FILES=$(find "$PROJECT_FORMAT_DIR" -type f | wc -l)
if [[ ! -f "${PROJECT_FORMAT_DIR}/xml.tar.gz" || $NUM_FILES -ne 1 ]]; then
echo "Error: The xml_tar directory should contain a single file named xml.tar.gz."
exit 1
fi
fi
rapids-logger "Uploading ${RAPIDS_VERSION_NUMBER} ${PROJECT} ${FORMAT} docs to S3."
ACL_OPTION="private"
if [[ "$FORMAT" == "xml_tar" ]]; then
ACL_OPTION="public-read"
fi
aws s3 sync \
--no-progress \
--delete \
--acl "${ACL_OPTION}" \
"${PROJECT_FORMAT_DIR}" \
"$(get_s3_dest "${PROJECT}" "${FORMAT}")"
echo ""
if [[ "${RAPIDS_BUILD_TYPE}" != "pull-request" ]]; then
continue
fi
rapids-logger "${PROJECT} ${FORMAT} preview URL:"
HTTP_URL="$(
get_s3_dest "${PROJECT}" "${FORMAT}" |
sed "s|s3://${RAPIDS_DOWNLOADS_BUCKET}|https://${RAPIDS_DOWNLOADS_DOMAIN}|"
)"
echo "Note: NVIDIA VPN access is required to view this URL."
echo "- ${HTTP_URL}/" | tee --append "${GITHUB_STEP_SUMMARY}"
echo ""
done
done
}
checks
copy_docs_to_s3