Skip to content

Commit 461afaf

Browse files
committed
Merge branch 'pipeline_fix_asset_upload' into 'master'
Account for pagination when looking up package id during asset upload See merge request evernym/utilities/devlab!9
2 parents cfdafb4 + 31fa853 commit 461afaf

2 files changed

Lines changed: 43 additions & 26 deletions

File tree

.gitlab-ci.yml

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -104,32 +104,7 @@ upload_release_asset:
104104
needs:
105105
- make_pkg
106106
script:
107-
- |
108-
if [ "${CI_COMMIT_TAG:0:1}" == "v" ] ; then
109-
export VERSION=${CI_COMMIT_TAG:1}
110-
fi
111-
- |
112-
for asset in $(find artifacts/ -type f) ; do
113-
fname=$(basename $asset)
114-
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $asset ${PACKAGE_REGISTRY_URL}/${VERSION}/${fname} || exit 1
115-
echo "Looking up package id"
116-
pkg_id=$(curl -sf ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages | jq ".[] | select(.version==\"${VERSION}\") | select(.name==\"devlab\") | select(.package_type==\"generic\") | .id") || exit 1
117-
if [ -z "$pkg_id" ] ; then
118-
echo "Failed looking up package id"
119-
echo "$pkg_id"
120-
exit 1
121-
fi
122-
echo "Looking up file inside package"
123-
pkg_file_id=$(curl -sf "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/${pkg_id}/package_files" | jq ".[] | select(.file_name==\"${fname}\") | .id") || exit 1
124-
if [ -z "$pkg_file_id" ] ; then
125-
echo "Failed looking up package file id"
126-
echo "$pkg_file_id"
127-
exit 1
128-
fi
129-
echo "Generating the direct download link"
130-
direct_dl="${CI_PROJECT_URL}/-/package_files/${pkg_file_id}/download"
131-
echo "$fname|${direct_dl}" >> ./artifacts/assets.out
132-
done
107+
- ci/upload_release_asset.sh
133108
artifacts:
134109
paths:
135110
- artifacts/assets.out

ci/upload_release_asset.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
if [ "${CI_COMMIT_TAG:0:1}" == "v" ] ; then
4+
export VERSION=${CI_COMMIT_TAG:1}
5+
fi
6+
7+
for asset in $(find artifacts/ -type f) ; do
8+
fname=$(basename $asset)
9+
echo "Uploading asset: $asset"
10+
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $asset ${PACKAGE_REGISTRY_URL}/${VERSION}/${fname} || exit 1
11+
echo "Looking up package id"
12+
page=1
13+
while [ ! -z "$page" ] ; do
14+
echo "Checking for package id on page: ${page}"
15+
pkg_id=$(curl -sf ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?page=${page} | jq ".[] | select(.version==\"${VERSION}\") | select(.name==\"devlab\") | select(.package_type==\"generic\") | .id")
16+
if [ $? -ne 0 ] ; then
17+
echo "Failed querying repo's packages at: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?page=${page}"
18+
exit 1
19+
fi
20+
if [ ! -z "$pkg_id" ] ; then
21+
echo "Found pkg_id: $pkg_id"
22+
break
23+
fi
24+
curl_headers=$(curl -sfI ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?page=${page})
25+
page=$(echo "$curl_headers" | grep -i '^x-next-page' | grep -o '[0-9]\+')
26+
done
27+
if [ -z "$pkg_id" ] ; then
28+
echo "Failed looking up package id"
29+
echo "$pkg_id"
30+
exit 1
31+
fi
32+
echo "Looking up file inside package"
33+
pkg_file_id=$(curl -sf "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/${pkg_id}/package_files" | jq ".[] | select(.file_name==\"${fname}\") | .id") || exit 1
34+
if [ -z "$pkg_file_id" ] ; then
35+
echo "Failed looking up package file id"
36+
echo "$pkg_file_id"
37+
exit 1
38+
fi
39+
echo "Generating the direct download link"
40+
direct_dl="${CI_PROJECT_URL}/-/package_files/${pkg_file_id}/download"
41+
echo "$fname|${direct_dl}" >> ./artifacts/assets.out
42+
done

0 commit comments

Comments
 (0)