From 8da543e80d1ab32977142ea309b309bf2f4b3882 Mon Sep 17 00:00:00 2001 From: "jacques.morice" Date: Thu, 28 Aug 2025 13:21:07 +0200 Subject: [PATCH 1/2] download release pages from asset --- generate | 82 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/generate b/generate index 172c6a33..aefb4819 100755 --- a/generate +++ b/generate @@ -17,13 +17,13 @@ GITLAB_URL="$2" PROJECT_NAME="$3" GH_PROJECT_NAME="$4" -set +x -if [ -z ${CI_PAGES_TOKEN} ] -then - echo "CI_PAGES_TOKEN is unset" - exit 1 -fi -set -ex +#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}" @@ -53,6 +53,7 @@ DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://ap | 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 @@ -65,39 +66,56 @@ do done echo "
  • latest version from GIT
  • " >> "${WORK_DIR}/public/index.html" +ALLTAGS="$(curl -v "https://api.github.com/repos/${GH_PROJECT_NAME}/releases" | jq -cr ' .[] | to_entries[] | select(.key == "tag_name") | .value ')" +## example: +## ALLTAGS=$'1.9.2\n1.9.1-fixed1.9.0\n1.8.1\n1.8.2\n1.8.1\n1.8.0' +## TAG = 1.9.1-fixed (correspond to the tag on pdidev/pdi) +## EX_TAG_BASE=1.9. +## STAG=1.9 +##hypothesis: TAG = [0-9].[0-9].[0-9]-fixed[0-9] +## or TAG = [0-9].[0-9].[0-9]-fixed +## or TAG = [0-9].[0-9].[0-9] +## where [0-9] is an integer - -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 +for TAG_BASE in "$(echo "${ALLTAGS}" | tr '"' ' ' | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*-fixed[0-9]*$/\1/g' | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*$/\1/g'| sort -rVu)" 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)" ] + list_tag_base=($TAG_BASE) ## get the list of string of TAG_BASE in a array + for EX_TAG_BASE in "${list_tag_base[@]}" do - SUBDIR="$(find . -mindepth 1 -maxdepth 1)" - find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . ';' - rmdir "$SUBDIR" + for TAG in $(echo "${ALLTAGS}" | fgrep "${EX_TAG_BASE}" | sort -rVu) + do + # remove "." (last character of EX_TAG_BASE) + STAG="$(echo "${EX_TAG_BASE}" | sed 's/\.$//')" + + DOWNLOAD_URL="https://github.com/${GH_PROJECT_NAME}/releases/download/${TAG}/pages.zip" + mkdir -p "${WORK_DIR}/public/${STAG}" + cd "${WORK_DIR}/public/${STAG}" + if curl -LfsSo artifacts.zip "${DOWNLOAD_URL}" + then + echo "unzip asset for release: ${TAG} and STAG=${STAG}" + echo "dowload_url=${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 "
  • version ${STAG}
  • " >> "${WORK_DIR}/public/index.html" + echo "
  • version ${STAG}
  • " + break + else + echo "error in downloading asset for release: ${TAG} and STAG=${STAG}" + echo "dowload_url=${DOWNLOAD_URL}" + exit 1 + fi + done done - echo "
  • version ${TAG}
  • " >> "${WORK_DIR}/public/index.html" done - - ######################## ## GITLAB ######################## From 9439842d69ebc79048f481ed85543a0d7f6869fc Mon Sep 17 00:00:00 2001 From: "jacques.morice" Date: Thu, 28 Aug 2025 16:14:50 +0200 Subject: [PATCH 2/2] fix #5, check token --- generate | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/generate b/generate index aefb4819..26e19f79 100755 --- a/generate +++ b/generate @@ -17,13 +17,13 @@ GITLAB_URL="$2" PROJECT_NAME="$3" GH_PROJECT_NAME="$4" -#set +x -# if [ -z ${CI_PAGES_TOKEN} ] -# then -# echo "CI_PAGES_TOKEN is unset" -# exit 1 -# fi -#set -ex +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}"