The post-release-templates workflow gets triggered whenever we create a github release. It is fed the git tag. A script is then run to update the templates' migrations and lockfile (if applicable). There was a scenario where despite the packages already being published to npm a few minutes prior, this process would error out saying that the latest version was not available. This PR adds a script that polls for 5 minutes against npm to wait for the newly published version to resolve and match the git release tag.
32 lines
958 B
Bash
Executable File
32 lines
958 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [[ "$#" -ne 2 ]]; then
|
|
echo "Usage: $0 <package-name> <version>"
|
|
exit 1
|
|
fi
|
|
|
|
PACKAGE_NAME="$1"
|
|
TARGET_VERSION=${2#v} # Git tag has leading 'v', npm version does not
|
|
TIMEOUT=300 # 5 minutes in seconds
|
|
INTERVAL=10 # 10 seconds
|
|
ELAPSED=0
|
|
|
|
echo "Waiting for version ${TARGET_VERSION} of '${PACKAGE_NAME}' to resolve... (timeout: ${TIMEOUT} seconds)"
|
|
|
|
while [[ ${ELAPSED} -lt ${TIMEOUT} ]]; do
|
|
latest_version=$(npm show "${PACKAGE_NAME}" version 2>/dev/null)
|
|
|
|
if [[ ${latest_version} == "${TARGET_VERSION}" ]]; then
|
|
echo "SUCCCESS: Version ${TARGET_VERSION} of ${PACKAGE_NAME} is available."
|
|
exit 0
|
|
else
|
|
echo "Version ${TARGET_VERSION} of ${PACKAGE_NAME} is not available yet. Retrying in ${INTERVAL} seconds... (elapsed: ${ELAPSED}s)"
|
|
fi
|
|
|
|
sleep "${INTERVAL}"
|
|
ELAPSED=$((ELAPSED + INTERVAL))
|
|
done
|
|
|
|
echo "Timed out after ${TIMEOUT} seconds waiting for version ${TARGET_VERSION} of '${PACKAGE_NAME}' to resolve."
|
|
exit 1
|