Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions azure-pipelines/1esstages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ stages:
parameters:
enableSigning: ${{ parameters.enableSigning }}
vsixFileNames: ${{ parameters.vsixFileNames }}
workingDirectory: ${{ job.working_directory }}

- template: ./templates/stage-artifacts.yml
- template: ./templates/test.yml
Expand Down
125 changes: 67 additions & 58 deletions azure-pipelines/templates/sign.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ parameters:
default: True
- name: vsixFileNames
type: object
default: ['']
default: [""]
- name: workingDirectory
type: string
default: "."

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"
$fileExists = Test-Path -Path "$(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/.azure-pipelines/SignExtension.signproj"
Write-Output "##vso[task.setvariable variable=signprojExists]$fileExists"

if ($fileExists) {
Expand All @@ -23,77 +26,83 @@ steps:

# 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)"
Write-Output "##vso[task.setvariable variable=name;isOutput=true]$((Get-Content -Raw -Path ${{ parameters.workingDirectory }}/package.json | ConvertFrom-Json).name)"
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$((Get-Content -Raw -Path ${{ parameters.workingDirectory }}/package.json | ConvertFrom-Json).version)"
condition: and(succeeded(), eq(variables['signprojExists'], True))
name: package
displayName: "\U0001F449 Get extension info from package.json"
workingDirectory: $(Build.SourcesDirectory)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little confusing why this step happens at the root, but subsequent ones at $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird because it seems like it worked fine but I would've assumed this would break it https://dev.azure.com/devdiv/DevDiv/_build/results?buildId=12924123&view=artifacts&pathAsName=false&type=publishedArtifacts


# Sign single vsix file if vsixFileNames are not provided
- ${{ if eq(join('', parameters.vsixFileNames), '') }}:
- script: npx @vscode/vsce@latest generate-manifest -i $(package.name)-$(package.version).vsix -o $(Build.SourcesDirectory)/extension.manifest
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Generate extension manifest"
- script: npx @vscode/vsce@latest generate-manifest -i $(package.name)-$(package.version).vsix -o $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/extension.manifest
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Generate extension manifest"
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}

# this task will pass even if signing fails, so we follow it up with a check to see if the signature file was created
- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Sign with MSBuild"
inputs:
command: 'build'
projects: $(Build.SourcesDirectory)/.azure-pipelines/SignExtension.signproj
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
# this task will pass even if signing fails, so we follow it up with a check to see if the signature file was created
- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Sign with MSBuild"
inputs:
command: "build"
projects: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/.azure-pipelines/SignExtension.signproj
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- pwsh: |
$filePath = "extension.signature.p7s"
- pwsh: |
$filePath = "extension.signature.p7s"

if (-Not (Test-Path $filePath)) {
Write-Error "The file '$filePath' does not exist."
exit 1
}
if (-Not (Test-Path $filePath)) {
Write-Error "The file '$filePath' does not exist."
exit 1
}

Write-Output "The file '$filePath' exists."
exit 0
displayName: "\U0001F449 Verify extension.signature.p7s file was created"
condition: and(succeeded(), eq(variables['signprojExists'], True))
Write-Output "The file '$filePath' exists."
exit 0
displayName: "\U0001F449 Verify extension.signature.p7s file was created"
condition: and(succeeded(), eq(variables['signprojExists'], True))
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}

# If vsixFileNames are provided, sign each file in list and move to corresponding directory
- ${{ if ne(join('', parameters.vsixFileNames), '') }}:
# run this script for each item in vsixFileNames
- ${{ each vsixFileName in parameters.vsixFileNames }}:
- script: npx @vscode/vsce@latest generate-manifest -i ${{ vsixFileName }}-$(package.version).vsix -o $(Build.SourcesDirectory)/extension.manifest
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Generate extension manifest for ${{ vsixFileName }}"
# run this script for each item in vsixFileNames
- ${{ each vsixFileName in parameters.vsixFileNames }}:
- script: npx @vscode/vsce@latest generate-manifest -i ${{ vsixFileName }}-$(package.version).vsix -o $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/extension.manifest
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Generate extension manifest for ${{ vsixFileName }}"
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}

# this task will pass even if signing fails, so we follow it up with a check to see if the signature file was created
- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Sign with MSBuild for ${{ vsixFileName }}"
inputs:
command: 'build'
projects: $(Build.SourcesDirectory)/.azure-pipelines/SignExtension.signproj
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
# this task will pass even if signing fails, so we follow it up with a check to see if the signature file was created
- task: DotNetCoreCLI@2
condition: and(succeeded(), eq(variables['signprojExists'], True))
displayName: "\U0001F449 Sign with MSBuild for ${{ vsixFileName }}"
inputs:
command: "build"
projects: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/.azure-pipelines/SignExtension.signproj
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)

- pwsh: |
$filePath = "extension.signature.p7s"
- pwsh: |
$filePath = "extension.signature.p7s"

if (-Not (Test-Path $filePath)) {
Write-Error "The file '$filePath' does not exist."
exit 1
}
if (-Not (Test-Path $filePath)) {
Write-Error "The file '$filePath' does not exist."
exit 1
}

Write-Output "The file '$filePath' exists."
exit 0
displayName: "\U0001F449 Verify extension.signature.p7s file was created for ${{ vsixFileName }}"
condition: and(succeeded(), eq(variables['signprojExists'], True))
Write-Output "The file '$filePath' exists."
exit 0
displayName: "\U0001F449 Verify extension.signature.p7s file was created for ${{ vsixFileName }}"
condition: and(succeeded(), eq(variables['signprojExists'], True))
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}

- pwsh: |
$targetDir = "${{ vsixFileName }}"
New-Item -ItemType Directory -Force -Path "$(Build.SourcesDirectory)/$targetDir"
Move-Item -Path "extension.signature.p7s" -Destination "$(Build.SourcesDirectory)/$targetDir/extension.signature.p7s" -Force
Move-Item -Path "extension.manifest" -Destination "$(Build.SourcesDirectory)/$targetDir/extension.manifest" -Force
Write-Output "Moved signature files to $targetDir directory"
displayName: "\U0001F449 Move signature files to ${{ vsixFileName }} directory"
condition: and(succeeded(), eq(variables['signprojExists'], True))
- pwsh: |
$targetDir = "${{ vsixFileName }}"
New-Item -ItemType Directory -Force -Path "$(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/$targetDir"
Move-Item -Path "extension.signature.p7s" -Destination "$(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/$targetDir/extension.signature.p7s" -Force
Move-Item -Path "extension.manifest" -Destination "$(Build.SourcesDirectory)/${{ parameters.workingDirectory }}/$targetDir/extension.manifest" -Force
Write-Output "Moved signature files to $targetDir directory"
displayName: "\U0001F449 Move signature files to ${{ vsixFileName }} directory"
condition: and(succeeded(), eq(variables['signprojExists'], True))
workingDirectory: $(Build.SourcesDirectory)/${{ parameters.workingDirectory }}