Skip to content

Commit

Permalink
Enable GH tags
Browse files Browse the repository at this point in the history
  • Loading branch information
jbigot committed Dec 5, 2024
1 parent c9e487a commit 51bfffe
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
env:
CI_PAGES_TOKEN: ${{secrets.CI_PAGES_TOKEN}}
run: |
./generate _site https://gitlab.maisondelasimulation.fr pdidev%2Fpdi
./generate _site https://gitlab.maisondelasimulation.fr pdidev%2Fpdi pdidev/pdi
find data -mindepth 1 -maxdepth 1 -exec cp -r '{}' _site ';'
./gen_sitemap _site
- name: Upload page artifact
Expand Down
97 changes: 49 additions & 48 deletions generate
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -ex

if [ $# -ne 3 ]
if [ $# -ne 4 ]
then
echo "Usage: $0 <directory> <gitlab URL> <project NAME>" >&2
echo "Usage: $0 <directory> <gitlab URL> <project NAME> <GitHub project NAME>" >&2
exit 1
fi

Expand All @@ -15,6 +15,7 @@ DEPLOY_DIR="${PWD}"
GITLAB_URL="$2"

PROJECT_NAME="$3"
GH_PROJECT_NAME="$3"

set +x
if [ -z ${CI_PAGES_TOKEN} ]
Expand Down Expand Up @@ -95,57 +96,57 @@ fi
########################
## GITHUB
########################
#INERROR=true
#ALLTAGS="$(curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -fsS "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 -LfsSo 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
#
#
#
INERROR=true
ALLTAGS="$(curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -fsS "https://api.github.com/repos/${GH_PROJECT_NAME}/tags" jq -r 'map(select(.name | test("^[0-9]+\\.[0-9]+\\.[0-9]+$"))) | sort_by(.name) | .[] | .name')"
for TAG_BASE in $(echo "${ALLTAGS}" | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*$/\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 -LfsSo 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 -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/pdidev/pdi/actions/artifacts | jq -r '.artifacts | map(select(.workflow_run.head_branch=="main")) | sort_by(.created_at) | last | .archive_download_url ')
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")) | 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
Expand Down

0 comments on commit 51bfffe

Please sign in to comment.