Last active
May 22, 2020 20:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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