|
96 | 96 | ########################
|
97 | 97 | ## GITHUB
|
98 | 98 | ########################
|
99 |
| -INERROR=true |
100 |
| -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')" |
101 |
| -for TAG_BASE in $(echo "${ALLTAGS}" | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*$/\1/' | sort -rVu) |
| 99 | +curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \ |
| 100 | +| jq --raw-output0 '.artifacts |
| 101 | + | map(select(.name == "pages" and (.workflow_run.head_branch |
| 102 | + | test("^v[0-9]+\\.[0-9]+$")))) |
| 103 | + | group_by(.workflow_run.head_branch) |
| 104 | + | map(sort_by(.created_at)) |
| 105 | + | map(last) |
| 106 | + | map({url:.archive_download_url,branch:.workflow_run.head_branch}) |
| 107 | + | .[]' \ |
| 108 | +| while read -d $'\0' TAG_INFO |
102 | 109 | do
|
103 |
| - for TAG in $(echo "${ALLTAGS}" | fgrep "${TAG_BASE}" | sort -rVu) |
104 |
| - do |
105 |
| - cd "${WORK_DIR}" |
106 |
| - mkdir -p "${TAG}" |
107 |
| - cd "${TAG}" |
108 |
| - if curl -LfsSo artifacts.zip "https://api.github.com/repos/${GH_PROJECT_NAME}/zipball/refs/tags/${TAG}" |
109 |
| - then |
110 |
| - INERROR=false |
111 |
| - STAG="$(echo "${TAG}" | sed 's/\.[0-9]*$//')" |
112 |
| - unzip -o -d public artifacts.zip |
113 |
| - rm artifacts.zip |
114 |
| - if [ -d "public/${TAG}" ] |
115 |
| - then |
116 |
| - mv "public/${TAG}" "${WORK_DIR}/public/${STAG}" |
117 |
| - elif [ -d "${TAG}" ] |
118 |
| - then |
119 |
| - mv "${TAG}" "${WORK_DIR}/public/${STAG}" |
120 |
| - elif [ -d "public" ] |
121 |
| - then |
122 |
| - mv public "${WORK_DIR}/public/${STAG}" |
123 |
| - fi |
124 |
| - echo "<li><a href='${STAG}/'>version ${STAG}</a>" >> "${WORK_DIR}/public/index.html" |
125 |
| - cd "${WORK_DIR}" |
126 |
| - rm -rf "${WORK_DIR}/${TAG}" |
127 |
| - break |
128 |
| - fi |
129 |
| - cd "${WORK_DIR}" |
130 |
| - rm -rf "${WORK_DIR}/${TAG}" |
131 |
| - done |
| 110 | + DOWNLOAD_URL="$(jq -r .url <<< "$TAG_INFO")" |
| 111 | + TAG="$(jq -r .branch <<< "$TAG_INFO" | sed 's/^v//')" |
| 112 | + cd "${WORK_DIR}" |
| 113 | + mkdir -p "${TAG}" |
| 114 | + cd "${TAG}" |
| 115 | + curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}" |
| 116 | + unzip -o -d public artifacts.zip |
| 117 | + rm artifacts.zip |
| 118 | + while [ 1 -eq "$(find . -mindepth 1 -maxdepth 1|wc -l)" ] |
| 119 | + do |
| 120 | + SUBDIR="$(find . -mindepth 1 -maxdepth 1)" |
| 121 | + find "$SUBDIR" -mindepth 1 -maxdepth 1 -exec mv '{}' . |
| 122 | + rmdir "$SUBDIR" |
| 123 | + done |
| 124 | + echo "<li><a href='${TAG}/'>version ${TAG}</a>" >> "${WORK_DIR}/public/index.html" |
132 | 125 | done
|
133 | 126 |
|
134 | 127 |
|
|
146 | 139 | mkdir -p "${WORK_DIR}/main"
|
147 | 140 | cd "${WORK_DIR}/main"
|
148 | 141 |
|
149 |
| -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 ') |
| 142 | +DOWNLOAD_URL=$(curl -fsS -H "Authorization: Bearer ${CI_PAGES_TOKEN}" https://api.github.com/repos/${GH_PROJECT_NAME}/actions/artifacts \ |
| 143 | + | jq -r '.artifacts |
| 144 | + | map(select(.workflow_run.head_branch=="main" and .name == "pages")) |
| 145 | + | sort_by(.created_at) |
| 146 | + | last |
| 147 | + | .archive_download_url') |
150 | 148 | curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
|
151 | 149 | unzip -o -d public artifacts.zip
|
152 | 150 | rm artifacts.zip
|
|
0 commit comments