Skip to content

Commit 9cdb7c7

Browse files
committed
Setup OneBranch and package build
1 parent 522c8f6 commit 9cdb7c7

File tree

3 files changed

+193
-8
lines changed

3 files changed

+193
-8
lines changed

.github/workflows/ci-test.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jobs:
3434
run: ./build.ps1 -Configuration Release -All
3535
shell: pwsh
3636

37+
- name: Package
38+
run: ./build.ps1 -BuildNupkg
39+
shell: pwsh
40+
3741
- name: Test
3842
run: ./build.ps1 -Test
3943
shell: pwsh
@@ -45,6 +49,13 @@ jobs:
4549
if: matrix.os == 'windows-latest'
4650
shell: powershell
4751

52+
- name: Upload build artifacts
53+
uses: actions/upload-artifact@v4
54+
if: always()
55+
with:
56+
name: PSScriptAnalyzer-package-${{ matrix.os }}
57+
path: out/**/*.nupkg
58+
4859
- name: Upload test results
4960
uses: actions/upload-artifact@v4
5061
if: always()
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#################################################################################
2+
# OneBranch Pipelines #
3+
# This pipeline was created by EasyStart from a sample located at: #
4+
# https://aka.ms/obpipelines/easystart/samples #
5+
# Documentation: https://aka.ms/obpipelines #
6+
# Yaml Schema: https://aka.ms/obpipelines/yaml/schema #
7+
# Retail Tasks: https://aka.ms/obpipelines/tasks #
8+
# Support: https://aka.ms/onebranchsup #
9+
#################################################################################
10+
11+
trigger: none
12+
13+
schedules:
14+
- cron: '20 16 * * 4'
15+
displayName: Weekly CodeQL
16+
branches:
17+
include:
18+
- main
19+
always: true
20+
21+
parameters:
22+
- name: debug
23+
displayName: Enable debug output
24+
type: boolean
25+
default: false
26+
27+
variables:
28+
system.debug: ${{ parameters.debug }}
29+
BuildConfiguration: Release
30+
WindowsContainerImage: onebranch.azurecr.io/windows/ltsc2022/vse2022:latest
31+
DOTNET_NOLOGO: true
32+
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
33+
34+
resources:
35+
repositories:
36+
- repository: templates
37+
type: git
38+
name: OneBranch.Pipelines/GovernedTemplates
39+
ref: refs/heads/main
40+
41+
extends:
42+
# https://aka.ms/obpipelines/templates
43+
template: v2/OneBranch.Official.CrossPlat.yml@templates
44+
parameters:
45+
globalSdl: # https://aka.ms/obpipelines/sdl
46+
asyncSdl:
47+
enabled: true
48+
forStages: [build]
49+
featureFlags:
50+
EnableCDPxPAT: false
51+
WindowsHostVersion:
52+
Version: 2022
53+
Network: Netlock
54+
stages:
55+
- stage: build
56+
jobs:
57+
- job: main
58+
displayName: Build package
59+
pool:
60+
type: windows
61+
variables:
62+
ob_outputDirectory: $(Build.SourcesDirectory)/out
63+
steps:
64+
- pwsh: |
65+
[xml]$xml = Get-Content Engine/Engine.csproj
66+
$version = $xml.SelectSingleNode(".//VersionPrefix")."#text"
67+
Write-Output "##vso[task.setvariable variable=version;isOutput=true]$version"
68+
name: package
69+
displayName: Get version from project properties
70+
- task: onebranch.pipeline.version@1
71+
displayName: Set OneBranch version
72+
inputs:
73+
system: Custom
74+
customVersion: $(package.version)
75+
- task: UseDotNet@2
76+
displayName: Use .NET SDK
77+
inputs:
78+
packageType: sdk
79+
useGlobalJson: true
80+
- pwsh: |
81+
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted
82+
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet
83+
./tools/installPSResources.ps1 -PSRepository CFS
84+
displayName: Install PSResources
85+
- pwsh: ./build.ps1 -Configuration Release -All
86+
displayName: Build
87+
- task: onebranch.pipeline.signing@1
88+
displayName: Sign 1st-party files
89+
inputs:
90+
command: sign
91+
signing_profile: external_distribution
92+
search_root: $(Build.SourcesDirectory)/out
93+
files_to_sign: |
94+
**/Microsoft.*.dll;
95+
**/*.psd1;
96+
**/*.psm1;
97+
**/*.ps1xml;
98+
- task: onebranch.pipeline.signing@1
99+
displayName: Sign 3rd-party files
100+
inputs:
101+
command: sign
102+
signing_profile: 135020002
103+
search_root: $(Build.SourcesDirectory)/out
104+
files_to_sign: |
105+
**/Newtonsoft.Json.dll;
106+
**/Pluralize.NET.dll;
107+
- pwsh: ./build.ps1 -BuildNupkg
108+
displayName: Package module
109+
- task: onebranch.pipeline.signing@1
110+
displayName: Sign NuGet package
111+
inputs:
112+
command: sign
113+
signing_profile: external_distribution
114+
search_root: $(Build.SourcesDirectory)/out
115+
files_to_sign: |
116+
*.nupkg
117+
- stage: release
118+
dependsOn: build
119+
condition: ne(variables['Build.Reason'], 'Schedule')
120+
variables:
121+
version: $[ stageDependencies.build.main.outputs['package.version'] ]
122+
drop: $(Pipeline.Workspace)/drop_build_main
123+
jobs:
124+
- job: github
125+
displayName: Publish draft to GitHub
126+
pool:
127+
type: windows
128+
variables:
129+
ob_outputDirectory: $(Build.SourcesDirectory)/out
130+
steps:
131+
- download: current
132+
displayName: Download artifacts
133+
- task: GitHubRelease@1
134+
displayName: Create GitHub release
135+
inputs:
136+
gitHubConnection: GitHub
137+
repositoryName: PowerShell/PSScriptAnalyzer
138+
assets: |
139+
$(drop)/PSScriptAnalyzer.$(version).nupkg
140+
tagSource: userSpecifiedTag
141+
tag: v$(version)
142+
isDraft: true
143+
addChangeLog: false
144+
releaseNotesSource: inline
145+
releaseNotesInline: "<!-- TODO: Generate release notes on GitHub! -->"
146+
- job: validation
147+
displayName: Manual validation
148+
pool:
149+
type: agentless
150+
timeoutInMinutes: 1440
151+
steps:
152+
- task: ManualValidation@0
153+
displayName: Wait 24 hours for validation
154+
inputs:
155+
notifyUsers: $(Build.RequestedForEmail)
156+
instructions: Please validate the release and then publish it!
157+
timeoutInMinutes: 1440
158+
- job: publish
159+
dependsOn: validation
160+
displayName: Publish to PowerShell Gallery
161+
pool:
162+
type: windows
163+
variables:
164+
ob_outputDirectory: $(Build.SourcesDirectory)/out
165+
steps:
166+
- download: current
167+
displayName: Download artifacts
168+
- task: NuGetCommand@2
169+
displayName: Publish module to PowerShell Gallery
170+
inputs:
171+
command: push
172+
packagesToPush: $(drop)/PSScriptAnalyzer.$(version).nupkg
173+
nuGetFeedType: external
174+
publishFeedCredentials: PowerShellGallery

tools/installPSResources.ps1

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Copyright (c) Microsoft Corporation.
22
# Licensed under the MIT License.
3+
param(
4+
[ValidateSet("PSGallery", "CFS")]
5+
[string]$PSRepository = "PSGallery"
6+
)
37

4-
$ErrorActionPreference = 'Stop'
5-
6-
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted | Out-Null
7-
if ($PSVersionTable.PSVersion.Major -lt 6) {
8-
throw "The build script requires PowerShell 7!"
8+
if ($PSRepository -eq "CFS" -and -not (Get-PSResourceRepository -Name CFS -ErrorAction SilentlyContinue)) {
9+
Register-PSResourceRepository -Name CFS -Uri "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v3/index.json"
910
}
1011

11-
# TODO: Switch to Install-PSResource when CI uses PowerShell 7.4
12-
Install-Module -Name platyPS -Scope CurrentUser
13-
Install-Module -Name Pester -Scope CurrentUser
12+
Install-PSResource -Repository $PSRepository -TrustRepository -Name platyPS
13+
Install-PSResource -Repository $PSRepository -TrustRepository -Name Pester

0 commit comments

Comments
 (0)