Skip to content

Commit

Permalink
Merge pull request #272 from SteveL-MSFT/release-pipeline
Browse files Browse the repository at this point in the history
Release pipeline
  • Loading branch information
SteveL-MSFT authored Nov 14, 2023
2 parents 1e1c7c5 + 5e15967 commit 24d8dee
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 37 deletions.
274 changes: 274 additions & 0 deletions .vsts-ci/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
trigger: none

variables:
- name: BuildConfiguration
value: 'release'
- name: PackageRoot
value: '$(System.ArtifactsDirectory)/Packages'
- group: DSCAPIScan

resources:
repositories:
- repository: ComplianceRepo
type: github
endpoint: ComplianceGHRepo
name: PowerShell/compliance
ref: master

stages:
- stage: BuildAndSign
displayName: Build Native Binaries
dependsOn: []
jobs:
- job: SetPackageVersion
displayName: Set PackageVersion
steps:
- checkout: self
- pwsh: |
$packageVersion = ./build.ps1 -GetPackageVersion
$vstsCommandString = "vso[task.setvariable variable=Version;isoutput=true]$packageVersion"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
name: Package
- job: BuildWin
dependsOn: SetPackageVersion
variables:
- group: ESRP
- name: PackageVersion
value: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
pool:
name: PowerShell1ES
demands:
- ImageOverride -equals PSMMS2019-Rust-Secure
displayName: Build
strategy:
matrix:
Windows x64:
buildName: x86_64-pc-windows-msvc
Windows x64_arm64:
buildName: aarch64-pc-windows-msvc

steps:
- checkout: self
- pwsh: |
Set-Location "$(Build.SourcesDirectory)/DSC"
./build.ps1 -Release -Architecture $(buildName) -SkipLinkCheck
displayName: 'Build $(buildName)'
condition: succeeded()
- pwsh: |
$null = New-Item -ItemType Directory -Path "$(PackageRoot)" -ErrorAction Ignore
$null = New-Item -ItemType Directory -Path "$(PackageRoot)/out" -ErrorAction Ignore
$outPath = New-Item -ItemType Directory -Path "$(PackageRoot)/out/$(buildName)" -ErrorAction Ignore
Copy-Item -Path "$(Build.SourcesDirectory)/DSC/bin/$(buildName)/$(BuildConfiguration)/*" -Destination $outPath -Verbose -Force
displayName: Copy binaries
condition: succeeded()
- pwsh: |
Set-Location "$(PackageRoot)"
$signSrcPath = "$(PackageRoot)/out/$(buildName)"
# Set signing src path variable
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
Write-Host ("sending " + $vstsCommandString)
Write-Host "##$vstsCommandString"
- pwsh: |
$signOutPath = "$(PackageRoot)/signed"
$null = New-Item -ItemType Directory -Path $signOutPath
# Set signing out path variable
$vstsCommandString = "vso[task.setvariable variable=signOutPath;isoutput=true]${signOutPath}"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
name: signOutPath
- pwsh: |
# Set path variable for guardian codesign validation
$vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]$(signOutPath.signOutPath)"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
displayName: Setup variables for signing
- checkout: ComplianceRepo

- template: EsrpSign.yml@ComplianceRepo
parameters:
# the folder which contains the binaries to sign
buildOutputPath: $(Build.SourcesDirectory)/DSC/bin/$(buildName)/$(BuildConfiguration)
# the location to put the signed output
signOutputPath: $(signOutPath.signOutPath)
# the certificate ID to use
certificateId: "CP-230012"
# The file pattern to use
# If not using minimatch: comma separated, with * supported
# If using minimatch: newline separated, with !, **, and * supported.
# See link in the useMinimatch comments.
pattern: '*.exe','*.ps1'
# decides if the task should use minimatch for the pattern matching.
# https://github.com/isaacs/minimatch#features
useMinimatch: false

- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: $(signOutPath.signOutPath)
Build_Repository_Uri: 'https://github.com/powershell/DSC'
PackageName: 'DSC'
PackageVersion: $(PackageVersion)

- pwsh: |
compress-archive -Path "$(signOutPath.signOutPath)/*" -DestinationPath "$(PackageRoot)/DSC-$(PackageVersion)-$(buildName).zip"
displayName: 'Compress $(buildName)'
condition: succeeded()
- pwsh: |
Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(PackageRoot)\DSC-$(PackageVersion)-$(buildName).zip"
displayName: Upload artifacts
condition: succeeded()
- job: PublishSigned
dependsOn: BuildWin
variables:
- name: signOutPath
value: $[ dependencies.BuildWin.outputs['signOutPath.signOutPath'] ]
steps:
- task: PublishPipelineArtifact@1
inputs:
targetpath: $(signOutPath)
artifactName: signed

- job: BuildLinux
dependsOn: SetPackageVersion
variables:
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
displayName: Linux-x64-gnu
pool:
name: PowerShell1ES
demands:
- ImageOverride -equals PSMMSUbuntu20.04-Secure
steps:
- pwsh: |
./build.ps1 -Release -Architecture x86_64-unknown-linux-gnu
displayName: 'Build x86_64-unknown-linux-gnu'
condition: succeeded()
- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: $(Build.SourcesDirectory)/bin/x86_64-unknown-linux-gnu/$(BuildConfiguration)
Build_Repository_Uri: 'https://github.com/powershell/DSC'
PackageName: 'DSC'
PackageVersion: $(PackageVersion)
- pwsh: |
new-item -itemType Directory $(PackageRoot) -Force
tar czf '$(PackageRoot)/DSC-$(PackageVersion)-x86_64-unknown-linux-gnu.tar.gz' -C $(Build.SourcesDirectory)/bin/x86_64-unknown-linux-gnu/$(BuildConfiguration) .
displayName: 'Compress x86_64-unknown-linux-gnu'
condition: succeeded()
- pwsh: |
Write-Host '##vso[artifact.upload containerfolder=release;artifactname=release]$(PackageRoot)/DSC-$(PackageVersion)-x86_64-unknown-linux-gnu.tar.gz'
displayName: Upload artifacts
condition: succeeded()
- job: BuildLinuxArm64
dependsOn: SetPackageVersion
variables:
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
displayName: Linux-ARM64-gnu
pool:
name: ps-powershell-rel-arm
demands:
- ImageOverride -equals PSMMSUbuntu20.04-ARM64-secure
steps:
- pwsh: |
./build.ps1 -Release -Architecture aarch64-unknown-linux-gnu
displayName: 'Build aarch64-unknown-linux-gnu'
condition: succeeded()
- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: $(Build.SourcesDirectory)/bin/aarch64-unknown-linux-gnu/$(BuildConfiguration)
Build_Repository_Uri: 'https://github.com/powershell/DSC'
PackageName: 'DSC'
PackageVersion: $(PackageVersion)
- pwsh: |
new-item -itemType Directory $(PackageRoot) -Force
tar czf '$(PackageRoot)/DSC-$(PackageVersion)-aarch64-unknown-linux-gnu.tar.gz' -C $(Build.SourcesDirectory)/bin/aarch64-unknown-linux-gnu/$(BuildConfiguration) .
displayName: 'Compress aarch64-unknown-linux-gnu'
condition: succeeded()
- pwsh: |
Write-Host '##vso[artifact.upload containerfolder=release;artifactname=release]$(PackageRoot)/DSC-$(PackageVersion)-aarch64-unknown-linux-gnu.tar.gz'
displayName: Upload artifacts
condition: succeeded()
- job: BuildMac
dependsOn: SetPackageVersion
variables:
PackageVersion: $[ dependencies.SetPackageVersion.outputs['Package.Version'] ]
displayName: Build
pool:
vmImage: macOS-Latest
strategy:
matrix:
macOS x64:
buildName: x86_64-apple-darwin
macOS arm64:
buildName: aarch64-apple-darwin
steps:
- pwsh: |
./build.ps1 -Release -Architecture $(buildName)
displayName: 'Build $(buildName)'
condition: succeeded()
- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: $(Build.SourcesDirectory)/bin/$(buildName)/$(BuildConfiguration)
Build_Repository_Uri: 'https://github.com/powershell/DSC'
PackageName: 'DSC'
PackageVersion: $(PackageVersion)
- pwsh: |
new-item -itemType Directory $(PackageRoot) -Force
tar czf '$(PackageRoot)/DSC-$(PackageVersion)-$(buildName).tar.gz' -C $(Build.SourcesDirectory)/bin/$(buildName)/$(BuildConfiguration) .
displayName: 'Compress $(buildName)'
condition: succeeded()
- pwsh: |
Write-Host "##vso[artifact.upload containerfolder=release;artifactname=release]$(PackageRoot)/DSC-$(PackageVersion)-$(buildName).tar.gz"
displayName: Upload artifacts
condition: succeeded()
- stage: compliance
displayName: Compliance
dependsOn: BuildAndSign
jobs:
- job: Compliance_Job
variables:
PackageVersion: $[ stageDependencies.BuildAndSign.SetPackageVersion.outputs['Package.Version'] ]
pool:
name: PowerShell1ES
demands:
- ImageOverride -equals PSMMS2019-Rust-Secure
steps:
- checkout: self
clean: true
- checkout: ComplianceRepo
clean: true

- download: current
artifact: release

- download: current
artifact: signed

- pwsh: |
Get-ChildItem -Path 'ENV:'
displayName: Capture environment
- template: assembly-module-compliance.yml@ComplianceRepo
parameters:
# binskim
AnalyzeTarget: '$(Build.SourcesDirectory)/DSC/bin/x86_64-pc-windows-msvc/release/*.exe' #'$(Pipeline.Workspace)/uncompressed/*.exe'
AnalyzeSymPath: 'SRV*'
# component-governance
sourceScanPath: '$(Build.SourcesDirectory)/DSC'
# credscan
suppressionsFile: ''
# TermCheck
optionsRulesDBPath: ''
optionsFTPath: ''
# tsa-upload
codeBaseName: 'DSC'
# selections
softwareName: 'DSC'
softwareNameFolder: '$(Build.SourcesDirectory)/DSC/bin/x86_64-pc-windows-msvc/release' #'$(Pipeline.Workspace)/uncompressed'
softwareVersion: '$(PackageVersion)'
connectionString: RunAs=App;AppId=$(APIScanClient);TenantId=$(APIScanTenant);AppKey=$(APIScanSecret)
APIScan: true # set to false when not using Windows APIs.
17 changes: 15 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ param(
[ValidateSet('current','aarch64-pc-windows-msvc','x86_64-pc-windows-msvc','aarch64-apple-darwin','x86_64-apple-darwin','aarch64-unknown-linux-gnu','aarch64-unknown-linux-musl','x86_64-unknown-linux-gnu','x86_64-unknown-linux-musl')]
$architecture = 'current',
[switch]$Clippy,
[switch]$Test
[switch]$Test,
[switch]$GetPackageVersion,
[switch]$SkipLinkCheck
)

if ($GetPackageVersion) {
$match = Select-String -Path $PSScriptRoot/dsc/Cargo.toml -Pattern '^version\s*=\s*"(?<ver>.*?)"$'
if ($null -eq $match) {
throw 'Unable to find version in Cargo.toml'
}

return $match.Matches.Groups[1].Value
}

## Test if Rust is installed
if (!(Get-Command 'cargo' -ErrorAction Ignore)) {
Write-Verbose -Verbose "Rust not found, installing..."
Expand All @@ -23,6 +34,7 @@ if (!(Get-Command 'cargo' -ErrorAction Ignore)) {
}
}

rustup default stable
$BuildToolsPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC"

function Find-LinkExe {
Expand All @@ -40,7 +52,7 @@ function Find-LinkExe {
}
}

if ($IsWindows -and !(Get-Command 'link.exe' -ErrorAction Ignore)) {
if (!$SkipLinkCheck -and $IsWindows -and !(Get-Command 'link.exe' -ErrorAction Ignore)) {
if (!(Test-Path $BuildToolsPath)) {
Write-Verbose -Verbose "link.exe not found, installing C++ build tools"
Invoke-WebRequest 'https://aka.ms/vs/17/release/vs_BuildTools.exe' -OutFile 'temp:/vs_buildtools.exe'
Expand Down Expand Up @@ -79,6 +91,7 @@ if ($architecture -eq 'current') {
$target = Join-Path $PSScriptRoot 'bin' $configuration
}
else {
rustup target add $architecture
$flags += '--target'
$flags += $architecture
$path = ".\target\$architecture\$configuration"
Expand Down
17 changes: 4 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tree-sitter-dscexpression/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ($null -eq (Get-Command npm -ErrorAction Ignore)) {

npm list tree-sitter-cli
if ($LASTEXITCODE -ne 0) {
npm install tree-sitter-cli
npm ci tree-sitter-cli --no-optional
}

Invoke-NativeCommand 'npx tree-sitter generate'
Expand Down
27 changes: 6 additions & 21 deletions tree-sitter-dscexpression/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24d8dee

Please sign in to comment.