Skip to content

Commit

Permalink
add documentation from github's main branch (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitmartin88 authored Dec 5, 2024
1 parent c3a52a3 commit f92b2cf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/actions/deploy/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ FROM alpine:3.10

COPY entrypoint.sh /entrypoint.sh

RUN [ "apk", "add", "bash", "curl" ]
RUN [ "apk", "add", "bash", "curl", "jq" ]

ENTRYPOINT ["/entrypoint.sh"]
89 changes: 77 additions & 12 deletions .github/actions/deploy/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ GITLAB_URL="$2"

PROJECT_NAME="$3"

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
Expand All @@ -35,6 +43,10 @@ cat << EOF > "${WORK_DIR}/public/index.html"
<ul>
EOF


########################
## GITLAB
########################
INERROR=true
ALLTAGS="$(curl -fs "${GITLAB_URL}/api/v4/projects/${PROJECT_NAME}/repository/tags" | tr ',' '\n' | grep '"name"' | tr '"' ' ' | awk '{print $4}' | grep '^[0-9]*\.[0-9]*\.[0-9]*$' | sort -rVu)"
for TAG_BASE in $(echo "${ALLTAGS}" | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*$/\1/' | sort -rVu)
Expand Down Expand Up @@ -80,28 +92,81 @@ fi



mkdir -p "${WORK_DIR}/master"
cd "${WORK_DIR}/master"
curl -fso artifacts.zip "${GITLAB_URL}/api/v4/projects/${PROJECT_NAME}/jobs/artifacts/master/download?job=pages"
unzip -o artifacts.zip

########################
## GITHUB
########################
#INERROR=true
#ALLTAGS="$(curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -fs "https://api.github.com/repos/${PROJECT_NAME}/tags" | tr ',' '\n' | grep '"name"' | tr '"' ' ' | awk '{print $3}' | grep '^[0-9]*\.[0-9]*\.[0-9]*-gh$' | sort -rVu)"
#for TAG_BASE in $(echo "${ALLTAGS}" | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*-gh$/\1/' | sort -rVu)
#do
# for TAG in $(echo "${ALLTAGS}" | fgrep "${TAG_BASE}" | sort -rVu)
# do
# cd "${WORK_DIR}"
# mkdir -p "${TAG}"
# cd "${TAG}"
# if curl -Lfso artifacts.zip "https://api.github.com/repos/${PROJECT_NAME}/zipball/refs/tags/${TAG}"
# then
# INERROR=false
# STAG="$(echo "${TAG}" | sed 's/\.[0-9]*$//')"
# unzip -o -d public artifacts.zip
# rm artifacts.zip
# if [ -d "public/${TAG}" ]
# then
# mv "public/${TAG}" "${WORK_DIR}/public/${STAG}"
# elif [ -d "${TAG}" ]
# then
# mv "${TAG}" "${WORK_DIR}/public/${STAG}"
# elif [ -d "public" ]
# then
# mv public "${WORK_DIR}/public/${STAG}"
# fi
# echo "<li><a href='${STAG}/'>version ${STAG}</a>" >> "${WORK_DIR}/public/index.html"
# cd "${WORK_DIR}"
# rm -rf "${WORK_DIR}/${TAG}"
# break
# fi
# cd "${WORK_DIR}"
# rm -rf "${WORK_DIR}/${TAG}"
# done
#done



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


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

DOWNLOAD_URL=$(curl -fs -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/pdidev/pdi/actions/artifacts | jq -r '.artifacts | .[] | select(.workflow_run.head_branch=="main") | .archive_download_url')
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -Lfso artifacts.zip "${DOWNLOAD_URL}"
unzip -o -d public artifacts.zip
rm artifacts.zip
if [ -d "public/master" ]
if [ -d "public/main" ]
then
mv "public/master" "${WORK_DIR}/public/"
elif [ -d "master" ]
mv "public/main" "${WORK_DIR}/public/"
elif [ -d "main" ]
then
mv "master" "${WORK_DIR}/public/"
mv "main" "${WORK_DIR}/public/"
elif [ -d "public" ]
then
mv public "master"
mv "master" "${WORK_DIR}/public/"
mv public "main"
mv "main" "${WORK_DIR}/public/"
fi
cd "${WORK_DIR}"
rm -rf "${WORK_DIR}/master"
rm -rf "${WORK_DIR}/main"


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

0 comments on commit f92b2cf

Please sign in to comment.