Skip to content

Commit b9ad9b5

Browse files
authored
Backport: Enable parallel download artifacts (#768) (#792)
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 6595142 commit b9ad9b5

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

0 commit comments

Comments
 (0)