Skip to content

Instantly share code, notes, and snippets.

@jrmullen
Last active May 22, 2020 20:00
Show Gist options
  • Save jrmullen/6199fe4283e9f0cd89f1e44c07c73aa8 to your computer and use it in GitHub Desktop.
Save jrmullen/6199fe4283e9f0cd89f1e44c07c73aa8 to your computer and use it in GitHub Desktop.
CI step to check whether a package.json version number has been bumped
#!/bin/bash
# Pull repo name from first argument
repo_name=$1
# Pull the latest release version from NPM
latest_release=$(npm show $repo_name version)
echo "Latest released version" $latest_release
# Pull the version from package.json
package_version=$(node -p "require('./package.json').version")
echo "Current package version" $package_version
# Comma-delimit the versions, translate the commas into newlines,
# sort by version (-V) in reverse order (-r), and return the top result
highest_semver=$(echo "$package_version,$latest_release" | tr ',' '\n' | sort -rV | head -1)
# If the highest version is the one from NPM, your package version is behind
if [ $highest_semver == $latest_release ]; then
echo "Package version already exists"
exit 1;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment