Skip to content

Commit

Permalink
Merge branch 'pipeline_fix_asset_upload' into 'master'
Browse files Browse the repository at this point in the history
Account for pagination when looking up package id during asset upload

See merge request evernym/utilities/devlab!9
  • Loading branch information
absltkaos committed Aug 18, 2021
2 parents cfdafb4 + 31fa853 commit 461afaf
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
27 changes: 1 addition & 26 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,32 +104,7 @@ upload_release_asset:
needs:
- make_pkg
script:
- |
if [ "${CI_COMMIT_TAG:0:1}" == "v" ] ; then
export VERSION=${CI_COMMIT_TAG:1}
fi
- |
for asset in $(find artifacts/ -type f) ; do
fname=$(basename $asset)
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $asset ${PACKAGE_REGISTRY_URL}/${VERSION}/${fname} || exit 1
echo "Looking up package id"
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
if [ -z "$pkg_id" ] ; then
echo "Failed looking up package id"
echo "$pkg_id"
exit 1
fi
echo "Looking up file inside package"
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
if [ -z "$pkg_file_id" ] ; then
echo "Failed looking up package file id"
echo "$pkg_file_id"
exit 1
fi
echo "Generating the direct download link"
direct_dl="${CI_PROJECT_URL}/-/package_files/${pkg_file_id}/download"
echo "$fname|${direct_dl}" >> ./artifacts/assets.out
done
- ci/upload_release_asset.sh
artifacts:
paths:
- artifacts/assets.out
Expand Down
42 changes: 42 additions & 0 deletions ci/upload_release_asset.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

if [ "${CI_COMMIT_TAG:0:1}" == "v" ] ; then
export VERSION=${CI_COMMIT_TAG:1}
fi

for asset in $(find artifacts/ -type f) ; do
fname=$(basename $asset)
echo "Uploading asset: $asset"
curl --header "JOB-TOKEN: ${CI_JOB_TOKEN}" --upload-file $asset ${PACKAGE_REGISTRY_URL}/${VERSION}/${fname} || exit 1
echo "Looking up package id"
page=1
while [ ! -z "$page" ] ; do
echo "Checking for package id on page: ${page}"
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")
if [ $? -ne 0 ] ; then
echo "Failed querying repo's packages at: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?page=${page}"
exit 1
fi
if [ ! -z "$pkg_id" ] ; then
echo "Found pkg_id: $pkg_id"
break
fi
curl_headers=$(curl -sfI ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages?page=${page})
page=$(echo "$curl_headers" | grep -i '^x-next-page' | grep -o '[0-9]\+')
done
if [ -z "$pkg_id" ] ; then
echo "Failed looking up package id"
echo "$pkg_id"
exit 1
fi
echo "Looking up file inside package"
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
if [ -z "$pkg_file_id" ] ; then
echo "Failed looking up package file id"
echo "$pkg_file_id"
exit 1
fi
echo "Generating the direct download link"
direct_dl="${CI_PROJECT_URL}/-/package_files/${pkg_file_id}/download"
echo "$fname|${direct_dl}" >> ./artifacts/assets.out
done

0 comments on commit 461afaf

Please sign in to comment.