Skip to content

Commit 7dec774

Browse files
authored
Enable parallel download artifacts (#768)
In the previous versions, it download artifacts from GitHub in serial not parallel, so it takes huge amount of times. In this version, it tries to download them in parallel, so it fixes above issue. Signed-off-by: Kentaro Hayashi <[email protected]>
1 parent 7a46ab5 commit 7dec774

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

fluent-package/manage-fluent-repositories.sh

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,39 +196,70 @@ EOF
196196
https://api.github.com/repos/fluent/fluent-package-builder/pulls/$PULL_NUMBER | jq --raw-output '.head | .ref + " " + .sha')
197197
head_branch=$(echo $response | cut -d' ' -f1)
198198
head_sha=$(echo $response | cut -d' ' -f2)
199+
rm -f dl.list
199200
curl --silent --location \
200201
-H "Accept: application/vnd.github+json" \
201202
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" \
202203
-H "X-GitHub-Api-Version: 2022-11-28" \
203204
"https://api.github.com/repos/fluent/fluent-package-builder/actions/artifacts?per_page=100&page=$d" | \
204-
jq --raw-output '.artifacts[] | select(.workflow_run.head_branch == "'$head_branch'" and .workflow_run.head_sha == "'$head_sha'") | .name + " " + .archive_download_url' | while read line
205+
jq --raw-output '.artifacts[] | select(.workflow_run.head_branch == "'$head_branch'" and .workflow_run.head_sha == "'$head_sha'") | .name + " " + (.size_in_bytes|tostring) + " " + .archive_download_url' > dl.list
206+
while read line
205207
do
206208
package=$(echo $line | cut -d' ' -f1)
207-
download_url=$(echo $line | cut -d' ' -f2)
209+
download_url=$(echo $line | cut -d' ' -f3)
208210
echo "Downloading $package.zip from $download_url"
209211
case $package in
210212
*debian*|*ubuntu*)
211213
mkdir -p apt/repositories
212214
(cd apt/repositories &&
213215
rm -f $package.zip &&
214216
curl --silent --location --output $package.zip \
215-
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url &&
216-
unzip -u -o $package.zip)
217+
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url ) &
217218
;;
218219
*centos*|*rockylinux*|*almalinux*|*amazonlinux*)
219220
mkdir -p yum/repositories
220221
(cd yum/repositories &&
221222
rm -f $package.zip &&
222223
curl --silent --location --output $package.zip \
223-
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url &&
224-
unzip -u -o $package.zip)
224+
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url ) &
225225
;;
226226
*)
227227
curl --silent --location --output $package.zip \
228-
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url
228+
-H "Authorization: Bearer $GITHUB_ACCESS_TOKEN" $download_url &
229229
;;
230230
esac
231-
done
231+
done < dl.list
232+
wait
233+
234+
verified=1
235+
while read line
236+
do
237+
package=$(echo $line | cut -d' ' -f1)
238+
download_size=$(echo $line | cut -d' ' -f2)
239+
case $package in
240+
*debian*|*ubuntu*)
241+
actual_size=$(stat --format="%s" apt/repositories/$package.zip)
242+
;;
243+
*rockylinux*|*almalinux*|*amazonlinux*)
244+
actual_size=$(stat --format="%s" yum/repositories/$package.zip)
245+
;;
246+
*)
247+
actual_size=$(stat --format="%s" $package.zip)
248+
;;
249+
esac
250+
if [ $download_size = "$actual_size" ]; then
251+
echo -e "[\e[32m\e[40mOK\e[0m] Verify apt/repositories/$package.zip"
252+
else
253+
echo -e "[\e[31m\e[40mNG\e[0m] Verify apt/repositories/$package.zip (expected: $download_size actual: $actual_size)"
254+
verified=0
255+
fi
256+
done < dl.list
257+
if [ $verified -eq 0 ]; then
258+
echo "Downloaded artifacts were corrupted! Check the downloaded artifacts."
259+
exit 1
260+
fi
261+
(cd apt/repositories && find . -name '*.zip' -exec unzip -u -o {} \;)
262+
(cd yum/repositories && find . -name '*.zip' -exec unzip -u -o {} \;)
232263
;;
233264
*)
234265
usage

0 commit comments

Comments
 (0)