Commit 8ed29a7b by Stephanie Closson Committed by GitHub

Toolkit: handle 404 errors gracefully on unpublish in circleci-release-next-packages.sh (#23417)

* handle 404 errors gracefully

* need to redirect stderr to stdout to check for 404s
parent 4a2a2b16
...@@ -10,7 +10,7 @@ function parse_git_hash() { ...@@ -10,7 +10,7 @@ function parse_git_hash() {
git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/\1/" git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/\1/"
} }
function prapare_version_commit () { function prepare_version_commit () {
echo $'\nCommiting version changes. This commit will not be checked-in!' echo $'\nCommiting version changes. This commit will not be checked-in!'
git config --global user.email "circleci@grafana.com" git config --global user.email "circleci@grafana.com"
git config --global user.name "CirceCI" git config --global user.name "CirceCI"
...@@ -18,23 +18,24 @@ function prapare_version_commit () { ...@@ -18,23 +18,24 @@ function prapare_version_commit () {
} }
function unpublish_previous_canary () { function unpublish_previous_canary () {
_package=$1
echo $'\nUnpublishing previous canary packages' echo $'\nUnpublishing previous canary packages'
for PACKAGE in "${PACKAGES[@]}" # dist-tag next to be changed to canary when https://github.com/grafana/grafana/pull/18195 is merged
do CURRENT_CANARY=$(npm view @grafana/"${_package}" dist-tags.canary)
# dist-tag next to be changed to canary when https://github.com/grafana/grafana/pull/18195 is merged if [ -z "${CURRENT_CANARY}" ]; then
CURRENT_CANARY=$(npm view @grafana/"${PACKAGE}" dist-tags.canary) echo "@grafana/${_package} - Nothing to unpublish"
if [ -z "${CURRENT_CANARY}" ]; then else
echo "@grafana/${PACKAGE} - Nothing to unpublish" echo "Unpublish @grafana/${_package}@${CURRENT_CANARY}"
else _response=$(npm unpublish @grafana/"${_package}"@"${CURRENT_CANARY}" 2>&1) || (
echo "Unpublish @grafana/${PACKAGE}@${CURRENT_CANARY}" echo "$_response" | grep "404" || (
npm unpublish "@grafana/${PACKAGE}@${CURRENT_CANARY}" || (
# We want to deprecate here, rather than fail and return an non-0 exit code # We want to deprecate here, rather than fail and return an non-0 exit code
echo "Unpublish unsucessful [$?]. Deprecating @grafana/${PACKAGE}@${CURRENT_CANARY}" echo "Unpublish unsuccessful [$?]. Deprecating @grafana/${_package}@${CURRENT_CANARY}"
# But if this fails, return the error code _response=$(npm deprecate @grafana/"${_package}"@"${CURRENT_CANARY}" "this package has been deprecated" 2>&1) || (
npm deprecate "@grafana/${PACKAGE}@${CURRENT_CANARY}" echo "$_response" | grep "404" && return 0
)
) )
fi )
done fi
} }
# Get current version from lerna.json # Get current version from lerna.json
...@@ -47,7 +48,7 @@ echo "Current lerna.json version: ${PACKAGE_VERSION}" ...@@ -47,7 +48,7 @@ echo "Current lerna.json version: ${PACKAGE_VERSION}"
# check if there were any changes to packages between current and previous commit # check if there were any changes to packages between current and previous commit
count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}') count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}')
count="1"
if [ -z "$count" ]; then if [ -z "$count" ]; then
echo "No changes in packages, skipping packages publishing" echo "No changes in packages, skipping packages publishing"
else else
...@@ -57,6 +58,7 @@ else ...@@ -57,6 +58,7 @@ else
echo $'\nGit status:' echo $'\nGit status:'
git status -s git status -s
prepare_version_commit
echo $'\nBuilding packages' echo $'\nBuilding packages'
...@@ -66,20 +68,19 @@ else ...@@ -66,20 +68,19 @@ else
yarn workspace @grafana/"${PACKAGE}" run build yarn workspace @grafana/"${PACKAGE}" run build
runtime=$((($(date +%s%N) - start)/1000000)) runtime=$((($(date +%s%N) - start)/1000000))
if [ "${CIRCLE_BRANCH}" == "master" ]; then if [ "${CIRCLE_BRANCH}" == "master" ]; then
exit_if_fail ./scripts/ci-metrics-publisher.sh "grafana.ci-buildtimes.$CIRCLE_JOB.$PACKAGE=$runtime" exit_if_fail ./scripts/ci-metrics-publisher.sh "grafana.ci-buildtimes.$CIRCLE_JOB.$PACKAGE=$runtime"
fi
exit_status=$?
if [ $exit_status -eq 0 ]; then
unpublish_previous_canary "$PACKAGE"
else
echo "Packages build failed, skipping canary release"
# TODO: notify on slack/email?
exit
fi fi
done done
exit_status=$?
if [ $exit_status -eq 1 ]; then
echo "Packages build failed, skipping canary release"
# TODO: notify on slack/email?
exit
fi
prapare_version_commit
unpublish_previous_canary
echo $'\nPublishing packages' echo $'\nPublishing packages'
yarn packages:publishCanary yarn packages:publishCanary
fi fi
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment