1- # Publishes @next (alpha) versions of all npm packages via ESRP. Manual trigger only.
2- trigger : none
1+ # Publishes all npm packages via ESRP:
2+ # - @next (alpha with today's date) from main, daily on schedule
3+ # - @next (alpha with commit timestamp) from main, on manual trigger
4+ # - @beta (beta with commit timestamp) from release-* branches, on push
5+ # - @latest from v* release tags (pushed when a GitHub release is published)
6+ trigger :
7+ branches :
8+ include :
9+ - release-*
10+ tags :
11+ include :
12+ - v*
313
414pr : none
515
16+ schedules :
17+ - cron : ' 10 5 * * *'
18+ displayName : " Daily @next publish"
19+ branches :
20+ include :
21+ - main
22+ always : true
23+
624resources :
725 repositories :
826 - repository : 1esPipelines
@@ -36,12 +54,12 @@ extends:
3654 displayName : " Checkout code"
3755
3856 - task : Bash@3
39- displayName : " Check the branch is main"
57+ displayName : " Check the branch is main, release-* or a v* tag "
4058 inputs :
4159 targetType : " inline"
4260 script : |
43- if [[ "$BUILD_SOURCE_BRANCH" != "refs/heads/main" ]]; then
44- echo "Alpha versions can only be published from main."
61+ if [[ "$BUILD_SOURCE_BRANCH" != "refs/heads/main" && "$BUILD_SOURCE_BRANCH" != refs/heads/release-* && "$BUILD_SOURCE_BRANCH" != refs/tags/v* ]]; then
62+ echo "Can only publish from main, release-* branches or v* tags ."
4563 echo "Unexpected branch: $BUILD_SOURCE_BRANCH"
4664 exit 1
4765 fi
@@ -78,18 +96,44 @@ extends:
7896 displayName : " npm run build"
7997
8098 - task : Bash@3
81- displayName : " Set alpha version with commit timestamp"
99+ name : setVersion
100+ displayName : " Set version and dist-tag"
82101 inputs :
83102 targetType : " inline"
84103 script : |
85104 set -e
86- node utils/build/update_canary_version.js --alpha --commit-timestamp
105+ if [[ "$BUILD_SOURCE_BRANCH" == refs/tags/v* ]]; then
106+ # Release version is already checked in, only publish what the tag points at.
107+ NPM_DIST_TAG="latest"
108+ elif [[ "$BUILD_SOURCE_BRANCH" == refs/heads/release-* ]]; then
109+ NPM_DIST_TAG="beta"
110+ node utils/build/update_canary_version.js --beta --commit-timestamp
111+ elif [[ "$BUILD_REASON" == "Schedule" ]]; then
112+ NPM_DIST_TAG="next"
113+ node utils/build/update_canary_version.js --alpha --today-date
114+ else
115+ NPM_DIST_TAG="next"
116+ node utils/build/update_canary_version.js --alpha --commit-timestamp
117+ fi
87118 node utils/workspace.js --ensure-consistent
88119 VERSION=$(node utils/workspace.js --get-version)
89- if [[ "$VERSION" != *-alpha-* ]]; then
120+ if [[ "$NPM_DIST_TAG" == "latest" && "$BUILD_SOURCE_BRANCH" != "refs/tags/v$VERSION" ]]; then
121+ echo "ERROR: version '$VERSION' does not match tag '$BUILD_SOURCE_BRANCH'"
122+ exit 1
123+ fi
124+ if [[ "$NPM_DIST_TAG" == "beta" && "$VERSION" != *-beta-* ]]; then
125+ echo "ERROR: unexpected version '$VERSION', must be a beta version"
126+ exit 1
127+ fi
128+ if [[ "$NPM_DIST_TAG" == "next" && "$VERSION" != *-alpha-* ]]; then
90129 echo "ERROR: unexpected version '$VERSION', must be an alpha version"
91130 exit 1
92131 fi
132+ echo "Publishing version $VERSION with dist-tag $NPM_DIST_TAG"
133+ echo "##vso[task.setvariable variable=npmDistTag;isOutput=true]$NPM_DIST_TAG"
134+ env :
135+ BUILD_SOURCE_BRANCH : $(Build.SourceBranch)
136+ BUILD_REASON : $(Build.Reason)
93137
94138 - task : Bash@3
95139 displayName : " Pack all packages"
@@ -106,6 +150,8 @@ extends:
106150 - job : Publish
107151 displayName : " ESRP Release to npm"
108152 dependsOn : Build
153+ variables :
154+ npmDistTag : $[ dependencies.Build.outputs['setVersion.npmDistTag'] ]
109155 templateContext :
110156 type : releaseJob
111157 isProduction : true
@@ -125,7 +171,7 @@ extends:
125171 intent : ' PackageDistribution'
126172 contenttype : ' npm'
127173 # npm dist-tag to publish with.
128- productstate : ' next '
174+ productstate : ' $(npmDistTag) '
129175 folderlocation : ' $(Build.ArtifactStagingDirectory)/esrp-build'
130176 waitforreleasecompletion : true
131177 owners : ' yurys@microsoft.com'
0 commit comments