forked from ImAleeexx/streamlink-drm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-docs.sh
executable file
·85 lines (63 loc) · 2.27 KB
/
deploy-docs.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
#!/usr/bin/env bash
shopt -s nullglob
set -eo pipefail
[[ -n "${GITHUB_ACTIONS}" ]] || [[ -n "${DOCS_DEPLOY_TOKEN}" ]] || exit 1
ROOT=$(git rev-parse --show-toplevel 2>/dev/null || realpath "$(dirname "$(readlink -f "${0}")")/..")
DOCS_DIR=${DOCS_DIR:-"${ROOT}/docs/_build/html"}
DOCS_REPO=${DOCS_REPO:-streamlink/streamlink.github.io}
DOCS_BRANCH=${DOCS_BRANCH:-master}
DOCS_USER=${DOCS_USER:-streamlinkbot}
DOCS_EMAIL=${DOCS_EMAIL:[email protected]}
FILELIST=".doctr-files"
if [[ "${GITHUB_REF}" =~ ^refs/tags/ ]]; then
WHAT="tag"
NAME="${GITHUB_REF/#refs\/tags\//}"
DEST="."
else
WHAT="branch"
NAME="${GITHUB_REF/#refs\/heads\//}"
DEST="latest"
fi
if ! [[ -s "${DOCS_DIR}/index.html" ]]; then
echo Missing or empty index.html
exit 1
fi
echo Creating temporary directory
TEMP=$(mktemp -d) && trap "rm -rf ${TEMP}" EXIT || exit 255
cd "${TEMP}"
echo Cloning repository...
git clone \
--depth=1 \
--origin=origin \
--branch="${DOCS_BRANCH}" \
"https://github.com/${DOCS_REPO}.git" \
.
echo Deleting all files stored in \'${DEST}\' file list
cat "${DEST}/${FILELIST}" | xargs realpath -- | awk -v P="$(pwd)" '$0 ~ P "/" {print $0}' | xargs rm --force --
echo Copying new files into \'${DEST}\'
mkdir --parents "${DEST}"
cp --archive "${DOCS_DIR}/." "${DEST}/"
echo Building a new file list in \'${DEST}\'
( cd "${DOCS_DIR}"; find . -type f | LC_ALL=C sort | sed "s/^\\.\//${DEST}\//" > "${TEMP}/${DEST}/${FILELIST}" )
if [[ -z "$(git status --porcelain)" ]]; then
echo No changes to be committed. Exiting...
exit 0
fi
echo Staging changes
git add --all
echo Committing changes
git config --local user.name "${DOCS_USER}"
git config --local user.email "${DOCS_EMAIL}"
cat << EOM | git commit -F-
Update docs from Github build ${GITHUB_RUN_NUMBER}
of ${GITHUB_REPOSITORY}
The docs were built from the ${WHAT} '${NAME}' against the commit
${GITHUB_SHA}
https://github.com/${GITHUB_REPOSITORY}/commit/${GITHUB_SHA:0:7}
https://github.com/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}
EOM
echo Pushing changes
git config --unset 'http.https://github.com/.extraheader' || true
git remote set-url --push origin "https://${DOCS_USER}:${DOCS_DEPLOY_TOKEN}@github.com/${DOCS_REPO}.git"
git push origin "${DOCS_BRANCH}"
echo Done