11name : Release
22
3- # Publishes a new version when a tag vX.Y.Z is pushed:
4- # 1. checks that the tag matches the version in the manifest, AssemblyInfo and package registration;
5- # 2. builds and tests;
6- # 3. publishes the VSIX to the Visual Studio Marketplace;
7- # 4. creates the GitHub release with the VSIX and the CHANGELOG section as notes.
8- # Run it manually (workflow_dispatch) for a dry run: steps 1-2 only, VSIX uploaded as an artifact.
9- #
10- # Secrets:
11- # VS_MARKETPLACE_PAT Azure DevOps personal access token, scope "Marketplace (Manage)", owned by an account
12- # that is a member of the "Ryadel" Marketplace publisher. Required to publish.
13- # SNK_BASE64 Optional: the strong-name key (Key.snk) encoded in base64. Without it the build
14- # generates a new key on every run.
3+ # Push a tag vX.Y.Z to release: the workflow checks the versions, builds, tests, publishes the VSIX to the
4+ # Visual Studio Marketplace and creates the GitHub release. Run it manually for a dry run (no publishing).
155
166on :
177 push :
188 tags : ['v*.*.*']
199 workflow_dispatch :
2010
2111permissions :
22- contents : write
12+ contents : read
2313
2414concurrency :
2515 group : release
2616 cancel-in-progress : false
2717
2818jobs :
29- release :
30- name : Build and publish
19+ build :
20+ name : Build and test
3121 runs-on : windows-latest
32- # Protect the environment in Settings > Environments to require an approval before publishing.
33- environment : marketplace
22+ outputs :
23+ version : ${{ steps.version.outputs.version }}
3424 env :
3525 SNK_BASE64 : ${{ secrets.SNK_BASE64 }}
36- PUBLISH : ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
3726 steps :
3827 - uses : actions/checkout@v7
3928
5039 Write-Host "Manifest: $version AssemblyVersion: $assembly InstalledProductRegistration: $registration"
5140 if ($assembly -ne "$version.0") { throw "AssemblyVersion $assembly does not match manifest version $version" }
5241 if ($registration -ne $version) { throw "InstalledProductRegistration $registration does not match manifest version $version" }
53- if ($env:PUBLISH -eq 'true ' -and $env:GITHUB_REF_NAME -ne "v$version") { throw "Tag $env:GITHUB_REF_NAME does not match manifest version v$version" }
42+ if ($env:GITHUB_REF_TYPE -eq 'tag ' -and $env:GITHUB_REF_NAME -ne "v$version") { throw "Tag $env:GITHUB_REF_NAME does not match manifest version v$version" }
5443 if (-not (Select-String -Path 'CHANGELOG.txt' -SimpleMatch "SourceControlSwitcher - v$version" -Quiet)) { throw "CHANGELOG.txt has no section for v$version" }
5544 "version=$version" >> $env:GITHUB_OUTPUT
5645
@@ -75,42 +64,63 @@ jobs:
7564 $lines[($start + 2)..($end - 1)] | Set-Content -Encoding utf8 'release-notes.md'
7665 Get-Content 'release-notes.md'
7766
78- - name : Upload VSIX
67+ - name : Upload VSIX and release notes
7968 uses : actions/upload-artifact@v7
8069 with :
81- name : SourceControlSwitcher-${{ steps.version.outputs.version }}-vsix
82- path : target/Release/SourceControlSwitcher.vsix
70+ name : release
71+ path : |
72+ target/Release/SourceControlSwitcher.vsix
73+ release-notes.md
8374 if-no-files-found : error
8475
76+ publish :
77+ name : Publish
78+ needs : build
79+ if : github.ref_type == 'tag'
80+ runs-on : windows-latest
81+ environment : marketplace
82+ permissions :
83+ contents : write
84+ steps :
85+ - uses : actions/checkout@v7
86+
87+ - uses : microsoft/setup-msbuild@v3
88+
89+ - name : Download VSIX and release notes
90+ uses : actions/download-artifact@v7
91+ with :
92+ name : release
93+ path : release
94+
8595 - name : Publish to the Visual Studio Marketplace
86- if : env.PUBLISH == 'true'
8796 shell : pwsh
8897 env :
8998 VS_MARKETPLACE_PAT : ${{ secrets.VS_MARKETPLACE_PAT }}
9099 run : |
91100 if (-not $env:VS_MARKETPLACE_PAT) { throw 'Secret VS_MARKETPLACE_PAT is not set' }
92- # VsixPublisher ships with the Microsoft.VSSDK.BuildTools package restored by the build.
101+ # VsixPublisher ships with the Microsoft.VSSDK.BuildTools package: restore it.
102+ msbuild SourceControlSwitcher/SourceControlSwitcher.csproj -t:Restore -v:minimal
93103 $publisher = Get-ChildItem "$env:USERPROFILE\.nuget\packages\microsoft.vssdk.buildtools" -Recurse -Filter VsixPublisher.exe |
94104 Where-Object { $_.Directory.Name -eq 'bin' } | Sort-Object FullName -Descending | Select-Object -First 1
95105 if (-not $publisher) { throw 'VsixPublisher.exe not found' }
96106 & $publisher.FullName publish `
97- -payload 'target/Release/SourceControlSwitcher.vsix' `
107+ -payload 'release/ target/Release/SourceControlSwitcher.vsix' `
98108 -publishManifest 'SourceControlSwitcher/Manifest/publishManifest.json' `
99109 -personalAccessToken $env:VS_MARKETPLACE_PAT
100110 if ($LASTEXITCODE -ne 0) { throw "VsixPublisher failed with exit code $LASTEXITCODE" }
101111
102112 - name : Create GitHub release
103- if : env.PUBLISH == 'true'
104113 shell : pwsh
105114 env :
106115 GH_TOKEN : ${{ github.token }}
107116 run : |
108117 $tag = $env:GITHUB_REF_NAME
118+ $vsix = 'release/target/Release/SourceControlSwitcher.vsix'
109119 gh release view $tag *> $null
110120 if ($LASTEXITCODE -eq 0) {
111- gh release upload $tag 'target/Release/SourceControlSwitcher. vsix' --clobber
121+ gh release upload $tag $ vsix --clobber
112122 } else {
113- gh release create $tag 'target/Release/SourceControlSwitcher. vsix' --verify-tag `
114- --title "Source Control Switcher ${{ steps.version .outputs.version }}" --notes-file 'release-notes.md'
123+ gh release create $tag $ vsix --verify-tag `
124+ --title "Source Control Switcher ${{ needs.build .outputs.version }}" --notes-file 'release/ release-notes.md'
115125 }
116126 if ($LASTEXITCODE -ne 0) { throw "gh release failed with exit code $LASTEXITCODE" }
0 commit comments