Skip to content

Commit 4e09712

Browse files
authored
Create pre-release pipeline (#352)
* Create prerelease pipeline * fake version update * revert fake version update
1 parent c543818 commit 4e09712

File tree

4 files changed

+167
-19
lines changed

4 files changed

+167
-19
lines changed

azure-pipelines/pre-release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
parameters:
2+
- name: NpmPublishTag
3+
displayName: 'Tag'
4+
type: string
5+
default: 'preview'
6+
- name: NpmPublishDryRun
7+
displayName: 'Dry Run'
8+
type: boolean
9+
default: true
10+
11+
trigger: none
12+
pr: none
13+
14+
resources:
15+
repositories:
16+
- repository: 1es
17+
type: git
18+
name: 1ESPipelineTemplates/1ESPipelineTemplates
19+
ref: refs/tags/release
20+
21+
extends:
22+
template: v1/1ES.Official.PipelineTemplate.yml@1es
23+
parameters:
24+
sdl:
25+
sourceAnalysisPool:
26+
name: 1es-pool-azfunc
27+
image: 1es-windows-2022
28+
os: windows
29+
codeql:
30+
runSourceLanguagesInSourceAnalysis: true
31+
pool:
32+
name: 1es-pool-azfunc
33+
image: 1es-windows-2022
34+
os: windows
35+
36+
stages:
37+
- stage: Build
38+
jobs:
39+
- template: /azure-pipelines/templates/build.yml@self
40+
parameters:
41+
# Version to be published is specified in branch
42+
IsPrerelease: false
43+
- stage: Release
44+
dependsOn: Build
45+
jobs:
46+
- job: Release
47+
steps:
48+
- task: DownloadPipelineArtifact@2
49+
inputs:
50+
artifact: drop
51+
path: $(Pipeline.Workspace)/drop
52+
displayName: 'Download artifact'
53+
- template: /azure-pipelines/templates/npm-publish-steps.yml@self
54+
parameters:
55+
tgzPath: '$(Pipeline.Workspace)/drop'
56+
NpmPublishTag: ${{ parameters.NpmPublishTag }}
57+
NpmPublishDryRun: ${{ parameters.NpmPublishDryRun }}
58+
- stage: GitHubTagAndRelease
59+
dependsOn: Release
60+
jobs:
61+
- job: GitHubTagAndRelease
62+
steps:
63+
- task: DownloadPipelineArtifact@2
64+
inputs:
65+
artifact: drop
66+
path: $(Pipeline.Workspace)/drop
67+
displayName: 'Download drop artifact'
68+
- powershell: |
69+
$files = Get-ChildItem "$(Pipeline.Workspace)\drop" -Filter "azure-functions-*.tgz"
70+
if ($files.Count -ne 1) {
71+
Write-Error "Expected one .tgz file, found $($files.Count)"
72+
exit 1
73+
}
74+
$file = $files[0].Name
75+
if ($file -match 'azure-functions-(.+)\.tgz') {
76+
$version = $Matches[1]
77+
Write-Host "Parsed version: $version"
78+
Write-Host "##vso[task.setvariable variable=version]$version"
79+
} else {
80+
Write-Error "Filename did not match expected pattern"
81+
exit 1
82+
}
83+
displayName: 'Extract version from .tgz filename'
84+
- template: /azure-pipelines/templates/github-release.yml@self
85+

azure-pipelines/release.yml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,8 @@ extends:
4444
- job: Release
4545
steps:
4646
- download: officialBuild
47-
- task: NodeTool@0
48-
displayName: 'Install Node.js'
49-
inputs:
50-
versionSpec: 18.x
51-
- script: npm ci
52-
displayName: 'npm ci'
53-
- script: 'npm run validateRelease -- --publishTag ${{ parameters.NpmPublishTag }} --dropPath "$(Pipeline.Workspace)/officialBuild/drop"'
54-
displayName: 'validate release'
55-
- script: mv *.tgz package.tgz
56-
displayName: 'Rename tgz file' # because the publish command below requires an exact path
57-
workingDirectory: '$(Pipeline.Workspace)/officialBuild/drop'
58-
- task: Npm@1
59-
displayName: 'npm publish'
60-
inputs:
61-
command: custom
62-
workingDir: '$(Pipeline.Workspace)/officialBuild/drop'
63-
verbose: true
64-
customCommand: 'publish package.tgz --tag ${{ parameters.NpmPublishTag }} --dry-run ${{ lower(parameters.NpmPublishDryRun) }}'
65-
customEndpoint: nodejs-library-npm
47+
- template: /azure-pipelines/templates/npm-publish-steps.yml@self
48+
parameters:
49+
tgzPath: '$(Pipeline.Workspace)/officialBuild/drop'
50+
NpmPublishTag: ${{ parameters.NpmPublishTag }}
51+
NpmPublishDryRun: ${{ parameters.NpmPublishDryRun }}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
steps:
2+
- powershell: |
3+
$githubToken = "$(GithubPat)"
4+
$newLibraryVersion = "$(version)"
5+
Write-Host "Debug: Version from pipeline variable is '$newLibraryVersion'"
6+
7+
# Create GitHub credential
8+
git config --global user.name "AzureFunctionsNodeJS"
9+
git config --global user.email "[email protected]"
10+
11+
# Clone Repository
12+
git clone https://[email protected]/Azure/azure-functions-nodejs-library
13+
Write-Host "Cloned azure-functions-nodejs-library into local"
14+
Set-Location "azure-functions-nodejs-library"
15+
git checkout "origin/release/$newLibraryVersion"
16+
17+
# Create release tag X.Y.Z
18+
Write-Host "Creating release tag $newLibraryVersion"
19+
git tag -a "$newLibraryVersion" -m "$newLibraryVersion"
20+
21+
# Push tag to remote
22+
git push origin $newLibraryVersion
23+
24+
displayName: 'Create and push release tag x.y.z'
25+
- powershell: |
26+
$githubUser = "$(GithubUser)"
27+
$githubToken = "$(GithubPat)"
28+
$newLibraryVersion = "$(version)"
29+
30+
# Create GitHub credential
31+
$credential = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("${githubUser}:${githubToken}"))
32+
33+
# Create Release Note
34+
Write-Host "Creating release note in GitHub"
35+
$body = (@{tag_name="$newLibraryVersion";name="Release $newLibraryVersion";body="- Fill in Release Note Here";draft=$true} | ConvertTo-Json -Compress)
36+
$response = Invoke-WebRequest -Headers @{"Cache-Control"="no-cache";"Content-Type"="application/json";"Authorization"="Basic $credential"} -Method Post -Body "$body" -Uri "https://api.github.com/repos/Azure/azure-functions-nodejs-library/releases"
37+
38+
# Return Value
39+
if ($response.StatusCode -ne 201) {
40+
Write-Host "Failed to create release note in GitHub"
41+
exit -1
42+
}
43+
44+
$draftUrl = $response | ConvertFrom-Json | Select -expand url
45+
Write-Host "Release draft created in $draftUrl"
46+
47+
displayName: 'Create GitHub release draft'
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
parameters:
2+
tgzPath: ''
3+
NpmPublishTag: ''
4+
NpmPublishDryRun: false
5+
6+
steps:
7+
- task: NodeTool@0
8+
displayName: 'Install Node.js'
9+
inputs:
10+
versionSpec: 18.x
11+
12+
- script: npm ci
13+
displayName: 'npm ci'
14+
15+
- script: 'npm run validateRelease -- --publishTag ${{ parameters.NpmPublishTag }} --dropPath "${{ parameters.tgzPath }}"'
16+
displayName: 'Validate release'
17+
name: validateReleaseStep
18+
19+
- script: mv *.tgz package.tgz
20+
displayName: 'Rename tgz file'
21+
workingDirectory: '${{ parameters.tgzPath }}'
22+
23+
- task: Npm@1
24+
displayName: 'npm publish'
25+
inputs:
26+
command: custom
27+
workingDir: '${{ parameters.tgzPath }}'
28+
verbose: true
29+
customCommand: 'publish package.tgz --tag ${{ parameters.NpmPublishTag }} --dry-run ${{ lower(parameters.NpmPublishDryRun) }}'
30+
customEndpoint: nodejs-library-npm

0 commit comments

Comments
 (0)