Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ICRC_Ledger): FI-1600: Download the latest ICRC ledger release instead of tip of master #3538

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 55 additions & 19 deletions rs/rosetta-api/scripts/download_latest_icrc1_ledger.sh
Original file line number Diff line number Diff line change
@@ -1,38 +1,74 @@
#!/usr/bin/env bash

set -uo pipefail
#set -x

COMMITS=$(curl -sLf -H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/dfinity/ic/commits?per_page=100" \
| jq '.[].sha' | tr -d \")

if [ "$?" -ne "0" ]; then
echo >&2 "Unable to fetch the commits from dfinity/ic. Please try again"
exit 1
fi
### Configuration
RELEASE_TAG_PREFIX=ledger-suite-icrc

for COMMIT in $COMMITS; do
### Download a specific release
## Download the ICRC ledger WASM and did files for a specific release. The files are downloaded
## from the github release page for the given release.
download_release() {
RELEASE=$1
STATUS_CODE=$(curl -s -o /dev/null -w "%{http_code}" -L --head \
"https://download.dfinity.systems/ic/$COMMIT/canisters/ic-icrc1-ledger.wasm.gz")
"https://github.com/dfinity/ic/releases/download/${RELEASE}/ic-icrc1-ledger.wasm.gz")
if (($STATUS_CODE >= 200)) && (($STATUS_CODE < 300)); then
echo "Found artifacts for commit $COMMIT. Downloading icrc1_ledger.did and icrc1_ledger.wasm.gz"
curl -sLf "https://raw.githubusercontent.com/dfinity/ic/$COMMIT/rs/ledger_suite/icrc1/ledger/ledger.did" \
echo "Found artifacts for release $RELEASE. Downloading icrc1_ledger.did and icrc1_ledger.wasm.gz"
curl -sLf "https://github.com/dfinity/ic/releases/download/${RELEASE}/ledger.did" \
-o icrc1_ledger.did
if [ "$?" -ne "0" ]; then
echo >&2 "Unable to download the icrc1 ledger did file. Please try again"
exit 2
fi
curl -sLf "https://download.dfinity.systems/ic/$COMMIT/canisters/ic-icrc1-ledger.wasm.gz" \
curl -sLf "https://github.com/dfinity/ic/releases/download/${RELEASE}/ic-icrc1-ledger.wasm.gz" \
-o icrc1_ledger.wasm.gz
if [ "$?" -ne "0" ]; then
echo >&2 "Unable to download the icrc1 ledger wasm file. Please try again"
exit 3
fi
exit 0
fi
done
}

### Find and download the latest ICRC ledger WASM and did file
## List the releases from the repository, looking for the most recent release where the corresponding
## tag starts with the expected prefix. Retrieves releases one page at a time, stopping if no release
## was found in some predefined maximum number of pages. Once a release is found, download the ledger
## WASM and did files.
find_and_download_release() {
PAGE=1
ITEMS_PER_PAGE=100
MAX_PAGES=10
while true; do
ITEM=0
# Unauthenticated requests are rate limited (per IP address) to 60 requests/hr
# https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28#primary-rate-limit-for-unauthenticated-users
REL_JSON=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/dfinity/ic/releases\?per_page\=${ITEMS_PER_PAGE}\&page\=${PAGE})
if [ "$?" -ne "0" ]; then
echo >&2 "Unable to fetch the releases from dfinity/ic."
exit 1
fi
while [ ${ITEM} -lt ${ITEMS_PER_PAGE} ]; do
RELEASE=$(echo ${REL_JSON} | jq ".[${ITEM}].tag_name" | tr -d '"')
if [ "$?" -ne "0" ]; then
echo >&2 "Error parsing release from response."
exit 1
fi
if [[ ${RELEASE} == ${RELEASE_TAG_PREFIX}* ]]; then
download_release "${RELEASE}"
break
else
ITEM=$((ITEM + 1))
fi
done
PAGE=$((PAGE + 1))
if [ ${PAGE} -gt ${MAX_PAGES} ]; then
echo "No ${RELEASE_TAG_PREFIX} release found in the first ${MAX_PAGES} with ${ITEMS_PER_PAGE} items per page, aborting."
exit 1
fi
done
}

echo "No commits with artifacts found"
exit 4
find_and_download_release
Loading