Skip to content

Commit d726942

Browse files
authored
Ensure npm publish succeeds when publishing non-latest versions (#2754)
1 parent 1650e3d commit d726942

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

.github/workflows/npm-publish.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,20 @@ jobs:
2727
run: |
2828
version=$(jq -r .version package.json)
2929
tag_meta=$(echo "$version" | cut -s -d '-' -f2)
30+
# if no meta info on the version (e.g. a '-alpha.1' prefix), publish as a stable release
3031
if [[ -z "$tag_meta" ]]; then
31-
npm publish --provenance --access public
32+
# get latest version on npm
33+
latest=$(npm view @elastic/elasticsearch --json | jq -r '.["dist-tags"].latest')
34+
35+
# if $version is higher than the most recently published version, publish as-is
36+
if [[ $(yes | npx semver "$version" "$latest" | tail -n1) == "$version" ]]; then
37+
npm publish --provenance --access public
38+
else
39+
# otherwise, publish with "previous" tag
40+
npm publish --provenance --access public --tag "previous"
41+
fi
3242
else
43+
# publish as a non-stable release using the meta name (e.g. 'alpha') as the tag
3344
tag=$(echo "$tag_meta" | cut -d '.' -f1)
3445
npm publish --provenance --access public --tag "$tag"
3546
fi

0 commit comments

Comments
 (0)