-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate NPM tag within publish-release bash script
If we want to release versions of GOV.UK Frontend older than the current major version, e.g: releasing a version 4.5.0. when we've already released version 5.0.0, then we need to be able to override NPM's default "tag" which tags the most recent release as "latest". Tagging v4.5.0 as "latest" would mean people doing `npm install govuk-frontend` would get v4.5.0 instead of v5.0.0. Unfortunately, the only way to NOT tag something as "latest" is to provide a different tag to tag it with. This script compares the tags on Github with the version being proposed. If the version number being proposed is smaller than the highest version tag on Github, the NPM tag will be `latest-[MAJOR-VERSION-NUMBER]` e.g: `latest-4`
- Loading branch information
Vanita Barrett
committed
May 20, 2022
1 parent
137b806
commit dabed4e
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Get highest tag published on Github | ||
HIGHEST_PUBLISHED_TAG=$(git tag --list 2>/dev/null | sort -V | tail -n1 2>/dev/null | sed 's/v//g') | ||
|
||
# Extract tag version from ./package/package.json | ||
CURRENT_TAG=$(node -p "require('./package/package.json').version") | ||
|
||
function version() { echo "$@" | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'; } | ||
|
||
if [ $CURRENT_TAG == $HIGHEST_PUBLISHED_TAG ]; then | ||
echo "⚠️ Git tag $TAG already exists. Check you have updated the version in package/package.json correctly." | ||
exit 1 | ||
elif [ $(version $CURRENT_TAG) -ge $(version $HIGHEST_PUBLISHED_TAG) ]; then | ||
NPM_TAG="latest" | ||
else | ||
major_version_num="${CURRENT_TAG:0:1}" | ||
NPM_TAG="latest-$major_version_num" | ||
fi |
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