Skip to content

Commit

Permalink
Recover if publishing packages fails part-way through
Browse files Browse the repository at this point in the history
Co-Authored-By: Alba Herrerias <[email protected]>
  • Loading branch information
jcoglan and AlbaHerrerias committed Dec 14, 2022
1 parent 4dcaac8 commit 5b07d18
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 17 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tests/integration/utils-bundle.js
package-lock.json
yarn.lock
/.eslintcache
release-todo.txt
71 changes: 71 additions & 0 deletions bin/publish-packages.sh
Original file line number Diff line number Diff line change
@@ -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
19 changes: 2 additions & 17 deletions bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5b07d18

Please sign in to comment.