Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jbigot committed Dec 5, 2024
1 parent 31f584d commit ae345bb
Showing 1 changed file with 62 additions and 78 deletions.
140 changes: 62 additions & 78 deletions generate
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,73 @@ trap "cd '${DEPLOY_DIR}'; rm -rf '${WORK_DIR}'" EXIT
mkdir -p "${WORK_DIR}/public/"

cat << EOF > "${WORK_DIR}/public/index.html"
<!DOCTYPE html>
<html>
<!doctype html>
<html lang=en>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>PDI: Documentation versions</title>
<meta charset=utf-8>
<title>PDI: Documentation versions</title>
</head>
<body>
<p>PDI documentation for:</p>
<h1>PDI documentation for:</h1>
<ul>
EOF


########################
## GITHUB
########################
DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
| jq -r '.artifacts
| map(select(.workflow_run.head_branch=="main" and .name == "pages"))
| sort_by(.created_at)
| last
| .archive_download_url')
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"




curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
| jq -cr '.artifacts
| map(select(.name == "pages" and (.workflow_run.head_branch
| test("^v[0-9]+\\.[0-9]+$"))))
| group_by(.workflow_run.head_branch)
| map(sort_by(.created_at))
| map(last)
| map({url:.archive_download_url,branch:.workflow_run.head_branch})
| .[]' \
| while read TAG_INFO
do
DOWNLOAD_URL="$(jq -r .url <<< "$TAG_INFO")"
TAG="$(jq -r .branch <<< "$TAG_INFO" | sed 's/^v//')"
mkdir -p "${WORK_DIR}/public/${TAG}"
cd "${WORK_DIR}/public/${TAG}"
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='${TAG}/'>version ${TAG}</a></li>" >> "${WORK_DIR}/public/index.html"
done




########################
## GITLAB
########################
Expand Down Expand Up @@ -72,7 +126,7 @@ do
then
mv public "${WORK_DIR}/public/${STAG}"
fi
echo "<li><a href='${STAG}/'>version ${STAG}</a>" >> "${WORK_DIR}/public/index.html"
echo "<li><a href='${STAG}/'>version ${STAG}</a></li>" >> "${WORK_DIR}/public/index.html"
cd "${WORK_DIR}"
rm -rf "${WORK_DIR}/${TAG}"
break
Expand All @@ -93,80 +147,10 @@ fi



########################
## GITHUB
########################
curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
| jq -cr '.artifacts
| map(select(.name == "pages" and (.workflow_run.head_branch
| test("^v[0-9]+\\.[0-9]+$"))))
| group_by(.workflow_run.head_branch)
| map(sort_by(.created_at))
| map(last)
| map({url:.archive_download_url,branch:.workflow_run.head_branch})
| .[]' \
| while read TAG_INFO
do
DOWNLOAD_URL="$(jq -r .url <<< "$TAG_INFO")"
TAG="$(jq -r .branch <<< "$TAG_INFO" | sed 's/^v//')"
cd "${WORK_DIR}"
mkdir -p "public/${TAG}"
cd "public/${TAG}"
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='${TAG}/'>version ${TAG}</a>" >> "${WORK_DIR}/public/index.html"
done



if [ true = "${INERROR}" ]
then
rm -rf "${WORK_DIR}"
exit 1
fi





mkdir -p "${WORK_DIR}/main"
cd "${WORK_DIR}/main"

DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \
| jq -r '.artifacts
| map(select(.workflow_run.head_branch=="main" and .name == "pages"))
| sort_by(.created_at)
| last
| .archive_download_url')
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
unzip -o -d public artifacts.zip
rm artifacts.zip
if [ -d "public/main" ]
then
mv "public/main" "${WORK_DIR}/public/"
elif [ -d "main" ]
then
mv "main" "${WORK_DIR}/public/"
elif [ -d "public" ]
then
mv public "main"
mv "main" "${WORK_DIR}/public/"
fi
cd "${WORK_DIR}"
rm -rf "${WORK_DIR}/main"


cat << EOF >> "${WORK_DIR}/public/index.html"
<li><a href='main/'>latest from GIT</a>
</ul>
</body>
EOF


mv "${WORK_DIR}/public"/* "${DEPLOY_DIR}"

0 comments on commit ae345bb

Please sign in to comment.