Skip to content

Commit ae345bb

Browse files
committed
Fix
1 parent 31f584d commit ae345bb

File tree

1 file changed

+62
-78
lines changed

1 file changed

+62
-78
lines changed

generate

+62-78
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,73 @@ trap "cd '${DEPLOY_DIR}'; rm -rf '${WORK_DIR}'" EXIT
3131
mkdir -p "${WORK_DIR}/public/"
3232

3333
cat << EOF > "${WORK_DIR}/public/index.html"
34-
<!DOCTYPE html>
35-
<html>
34+
<!doctype html>
35+
<html lang=en>
3636
<head>
37-
<meta charset="UTF-8">
38-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
39-
<title>PDI: Documentation versions</title>
37+
<meta charset=utf-8>
38+
<title>PDI: Documentation versions</title>
4039
</head>
4140
<body>
42-
<p>PDI documentation for:</p>
41+
<h1>PDI documentation for:</h1>
4342
<ul>
4443
EOF
4544

4645

46+
########################
47+
## GITHUB
48+
########################
49+
DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
50+
| jq -r '.artifacts
51+
| map(select(.workflow_run.head_branch=="main" and .name == "pages"))
52+
| sort_by(.created_at)
53+
| last
54+
| .archive_download_url')
55+
mkdir -p "${WORK_DIR}/public/main"
56+
cd "${WORK_DIR}/public/main"
57+
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
58+
unzip -o -d public artifacts.zip
59+
rm artifacts.zip
60+
while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ]
61+
do
62+
SUBDIR="$(find . -mindepth 1 -maxdepth 1)"
63+
find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';'
64+
rmdir "$SUBDIR"
65+
done
66+
echo "<li><a href='main/'>latest version from GIT</a></li>" >> "${WORK_DIR}/public/index.html"
67+
68+
69+
70+
71+
curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
72+
| jq -cr '.artifacts
73+
| map(select(.name == "pages" and (.workflow_run.head_branch
74+
| test("^v[0-9]+\\.[0-9]+$"))))
75+
| group_by(.workflow_run.head_branch)
76+
| map(sort_by(.created_at))
77+
| map(last)
78+
| map({url:.archive_download_url,branch:.workflow_run.head_branch})
79+
| .[]' \
80+
| while read TAG_INFO
81+
do
82+
DOWNLOAD_URL="$(jq -r .url <<< "$TAG_INFO")"
83+
TAG="$(jq -r .branch <<< "$TAG_INFO" | sed 's/^v//')"
84+
mkdir -p "${WORK_DIR}/public/${TAG}"
85+
cd "${WORK_DIR}/public/${TAG}"
86+
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
87+
unzip -o -d public artifacts.zip
88+
rm artifacts.zip
89+
while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ]
90+
do
91+
SUBDIR="$(find . -mindepth 1 -maxdepth 1)"
92+
find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';'
93+
rmdir "$SUBDIR"
94+
done
95+
echo "<li><a href='${TAG}/'>version ${TAG}</a></li>" >> "${WORK_DIR}/public/index.html"
96+
done
97+
98+
99+
100+
47101
########################
48102
## GITLAB
49103
########################
@@ -72,7 +126,7 @@ do
72126
then
73127
mv public "${WORK_DIR}/public/${STAG}"
74128
fi
75-
echo "<li><a href='${STAG}/'>version ${STAG}</a>" >> "${WORK_DIR}/public/index.html"
129+
echo "<li><a href='${STAG}/'>version ${STAG}</a></li>" >> "${WORK_DIR}/public/index.html"
76130
cd "${WORK_DIR}"
77131
rm -rf "${WORK_DIR}/${TAG}"
78132
break
@@ -93,80 +147,10 @@ fi
93147

94148

95149

96-
########################
97-
## GITHUB
98-
########################
99-
curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
100-
| jq -cr '.artifacts
101-
| map(select(.name == "pages" and (.workflow_run.head_branch
102-
| test("^v[0-9]+\\.[0-9]+$"))))
103-
| group_by(.workflow_run.head_branch)
104-
| map(sort_by(.created_at))
105-
| map(last)
106-
| map({url:.archive_download_url,branch:.workflow_run.head_branch})
107-
| .[]' \
108-
| while read TAG_INFO
109-
do
110-
DOWNLOAD_URL="$(jq -r .url <<< "$TAG_INFO")"
111-
TAG="$(jq -r .branch <<< "$TAG_INFO" | sed 's/^v//')"
112-
cd "${WORK_DIR}"
113-
mkdir -p "public/${TAG}"
114-
cd "public/${TAG}"
115-
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
116-
unzip -o -d public artifacts.zip
117-
rm artifacts.zip
118-
while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ]
119-
do
120-
SUBDIR="$(find . -mindepth 1 -maxdepth 1)"
121-
find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';'
122-
rmdir "$SUBDIR"
123-
done
124-
echo "<li><a href='${TAG}/'>version ${TAG}</a>" >> "${WORK_DIR}/public/index.html"
125-
done
126-
127-
128-
129-
if [ true = "${INERROR}" ]
130-
then
131-
rm -rf "${WORK_DIR}"
132-
exit 1
133-
fi
134-
135-
136-
137-
138-
139-
mkdir -p "${WORK_DIR}/main"
140-
cd "${WORK_DIR}/main"
141-
142-
DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
143-
| jq -r '.artifacts
144-
| map(select(.workflow_run.head_branch=="main" and .name == "pages"))
145-
| sort_by(.created_at)
146-
| last
147-
| .archive_download_url')
148-
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
149-
unzip -o -d public artifacts.zip
150-
rm artifacts.zip
151-
if [ -d "public/main" ]
152-
then
153-
mv "public/main" "${WORK_DIR}/public/"
154-
elif [ -d "main" ]
155-
then
156-
mv "main" "${WORK_DIR}/public/"
157-
elif [ -d "public" ]
158-
then
159-
mv public "main"
160-
mv "main" "${WORK_DIR}/public/"
161-
fi
162-
cd "${WORK_DIR}"
163-
rm -rf "${WORK_DIR}/main"
164-
165-
166150
cat << EOF >> "${WORK_DIR}/public/index.html"
167-
<li><a href='main/'>latest from GIT</a>
168151
</ul>
169152
</body>
170153
EOF
171154

155+
172156
mv "${WORK_DIR}/public"/* "${DEPLOY_DIR}"

0 commit comments

Comments
 (0)