From 5b07d18d28fb8472fc35d914b911786e671cc08f Mon Sep 17 00:00:00 2001 From: James Coglan Date: Wed, 14 Dec 2022 15:45:07 +0000 Subject: [PATCH] Recover if publishing packages fails part-way through Co-Authored-By: Alba Herrerias --- .gitignore | 1 + bin/publish-packages.sh | 71 +++++++++++++++++++++++++++++++++++++++++ bin/release.sh | 19 ++--------- 3 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 bin/publish-packages.sh diff --git a/.gitignore b/.gitignore index 475cbf68da..c67c05b23e 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ tests/integration/utils-bundle.js package-lock.json yarn.lock /.eslintcache +release-todo.txt diff --git a/bin/publish-packages.sh b/bin/publish-packages.sh new file mode 100644 index 0000000000..b3ebf38c7c --- /dev/null +++ b/bin/publish-packages.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +set -e + +publish_packages () { + local root_dir="$PWD" + local todo="$root_dir/release-todo.txt" + + if [[ ! -e "$todo" ]] ; then + echo 'No packages to release, quitting.' + return 0 + fi + + local pkgs=($(cat "$todo")) + local failed='n' + + for pkg in "${pkgs[@]}" ; do + cd "$root_dir" + + if ! should_publish "$pkg" ; then + continue + fi + + if [[ "$failed" == 'n' ]] ; then + if ! publish_package "$pkg" ; then + failed='y' + echo "Publishing '$pkg' failed, quitting." + echo "$pkg" > "$todo" + fi + else + echo "$pkg" >> "$todo" + fi + done + + if [[ "$failed" == 'n' ]] ; then + rm "$todo" + fi +} + +should_publish () { + local pkg="$1" + + if [ ! -d "packages/node_modules/$pkg" ]; then + return 1 + elif [ "true" = $(node --eval "console.log(require('./packages/node_modules/$pkg/package.json').private);") ]; then + return 1 + else + return 0 + fi +} + +publish_package () { + local pkg="$1" + + cd "packages/node_modules/$pkg" + echo "Publishing $pkg..." + + if [ -n "$DRY_RUN" ]; then + echo "Dry run, not publishing" + elif [ -n "$BETA" ]; then + if ! npm publish --tag beta ; then + return 1 + fi + else + if ! npm publish ; then + return 1 + fi + fi +} + +publish_packages diff --git a/bin/release.sh b/bin/release.sh index a3bd78052e..d449db3962 100755 --- a/bin/release.sh +++ b/bin/release.sh @@ -26,23 +26,8 @@ git checkout -b $BUILD_DIR node bin/update-package-json-for-publish.js # Publish all modules with Lerna -for pkg in $(ls packages/node_modules); do - if [ ! -d "packages/node_modules/$pkg" ]; then - continue - elif [ "true" = $(node --eval "console.log(require('./packages/node_modules/$pkg/package.json').private);") ]; then - continue - fi - cd packages/node_modules/$pkg - echo "Publishing $pkg..." - if [ ! -z $DRY_RUN ]; then - echo "Dry run, not publishing" - elif [ ! -z $BETA ]; then - npm publish --tag beta - else - npm publish - fi - cd - -done +ls packages/node_modules > release-todo.txt +sh bin/publish-packages.sh # Create git tag, which is also the Bower/Github release rm -fr lib src dist bower.json component.json package.json