Skip to content

Commit

Permalink
Setup Invoke-Build and OneBranch pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
andyleejordan committed Sep 23, 2024
1 parent 11a148e commit 892740b
Show file tree
Hide file tree
Showing 3 changed files with 261 additions and 6 deletions.
173 changes: 173 additions & 0 deletions .pipelines/SecretStore-Official.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
#################################################################################
# OneBranch Pipelines #
# This pipeline was created by EasyStart from a sample located at: #
# https://aka.ms/obpipelines/easystart/samples #
# Documentation: https://aka.ms/obpipelines #
# Yaml Schema: https://aka.ms/obpipelines/yaml/schema #
# Retail Tasks: https://aka.ms/obpipelines/tasks #
# Support: https://aka.ms/onebranchsup #
#################################################################################

trigger:
- main

schedules:
- cron: '23 16 * * 4'
displayName: Weekly CodeQL
branches:
include:
- main
always: true

parameters:
- name: debug
displayName: Enable debug output
type: boolean
default: false

variables:
system.debug: ${{ parameters.debug }}
BuildConfiguration: Release
WindowsContainerImage: onebranch.azurecr.io/windows/ltsc2022/vse2022:latest
DOTNET_NOLOGO: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false

resources:
repositories:
- repository: templates
type: git
name: OneBranch.Pipelines/GovernedTemplates
ref: refs/heads/main

extends:
# https://aka.ms/obpipelines/templates
template: v2/OneBranch.Official.CrossPlat.yml@templates
parameters:
globalSdl: # https://aka.ms/obpipelines/sdl
asyncSdl:
enabled: true
forStages: [build]
featureFlags:
EnableCDPxPAT: false
WindowsHostVersion:
Version: 2022
Network: Netlock
stages:
- stage: build
jobs:
- job: main
displayName: Build package
pool:
type: windows
variables:
ob_outputDirectory: $(Build.SourcesDirectory)/out
steps:
- pwsh: |
[xml]$xml = Get-Content Directory.Build.props
$version = $xml.Project.PropertyGroup.ModuleVersion
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$version"
name: package
displayName: Get version from project properties
- task: onebranch.pipeline.version@1
displayName: Set OneBranch version
inputs:
system: Custom
customVersion: $(package.version)
- task: UseDotNet@2
displayName: Use .NET SDK
inputs:
packageType: sdk
useGlobalJson: true
- pwsh: |
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet
./tools/installPSResources.ps1 -PSRepository CFS
displayName: Install PSResources
- pwsh: Invoke-Build -Configuration $(BuildConfiguration) -Task Build, Test
displayName: Build
- task: onebranch.pipeline.signing@1
displayName: Sign 1st-party files in module
inputs:
command: sign
signing_profile: external_distribution
search_root: $(Build.SourcesDirectory)/module
files_to_sign: |
Microsoft.*.dll;
**/Microsoft.*.psd1;
**/Microsoft.*.psm1;
- task: ArchiveFiles@2
displayName: Zip module
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/module
includeRootFolder: false
archiveType: zip
archiveFile: out/SecretStore-v$(package.version).zip
- pwsh: Invoke-Build -Configuration $(BuildConfiguration) Package
displayName: Package module
- task: onebranch.pipeline.signing@1
displayName: Sign NuGet package
inputs:
command: sign
signing_profile: external_distribution
search_root: $(Build.SourcesDirectory)/out
files_to_sign: |
*.nupkg
- stage: release
dependsOn: build
condition: eq(variables['Build.Reason'], 'Manual')
variables:
version: $[ stageDependencies.build.main.outputs['package.version'] ]
drop: $(Pipeline.Workspace)/drop_build_main
jobs:
- job: github
displayName: Publish draft to GitHub
pool:
type: windows
variables:
ob_outputDirectory: $(Build.SourcesDirectory)/out
steps:
- download: current
displayName: Download artifacts
- task: GitHubRelease@1
displayName: Create GitHub release
inputs:
gitHubConnection: GitHub
repositoryName: PowerShell/SecretStore
assets: |
$(drop)/Microsoft.PowerShell.SecretStore.$(version).nupkg
$(drop)/SecretStore-v$(version).zip
tagSource: userSpecifiedTag
tag: v$(version)
isDraft: true
addChangeLog: false
releaseNotesSource: inline
releaseNotesInline: "<!-- TODO: Generate release notes on GitHub! -->"
- job: validation
displayName: Manual validation
pool:
type: agentless
timeoutInMinutes: 1440
steps:
- task: ManualValidation@0
displayName: Wait 24 hours for validation
inputs:
notifyUsers: $(Build.RequestedForEmail)
instructions: Please validate the release and then publish it!
timeoutInMinutes: 1440
- job: publish
dependsOn: validation
displayName: Publish to PowerShell Gallery
pool:
type: windows
variables:
ob_outputDirectory: $(Build.SourcesDirectory)/out
steps:
- download: current
displayName: Download artifacts
- task: NuGetCommand@2
displayName: Publish module to PowerShell Gallery
inputs:
command: push
packagesToPush: $(drop)/Microsoft.PowerShell.SecretStore.$(version).nupkg
nuGetFeedType: external
publishFeedCredentials: PowerShellGallery
81 changes: 81 additions & 0 deletions SecretStore.build.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
[CmdletBinding()]
param(
[ValidateSet("Debug", "Release")]
[string]$Configuration = "Debug"
)

#Requires -Modules @{ ModuleName = "InvokeBuild"; ModuleVersion = "5.0.0" }

task FindDotNet -Before Clean, Build {
Assert (Get-Command dotnet -ErrorAction SilentlyContinue) "The dotnet CLI was not found, please install it: https://aka.ms/dotnet-cli"
$DotnetVersion = dotnet --version
Assert ($?) "The required .NET SDK was not found, please install it: https://aka.ms/dotnet-cli"
Write-Host "Using dotnet $DotnetVersion at path $((Get-Command dotnet).Source)" -ForegroundColor Green
}

task Clean {
Remove-BuildItem ./artifacts, ./module, ./out
Invoke-BuildExec { dotnet clean ./src/code }
}

task BuildDocs -If { Test-Path -LiteralPath ./help } {
New-ExternalHelp -Path ./help -OutputPath ./module/en-US
}

task BuildModule {
New-Item -ItemType Directory -Force ./module | Out-Null

Invoke-BuildExec { dotnet publish ./src/code -c $Configuration }

$FullModuleName = "Microsoft.PowerShell.SecretStore"

$CSharpArtifacts = @(
"$FullModuleName.dll",
"$FullModuleName.pdb",
"System.IO.FileSystem.AccessControl.dll",
"System.Runtime.InteropServices.RuntimeInformation.dll")

$CSharpArtifacts | ForEach-Object {
$item = "./artifacts/publish/$FullModuleName/$($Configuration.ToLower())/$_"
Copy-Item -Force -LiteralPath $item -Destination ./module
}

$BaseArtifacts = @(
"README.md",
"LICENSE",
"ThirdPartyNotices.txt")

$BaseArtifacts | ForEach-Object {
$itemToCopy = Join-Path $PSScriptRoot $_
Copy-Item -Force -LiteralPath $itemToCopy -Destination ./module
}

Copy-Item -Force -Recurse "./src/$FullModuleName.Extension/" -Destination ./module

[xml]$xml = Get-Content Directory.Build.props
$moduleVersion = $xml.Project.PropertyGroup.ModuleVersion
$manifestContent = Get-Content -LiteralPath "./src/$FullModuleName.psd1" -Raw
$newManifestContent = $manifestContent -replace '{{ModuleVersion}}', $moduleVersion
Set-Content -LiteralPath "./module/$FullModuleName.psd1" -Encoding utf8 -Value $newManifestContent
}

task Package {
New-Item -ItemType Directory -Force ./out | Out-Null

try {
Register-PSResourceRepository -Name SecretStore -Uri ./out -ErrorAction Stop
Publish-PSResource -Path ./module -Repository SecretStore -SkipDependenciesCheck -Verbose
} finally {
Unregister-PSResourceRepository -Name SecretStore
}
}

task Test {
Invoke-Pester -CI -Output Diagnostic
}

task Build BuildModule, BuildDocs

task . Clean, Build
13 changes: 7 additions & 6 deletions src/code/Microsoft.PowerShell.SecretStore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Deterministic>true</Deterministic>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.PowerShell.SecretStore</RootNamespace>
<AssemblyName>Microsoft.PowerShell.SecretStore</AssemblyName>
<AssemblyVersion>1.0.6.0</AssemblyVersion>
<FileVersion>1.0.6</FileVersion>
<InformationalVersion>1.0.6</InformationalVersion>
<TargetFramework>net461</TargetFramework>
<AssemblyVersion>$(ModuleVersion).0</AssemblyVersion>
<FileVersion>$(ModuleVersion)</FileVersion>
<InformationalVersion>$(ModuleVersion)</InformationalVersion>
<TargetFramework>net462</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.PowerShell.SecretManagement.Library" Version="0.9.1-*" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" />
<PackageReference Include="Microsoft.CSharp" version="4.5.0" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1" PrivateAssets="All" />
<PackageReference Include="System.IO.FileSystem.AccessControl" version="4.7.0" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
</ItemGroup>

</Project>

0 comments on commit 892740b

Please sign in to comment.