Skip to content

Commit f2bcc8a

Browse files
committed
Publish official packages from main branch only
This lets us get around problems with publishing to multiple pre-release tags without needing to bump package versions after each release.
1 parent 781cfe0 commit f2bcc8a

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

.vsts/common/publish-packages.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
package_name=$1
6+
if [ -z $package_name ]; then
7+
echo "Failed to publish package: No package name supplied"
8+
exit 1
9+
fi
10+
11+
ver=$(npm pkg get version | sed 's/"//g')
12+
package_version=$(echo "$ver-$DIST_TAG.$BUILD_BUILDNUMBER" | sed 's/_//g')
13+
14+
# Publish only from the main branch for now so that we don't have to worry
15+
# about version bumping after releases from different branches.
16+
if [ $(git symbolic-ref -q --short HEAD) = 'main' ]; then
17+
echo "Publishing package $package_name@$package_version"
18+
19+
npm version --no-git-tag-version $package_version
20+
npm publish --tag $DIST_TAG
21+
else
22+
echo "Skipped publishing $package_name@$package_version: Packages are only published from the main branch."
23+
fi

.vsts/linux/publish-npm-package.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ parameters:
33
packageName: ''
44

55
steps:
6-
- bash: |
7-
set -e
8-
ver=$(npm pkg get version | sed 's/"//g')
9-
package_version=$(echo "$ver-$DIST_TAG.$BUILD_BUILDNUMBER" | sed 's/_//g')
10-
echo "Publishing package ${{parameters.packageName}}@$package_version"
11-
npm version --no-git-tag-version $package_version
12-
npm publish --tag $DIST_TAG
13-
displayName: "Publish package: ${{parameters.packageName}}"
14-
workingDirectory: ${{parameters.packagePath}}
6+
- bash: $(Build.SourcesDirectory)/.vsts/common/publish-packages.sh ${{parameters.packageName}}
7+
displayName: "Publish package: ${{parameters.packageName}}"
8+
workingDirectory: ${{parameters.packagePath}}

0 commit comments

Comments
 (0)