Skip to content

Commit 64a7ed0

Browse files
committed
Setup OneBranch and package build
1 parent 08c24ea commit 64a7ed0

File tree

3 files changed

+192
-8
lines changed

3 files changed

+192
-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: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
**/*.ps1xml;
97+
- task: onebranch.pipeline.signing@1
98+
displayName: Sign 3rd-party files
99+
inputs:
100+
command: sign
101+
signing_profile: 135020002
102+
search_root: $(Build.SourcesDirectory)/out
103+
files_to_sign: |
104+
**/Newtonsoft.Json.dll;
105+
**/Pluralize.NET.dll;
106+
- pwsh: ./build.ps1 -BuildNupkg
107+
displayName: Package module
108+
- task: onebranch.pipeline.signing@1
109+
displayName: Sign NuGet package
110+
inputs:
111+
command: sign
112+
signing_profile: external_distribution
113+
search_root: $(Build.SourcesDirectory)/out
114+
files_to_sign: |
115+
*.nupkg
116+
- stage: release
117+
dependsOn: build
118+
condition: ne(variables['Build.Reason'], 'Schedule')
119+
variables:
120+
version: $[ stageDependencies.build.main.outputs['package.version'] ]
121+
drop: $(Pipeline.Workspace)/drop_build_main
122+
jobs:
123+
- job: github
124+
displayName: Publish draft to GitHub
125+
pool:
126+
type: windows
127+
variables:
128+
ob_outputDirectory: $(Build.SourcesDirectory)/out
129+
steps:
130+
- download: current
131+
displayName: Download artifacts
132+
- task: GitHubRelease@1
133+
displayName: Create GitHub release
134+
inputs:
135+
gitHubConnection: GitHub
136+
repositoryName: PowerShell/PSScriptAnalyzer
137+
assets: |
138+
$(drop)/PSScriptAnalyzer.$(version).nupkg
139+
tagSource: userSpecifiedTag
140+
tag: v$(version)
141+
isDraft: true
142+
addChangeLog: false
143+
releaseNotesSource: inline
144+
releaseNotesInline: "<!-- TODO: Generate release notes on GitHub! -->"
145+
- job: validation
146+
displayName: Manual validation
147+
pool:
148+
type: agentless
149+
timeoutInMinutes: 1440
150+
steps:
151+
- task: ManualValidation@0
152+
displayName: Wait 24 hours for validation
153+
inputs:
154+
notifyUsers: $(Build.RequestedForEmail)
155+
instructions: Please validate the release and then publish it!
156+
timeoutInMinutes: 1440
157+
- job: publish
158+
dependsOn: validation
159+
displayName: Publish to PowerShell Gallery
160+
pool:
161+
type: windows
162+
variables:
163+
ob_outputDirectory: $(Build.SourcesDirectory)/out
164+
steps:
165+
- download: current
166+
displayName: Download artifacts
167+
- task: NuGetCommand@2
168+
displayName: Publish module to PowerShell Gallery
169+
inputs:
170+
command: push
171+
packagesToPush: $(drop)/PSScriptAnalyzer.$(version).nupkg
172+
nuGetFeedType: external
173+
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)