Repository navigation
Expand file tree
/
Copy pathgenerate
More file actions
executable file
·118 lines (103 loc) · 3.98 KB
/
Copy pathgenerate
File metadata and controls
executable file
·118 lines (103 loc) · 3.98 KB
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
set -ex
if [ $# -ne 2 ]
then
echo "Usage: $0 <directory> <GitHub project NAME>" >&2
exit 1
fi
DEPLOY_DIR="${1}"
mkdir -p "${DEPLOY_DIR}"
cd "${DEPLOY_DIR}"
DEPLOY_DIR="${PWD}"
GH_PROJECT_NAME="$2"
set +x
if [ -z ${CI_PAGES_TOKEN} ]
then
echo "CI_PAGES_TOKEN is unset"
exit 1
fi
set -ex
cd "$(mktemp -t -d WEB_DEPLOY.tmdir.XXXXXXXXXXXX || exit 1)"
WORK_DIR="${PWD}"
trap "cd '${DEPLOY_DIR}'; rm -rf '${WORK_DIR}'" EXIT
mkdir -p "${WORK_DIR}/public/"
cat << EOF > "${WORK_DIR}/public/index.html"
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>PDI: Documentation versions</title>
</head>
<body>
<h1>PDI documentation for:</h1>
<ul>
EOF
MAIN_RUN_ID=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" \
"https://api.github.com/repos/${GH_PROJECT_NAME}/actions/workflows/pages.yml/runs?branch=main&event=push&status=success&per_page=1" \
| jq -r '.workflow_runs[0].id // empty')
DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" \
"https://api.github.com/repos/${GH_PROJECT_NAME}/actions/runs/${MAIN_RUN_ID}/artifacts?name=pages" \
| jq -r 'first(.artifacts[] | select(.expired | not) | .archive_download_url) // empty')
mkdir -p "${WORK_DIR}/public/main"
cd "${WORK_DIR}/public/main"
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
unzip -o -d public artifacts.zip
rm artifacts.zip
while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ]
do
SUBDIR="$(find . -mindepth 1 -maxdepth 1)"
find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';'
rmdir "$SUBDIR"
done
echo "<li><a href='main/'>latest version from GIT</a></li>" >> "${WORK_DIR}/public/index.html"
JSON="$(curl -v "https://api.github.com/repos/${GH_PROJECT_NAME}/releases")"
ALLTAGS="$(jq -cr ' .[] | to_entries[] | select(.key == "tag_name") | .value ' <<< "${JSON}")"
## example:
## ALLTAGS=$'1.9.2\n1.9.1-fixed1.9.0\n1.8.1\n1.8.2\n1.8.1\n1.8.0'
## TAG = 1.9.1-fixed (correspond to the tag on pdidev/pdi)
## EX_TAG_BASE=1.9.
## STAG=1.9
##hypothesis: TAG = [0-9].[0-9].[0-9]-fixed[0-9]
## or TAG = [0-9].[0-9].[0-9]-fixed
## or TAG = [0-9].[0-9].[0-9]
## where [0-9] is an integer
for TAG_BASE in "$(echo "${ALLTAGS}" | tr '"' ' ' | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*-fixed[0-9]*$/\1/g' | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*$/\1/g'| sort -rVu)"
do
list_tag_base=($TAG_BASE) ## get the list of string of TAG_BASE in a array
for EX_TAG_BASE in "${list_tag_base[@]}"
do
for TAG in $(echo "${ALLTAGS}" | fgrep "${EX_TAG_BASE}" | sort -rVu)
do
# remove "." (last character of EX_TAG_BASE)
STAG="$(echo "${EX_TAG_BASE}" | sed 's/\.$//')"
DOWNLOAD_URL="$(jq --arg TAG "${TAG}" -cr ' .[] | select(.tag_name == $TAG ) | .assets[] | select(.name == "pages.zip") | .browser_download_url ' <<< "${JSON}")"
mkdir -p "${WORK_DIR}/public/${STAG}"
cd "${WORK_DIR}/public/${STAG}"
if curl -LfsSo artifacts.zip "${DOWNLOAD_URL}"
then
echo "unzip asset for release: ${TAG} and STAG=${STAG}"
echo "dowload_url=${DOWNLOAD_URL}"
unzip -o -d public artifacts.zip
rm artifacts.zip
while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ]
do
SUBDIR="$(find . -mindepth 1 -maxdepth 1)"
find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';'
rmdir "$SUBDIR"
done
echo "<li><a href='${STAG}/'>version ${STAG}</a></li>" >> "${WORK_DIR}/public/index.html"
echo "<li><a href='${STAG}/'>version ${STAG}</a></li>"
break
else
echo "error in downloading asset for release: ${TAG} and STAG=${STAG}"
echo "dowload_url=${DOWNLOAD_URL}"
exit 1
fi
done
done
done
cat << EOF >> "${WORK_DIR}/public/index.html"
</ul>
</body>
EOF
mv "${WORK_DIR}/public"/* "${DEPLOY_DIR}"