Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active October 6, 2017 19:12
Show Gist options
  • Save tlrobinson/952bf5190614f1be4759d01a2584b1d7 to your computer and use it in GitHub Desktop.
Save tlrobinson/952bf5190614f1be4759d01a2584b1d7 to your computer and use it in GitHub Desktop.
Script to try updating `yarn outdated` packages, build, and run tests, committing if successful.
#!/usr/bin/env bash
set -eu
log_dir=".upgrade-frontend-deps-logs"
mkdir -p "$log_dir"
if ! git diff-index --quiet HEAD --; then
echo "Make sure the working tree doesn't have uncommitted changes"
exit 1
fi
yarn
yarn outdated | grep -E 'dependencies\s*$' | while read line; do
echo "================================================================================"
echo "$line"
package=$(echo "$line" | awk '{ print $1 }')
current=$(echo "$line" | awk '{ print $2 }')
wanted=$(echo "$line" | awk '{ print $3 }')
if [ "$current" != "$wanted" ]; then
# reset
git co . > /dev/null
yarn > /dev/null
# upgrade
if yarn upgrade "$package" > "$log_dir/$package.upgrade.out" 2> "$log_dir/$package.upgrade.err"; then
echo "Upgrade succeeded"
# build
if yarn run build > "$log_dir/$package.build.out" 2> "$log_dir/$package.build.err"; then
echo "Build succeeded"
# test
if yarn run test > "$log_dir/$package.test.out" 2> "$log_dir/$package.test.err"; then
echo "Tests succeeded"
git commit -m "Upgrade $package from $current to $wanted" -- "package.json" "yarn.lock"
else
echo "Tests failed"
fi
else
echo "Build failed"
fi
else
echo "Upgrade failed"
fi
else
echo "Skipping"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment