Skip to content

Commit df0b272

Browse files
authored
Fix package publishing script (#2741)
This was broken because the Git repo on the DevOps pipelines runs on a detached HEAD. Use the DevOps environment variable to read the target branch instead of using git symbolic-ref.
1 parent 1ec04b8 commit df0b272

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

.vsts/common/publish-packages.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
set -e
44

5-
package_name=$1
5+
branch=$1
6+
if [ -z $1 ]; then
7+
echo "Failed to publish package: No branch name supplied"
8+
exit 1
9+
fi
10+
11+
package_name=$2
612
if [ -z $package_name ]; then
713
echo "Failed to publish package: No package name supplied"
814
exit 1
@@ -11,11 +17,15 @@ fi
1117
ver=$(npm pkg get version | sed 's/"//g')
1218
package_version=$(echo "$ver-$DIST_TAG.$BUILD_BUILDNUMBER" | sed 's/_//g')
1319

20+
echo "Publishing package $package_name@$package_version"
21+
echo "=================================="
22+
echo "Working dir: $PWD"
23+
echo "Branch: $branch"
24+
echo "=================================="
25+
1426
# Publish only from the main branch for now so that we don't have to worry
1527
# 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-
28+
if [ "$branch" = "refs/heads/main" ]; then
1929
npm version --no-git-tag-version $package_version
2030
npm publish --tag $DIST_TAG
2131
else

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ parameters:
33
packageName: ''
44

55
steps:
6-
- bash: $(Build.SourcesDirectory)/.vsts/common/publish-packages.sh ${{parameters.packageName}}
6+
- script: |
7+
set -e
8+
$(Build.SourcesDirectory)/.vsts/common/publish-packages.sh $(Build.SourceBranch) ${{parameters.packageName}}
79
displayName: "Publish package: ${{parameters.packageName}}"
810
workingDirectory: ${{parameters.packagePath}}

0 commit comments

Comments
 (0)