From 51bfffe3ffb0d8994eda1bccbf6a8a76ddbec130 Mon Sep 17 00:00:00 2001 From: Julien Bigot Date: Thu, 5 Dec 2024 14:27:53 +0900 Subject: [PATCH] Enable GH tags --- .github/workflows/deploy.yml | 2 +- generate | 97 ++++++++++++++++++------------------ 2 files changed, 50 insertions(+), 49 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index ab4e6e65..7a5f2bff 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/generate b/generate index 38cfa942..41f028d2 100755 --- a/generate +++ b/generate @@ -1,9 +1,9 @@ #!/bin/bash set -ex -if [ $# -ne 3 ] +if [ $# -ne 4 ] then - echo "Usage: $0 " >&2 + echo "Usage: $0 " >&2 exit 1 fi @@ -15,6 +15,7 @@ DEPLOY_DIR="${PWD}" GITLAB_URL="$2" PROJECT_NAME="$3" +GH_PROJECT_NAME="$3" set +x if [ -z ${CI_PAGES_TOKEN} ] @@ -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 "
  • version ${STAG}" >> "${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 "
  • version ${STAG}" >> "${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