Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azure-pipelines: Add steps to sign extensions with MSBuild #1775

Merged
merged 50 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bccd6da
Use MicroBuild template
alexweininger Aug 2, 2024
7596666
Add teamname
alexweininger Aug 2, 2024
2de1b58
undo
alexweininger Aug 2, 2024
34f87e7
Add TeamName variable
alexweininger Aug 2, 2024
c597cb2
remove team name
alexweininger Aug 2, 2024
8a4c1dd
Add sign step
alexweininger Aug 6, 2024
9df3746
Add install signing plugin task
alexweininger Aug 6, 2024
5e2b357
enable mb signing toolset
alexweininger Aug 6, 2024
e40af3e
Remove other sign step
alexweininger Aug 6, 2024
81b5767
edit
alexweininger Aug 6, 2024
2e0ab5d
use copy instead of cp
alexweininger Aug 6, 2024
19a0d40
slash
alexweininger Aug 6, 2024
795f24c
Use repo name for vsix
alexweininger Aug 22, 2024
3dc2d69
Fixup
alexweininger Aug 22, 2024
d23efaa
Get version from package.json
alexweininger Aug 22, 2024
03c7f2a
fixup
alexweininger Aug 22, 2024
bf14fad
Fixup
alexweininger Aug 22, 2024
8443c9f
Fixup
alexweininger Aug 22, 2024
13174de
Fixup
alexweininger Aug 22, 2024
86d5d90
Upload package.json as build artifact
alexweininger Aug 22, 2024
b9d8879
Fixup
alexweininger Aug 22, 2024
77b8c45
Upload package.json
alexweininger Aug 22, 2024
8c98d05
Fixup
alexweininger Aug 22, 2024
94fca88
Make it even stronger
alexweininger Aug 22, 2024
0659bed
Fixes
alexweininger Aug 22, 2024
2b67715
work
alexweininger Aug 23, 2024
5c2d846
Sign with MSBuild
alexweininger Aug 23, 2024
0458a7d
Organize yaml
alexweininger Aug 23, 2024
3456fe2
Fixup
alexweininger Aug 23, 2024
86d0804
use bash
alexweininger Aug 23, 2024
50c3294
Use powershell
alexweininger Aug 23, 2024
ba28c81
Fixup
alexweininger Aug 23, 2024
3474d7c
Fixup
alexweininger Aug 23, 2024
7bc1a93
Fixup
alexweininger Aug 23, 2024
ef0032c
Fixup
alexweininger Aug 23, 2024
91d8744
Fixup
alexweininger Aug 23, 2024
35a2364
Fixup
alexweininger Aug 23, 2024
f4d1e55
Fixup
alexweininger Aug 23, 2024
badb159
Fixup
alexweininger Aug 23, 2024
9de63e9
Remove
alexweininger Aug 23, 2024
217c108
Remove comments
alexweininger Aug 23, 2024
f32608d
Fixup
alexweininger Aug 23, 2024
2041d82
Fixup
alexweininger Aug 23, 2024
398bf24
Define variable
alexweininger Aug 23, 2024
f3276fb
Try this
alexweininger Aug 23, 2024
57215da
Undo
alexweininger Aug 23, 2024
205aa2e
Edit readme
alexweininger Aug 23, 2024
ce8c8b0
Merge remote-tracking branch 'origin' into alex/sign-with-msbuild
alexweininger Aug 23, 2024
68b29a4
Try moving csproj
alexweininger Aug 23, 2024
fa0a985
Update instructions
alexweininger Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions azure-pipelines/1esmain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ resources:
repositories:
- repository: 1esPipelines
type: git
name: 1ESPipelineTemplates/1ESPipelineTemplates
name: 1ESPipelineTemplates/MicroBuildTemplate
ref: refs/tags/release

extends:
template: v1/1ES.Official.PipelineTemplate.yml@1esPipelines
template: azure-pipelines/MicroBuild.1ES.Official.yml@1esPipelines
parameters:
sdl:
credscan:
Expand Down
7 changes: 7 additions & 0 deletions azure-pipelines/1esstages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ stages:
- ${{ each job in parameters.jobs }}:
- job: ${{ job.name }}
templateContext:
mb: # Enable the MicroBuild Signing toolset
signing:
enabled: true
signType: real # options are 'real' & 'test'
zipSources: false
outputs:
- output: pipelineArtifact
targetPath: $(build.artifactstagingdirectory)/build/${{ job.name }}
Expand All @@ -27,6 +32,8 @@ stages:
additionalSetupSteps: ${{ parameters.additionalSetupSteps }}
- template: ./templates/build.yml
- template: ./templates/1espackage.yml
- template: ./templates/sign.yml
- template: ./templates/stage-artifacts.yml
- template: ./templates/test.yml
parameters:
useAzureFederatedCredentials: ${{ parameters.useAzureFederatedCredentials }}
Expand Down
47 changes: 47 additions & 0 deletions azure-pipelines/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,56 @@ resources:
ref: main
endpoint: GitHub-AzureTools # The service connection to use when accessing this repository

parameters:
- name: enableLongRunningTests
displayName: Enable Long Running Tests
type: boolean
default: true

variables:
# Required by MicroBuild template
- name: TeamName
value: "Azure Tools for VS Code"

# Use those templates
extends:
template: azure-pipelines/1esmain.yml@azExtTemplates
parameters:
useAzureFederatedCredentials: ${{ parameters.enableLongRunningTests }}
```

6. To enable extension signing, add a `SignExtension.signproj` file in the `.azure-pipelines` folder with the following contents:

```xml
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" Sdk="Microsoft.Build.NoTargets/3.7.56">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<!-- FilesToSign needs to be inside $(OutDir) hence we copy it into
$(OutDir) before (from CWD) and move it back outside after the signing -->
<FilesToSign Include="$(OutDir)\extension.signature.p7s">
<!-- Add the certificate friendly name below -->
<Authenticode>VSCodePublisher</Authenticode>
</FilesToSign>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<Target Name="CopySignatureFile" BeforeTargets="SignFiles">
<Copy SourceFiles="$(ProjectDir)\..\extension.manifest" DestinationFiles="$(OutDir)\extension.signature.p7s" />
</Target>

<Target Name="CopyBackSignatureFile" AfterTargets="SignFiles">
<Copy SourceFiles="$(OutDir)\extension.signature.p7s" DestinationFiles="$(ProjectDir)\..\extension.signature.p7s" />
</Target>
</Project>
```

### (DEPRECATED) Primary pipelines
Expand Down
10 changes: 0 additions & 10 deletions azure-pipelines/templates/1espackage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,3 @@ steps:
customCommand: run package
workingDir: $(working_directory)
condition: succeeded()

- task: CopyFiles@2
displayName: "\U0001F449 Copy packages and vsix to staging directory"
inputs:
Contents: |
**/*.vsix
**/*.tar.gz
**/*.tgz
TargetFolder: "$(build.artifactstagingdirectory)/build/$(artifact_name)"
condition: and(succeeded(), ne(variables['System.PullRequest.IsFork'], 'True'))
32 changes: 32 additions & 0 deletions azure-pipelines/templates/sign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
steps:
# Check if the SignExtension.signproj file exists and set a variable using PowerShell
# All other steps in this template will only run if the file exists
- powershell: |
$fileExists = Test-Path -Path "$(Build.SourcesDirectory)/.azure-pipelines/SignExtension.signproj"
Write-Output "##vso[task.setvariable variable=signprojExists]$fileExists"

if ($fileExists) {
Write-Output "SignExtension.signproj file found. Signing extension."
} else {
Write-Output "SignExtension.signproj file not found. Skipping signing."
}
displayName: "\U0001F449 Check for SignExtension.signproj File"

# put the extension name and version from the package.json into variables to use later. Variables can be used in later steps as $(package.name) and $(package.version)
- pwsh: |
Write-Output "##vso[task.setvariable variable=name;isOutput=true]$((Get-Content -Raw -Path package.json | ConvertFrom-Json).name)"
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$((Get-Content -Raw -Path package.json | ConvertFrom-Json).version)"
condition: eq(variables['signprojExists'], True)
name: package
displayName: "\U0001F449 Get extension info from package.json"

- script: npx @vscode/vsce@latest generate-manifest -i $(package.name)-$(package.version).vsix -o $(Build.SourcesDirectory)/extension.manifest
condition: eq(variables['signprojExists'], True)
displayName: "\U0001F449 Generate extension manifest"

- task: DotNetCoreCLI@2
condition: eq(variables['signprojExists'], True)
displayName: "\U0001F449 Sign with MSBuild"
inputs:
command: 'build'
projects: $(Build.SourcesDirectory)/.azure-pipelines/SignExtension.signproj
17 changes: 17 additions & 0 deletions azure-pipelines/templates/stage-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
steps:
- task: CopyFiles@2
displayName: "\U0001F449 Copy packages and vsix to staging directory"
inputs:
# Uploading the package.json so we can publish later without cloning the source
bwateratmsft marked this conversation as resolved.
Show resolved Hide resolved
# Files related to signing:
# extension.manifest is the signature file
# extension.signature.p7s is the extension manifest generated by vsce
Contents: |
**/*.vsix
package.json
extension.manifest
extension.signature.p7s
**/*.tar.gz
**/*.tgz
TargetFolder: "$(build.artifactstagingdirectory)/build/$(artifact_name)"
condition: and(succeeded(), ne(variables['System.PullRequest.IsFork'], 'True'))
Loading