Skip to content

Commit 1a93ad1

Browse files
committed
Enable GH tags
1 parent c9e487a commit 1a93ad1

File tree

2 files changed

+50
-49
lines changed

2 files changed

+50
-49
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
env:
1616
CI_PAGES_TOKEN: ${{secrets.CI_PAGES_TOKEN}}
1717
run: |
18-
./generate _site https://gitlab.maisondelasimulation.fr pdidev%2Fpdi
18+
./generate _site https://gitlab.maisondelasimulation.fr pdidev%2Fpdi pdidev/pdi
1919
find data -mindepth 1 -maxdepth 1 -exec cp -r '{}' _site ';'
2020
./gen_sitemap _site
2121
- name: Upload page artifact

generate

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22
set -ex
33

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

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

1717
PROJECT_NAME="$3"
18+
GH_PROJECT_NAME="$3"
1819

1920
set +x
2021
if [ -z ${CI_PAGES_TOKEN} ]
@@ -95,57 +96,57 @@ fi
9596
########################
9697
## GITHUB
9798
########################
98-
#INERROR=true
99-
#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)"
100-
#for TAG_BASE in $(echo "${ALLTAGS}" | sed 's/^\([0-9]*\.[0-9]*\.\)[0-9]*-gh$/\1/' | sort -rVu)
101-
#do
102-
# for TAG in $(echo "${ALLTAGS}" | fgrep "${TAG_BASE}" | sort -rVu)
103-
# do
104-
# cd "${WORK_DIR}"
105-
# mkdir -p "${TAG}"
106-
# cd "${TAG}"
107-
# if curl -LfsSo artifacts.zip "https://api.github.com/repos/${PROJECT_NAME}/zipball/refs/tags/${TAG}"
108-
# then
109-
# INERROR=false
110-
# STAG="$(echo "${TAG}" | sed 's/\.[0-9]*$//')"
111-
# unzip -o -d public artifacts.zip
112-
# rm artifacts.zip
113-
# if [ -d "public/${TAG}" ]
114-
# then
115-
# mv "public/${TAG}" "${WORK_DIR}/public/${STAG}"
116-
# elif [ -d "${TAG}" ]
117-
# then
118-
# mv "${TAG}" "${WORK_DIR}/public/${STAG}"
119-
# elif [ -d "public" ]
120-
# then
121-
# mv public "${WORK_DIR}/public/${STAG}"
122-
# fi
123-
# echo "<li><a href='${STAG}/'>version ${STAG}</a>" >> "${WORK_DIR}/public/index.html"
124-
# cd "${WORK_DIR}"
125-
# rm -rf "${WORK_DIR}/${TAG}"
126-
# break
127-
# fi
128-
# cd "${WORK_DIR}"
129-
# rm -rf "${WORK_DIR}/${TAG}"
130-
# done
131-
#done
132-
133-
134-
135-
#if [ true = "${INERROR}" ]
136-
#then
137-
# rm -rf "${WORK_DIR}"
138-
# exit 1
139-
#fi
140-
#
141-
#
142-
#
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)
102+
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
132+
done
133+
134+
135+
136+
if [ true = "${INERROR}" ]
137+
then
138+
rm -rf "${WORK_DIR}"
139+
exit 1
140+
fi
141+
142+
143+
143144

144145

145146
mkdir -p "${WORK_DIR}/main"
146147
cd "${WORK_DIR}/main"
147148

148-
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 ')
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 ')
149150
curl -H "Authorization: Bearer ${CI_PAGES_TOKEN}" -LfsSo artifacts.zip "${DOWNLOAD_URL}"
150151
unzip -o -d public artifacts.zip
151152
rm artifacts.zip

0 commit comments

Comments
 (0)