Skip to content

Commit 4f9be54

Browse files
jpogranglennsarti
andcommitted
(maint) Release documentation
This commit documents the release process for a Marketplace release of the Puppet Extension. It also updates the release tool to extract the release notes in the Changelog. Co-authored-by: Glenn Sarti <[email protected]>
1 parent 92b9550 commit 4f9be54

File tree

2 files changed

+212
-0
lines changed

2 files changed

+212
-0
lines changed

tools/RELEASE.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Release Puppet Extension for VSCode
2+
3+
## Pre-release steps
4+
5+
### Vendor Latest Puppet Language Server and Syntax Files
6+
7+
1. Ensure [puppet-editor-services](https://github.com/lingua-pupuli/puppet-editor-services) has been tagged and release process followed. Note version.
8+
1. Ensure [puppet-editor-syntax](https://github.com/lingua-pupuli/puppet-editor-syntax) has been tagged and release process followed. Note version.
9+
1. `git clone https://github.com/lingua-pupuli/puppet-vscode` or `git clean -xfd` on working copy
10+
1. Update `editor-components.json` with latest `puppet-editor-services` and `puppet-editor-syntax` versions. These can be seperate commits
11+
1. Create PR
12+
13+
## Prepare VSCode extension
14+
15+
1. `git clone https://github.com/lingua-pupuli/puppet-vscode` or `git clean -xfd` on working copy
16+
1. Update `CHANGELOG` with all tickets from release milestone for `puppet-vscode`, and any tickets from `puppet-editor-services` and `puppet-editor-syntax` that apply to this release.
17+
1. Increment `version` field of `package.json`
18+
1. Run `npm install` to update `package-lock.json`
19+
1. `git commit -m '(maint) Release <version>'`
20+
1. Create release PR
21+
22+
## Package VSCode extension
23+
24+
1. `git clone https://github.com/lingua-pupuli/puppet-vscode` or `git clean -xfd` on working copy
25+
1. `git tag -a '<version>' -m '<version>' <commit id>`
26+
1. `git push <remote> <version>`
27+
1. `git checkout <version>`
28+
1. `git reset --hard <version>`
29+
1. `mkdir 'output'`
30+
1. `npm install` (this should produce no changes, but package-lock.json may be different, safe to ignore)
31+
1. `npx vsce package`
32+
1. `mv "puppet-vscode-*.vsix" 'output'`
33+
1. `./tools/release.ps1 -releaseversion <version> -guthubusername 'lingua-pupuli' -githubtoken <token>`
34+
35+
## Publish VSCode extnsion
36+
37+
1. Install personal access token from https://pogran.visualstudio.com/puppet-vscode ([instructions](https://code.visualstudio.com/api/working-with-extensions/publishing-extension#get-a-personal-access-token))
38+
1. `git clone https://github.com/lingua-pupuli/puppet-vscode` or `git clean -xfd` on working copy
39+
1. `npm install`
40+
1. `npmx vsce publish`

tools/release.ps1

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
param(
2+
[parameter(Mandatory = $true)]
3+
[String]$ReleaseVersion,
4+
5+
[parameter(Mandatory = $true)]
6+
[String]$GitHubUsername,
7+
8+
[parameter(Mandatory = $true)]
9+
[String]$GitHubToken
10+
)
11+
12+
$ErrorActionPreference = 'Stop'
13+
14+
# Adapted from https://www.herebedragons.io/powershell-create-github-release-with-artifact
15+
function Update-GitHubRelease {
16+
param(
17+
$VersionNumber,
18+
$PreRelease,
19+
$ReleaseNotes,
20+
$ArtifactOutputDirectory,
21+
$GitHubUsername,
22+
$GitHubRepository,
23+
$GitHubApiUsername,
24+
$GitHubApiKey
25+
)
26+
27+
$draft = $false
28+
29+
$auth = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes($gitHubApiUsername + ':' + $gitHubApiKey));
30+
31+
# Github uses TLS 1.2
32+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
33+
34+
# Find existing release
35+
$ReleaseDetails = $null
36+
$releaseParams = @{
37+
Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases/tags/$versionNumber";
38+
Method = 'GET';
39+
ContentType = 'application/json';
40+
Headers = @{
41+
Authorization = $auth;
42+
}
43+
}
44+
45+
try {
46+
$ReleaseDetails = Invoke-RestMethod @releaseParams
47+
}
48+
catch {
49+
# Release is missing, create it
50+
$ReleaseDetails = $null
51+
}
52+
53+
if ($ReleaseDetails -eq $null) {
54+
Write-Host "Creating release $versionNumber"
55+
# Create a release
56+
$releaseData = @{
57+
tag_name = [string]::Format("{0}", $versionNumber);
58+
name = [string]::Format("{0}", $versionNumber);
59+
body = $releaseNotes;
60+
draft = $draft;
61+
prerelease = $preRelease;
62+
}
63+
$releaseParams = @{
64+
ContentType = 'application/json'
65+
Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases";
66+
Method = 'POST';
67+
Headers = @{
68+
Authorization = $auth;
69+
}
70+
Body = (ConvertTo-Json $releaseData -Compress)
71+
}
72+
$ReleaseDetails = Invoke-RestMethod @releaseParams
73+
}
74+
else {
75+
Write-Host "Updating release $versionNumber"
76+
# Create a release
77+
$releaseData = @{
78+
tag_name = [string]::Format("{0}", $versionNumber);
79+
name = [string]::Format("{0}", $versionNumber);
80+
body = $releaseNotes;
81+
draft = $draft;
82+
prerelease = $preRelease;
83+
}
84+
$releaseParams = @{
85+
ContentType = 'application/json'
86+
Uri = "https://api.github.com/repos/$gitHubUsername/$gitHubRepository/releases/$($ReleaseDetails.id)";
87+
Method = 'PATCH';
88+
Headers = @{
89+
Authorization = $auth;
90+
}
91+
Body = (ConvertTo-Json $releaseData -Compress)
92+
}
93+
$ReleaseDetails = Invoke-RestMethod @releaseParams
94+
}
95+
96+
# Upload assets
97+
$uploadUri = $ReleaseDetails | Select-Object -ExpandProperty upload_url
98+
$uploadUri = $uploadUri -creplace '\{\?name,label\}'
99+
100+
if (Test-Path -Path $artifactOutputDirectory) {
101+
Get-ChildItem -Path $artifactOutputDirectory | ForEach-Object {
102+
$filename = $_.Name
103+
$filepath = $_.Fullname
104+
Write-Host "Uploading $filename ..."
105+
106+
$uploadParams = @{
107+
Uri = $uploadUri;
108+
Method = 'POST';
109+
Headers = @{
110+
Authorization = $auth;
111+
}
112+
ContentType = 'application/text';
113+
InFile = $filepath
114+
}
115+
116+
if ($filename -match '\.zip$') {
117+
$uploadParams.ContentType = 'application/zip'
118+
}
119+
if ($filename -match '\.gz$') {
120+
$uploadParams.ContentType = 'application/tar+gzip'
121+
}
122+
$uploadParams.Uri += "?name=$filename"
123+
124+
Invoke-RestMethod @uploadParams | Out-Null
125+
}
126+
} else {
127+
Write-Host "No assets to upload as '$artifactOutputDirectory' doesn't exist"
128+
}
129+
}
130+
131+
function Get-ReleaseNotes {
132+
param($Version)
133+
134+
Write-Host "Getting release notes for version $Version ..."
135+
136+
$changelog = Join-Path -Path $PSScriptRoot -ChildPath '..\CHANGELOG.md'
137+
$releaseNotes = $null
138+
$inSection = $false
139+
140+
Get-Content $changelog | ForEach-Object {
141+
$line = $_
142+
143+
if ($inSection) {
144+
if ($line -match "^## ") {
145+
$inSection = $false
146+
}
147+
else {
148+
$releaseNotes = $releaseNotes + "`n" + $line
149+
}
150+
}
151+
else {
152+
if (($line -match "^## \[${version}\] ") -or ($line -match "^## ${version} ")) {
153+
$releaseNotes = $line
154+
$inSection = $true
155+
}
156+
}
157+
}
158+
159+
return ($releaseNotes -replace "\[${version}\]", $version)
160+
}
161+
162+
$params = @{
163+
VersionNumber = $releaseVersion
164+
PreRelease = $false
165+
ReleaseNotes = (Get-ReleaseNotes -Version $releaseVersion)
166+
ArtifactOutputDirectory = 'output'
167+
GitHubUsername = 'lingua-pupuli'
168+
GitHubRepository = 'puppet-vscode'
169+
GitHubApiUsername = $GitHubUsername
170+
GitHubApiKey = $GitHubToken
171+
}
172+
Update-GitHubRelease @params

0 commit comments

Comments
 (0)