Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Proxy Module, Setup Pipeline, Fix Project Dependency to NetStandard2.0 #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .config/tsaoptions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"instanceUrl": "https://msazure.visualstudio.com",
"projectName": "One",
"areaPath": "One\\MGMT\\Compute\\Powershell\\Powershell\\PowerShell Core\\ThreadJob",
"codebaseName": "TFSMSAzure_ThreadJob",
"notificationAliases": [ "[email protected]", "[email protected]" ],
"tools": [ "CredScan", "PoliCheck", "BinSkim" ]
}
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: "nuget" # See documentation for possible values
directory: "/src/code" # Location of package manifests
schedule:
interval: "daily"

- package-ecosystem: github-actions
directory: /
schedule:
interval: daily

- package-ecosystem: nuget
directory: /
schedule:
interval: daily
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: usually we leave a new line at the end of a file.

Copy link
Author

Choose a reason for hiding this comment

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

done

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ xhtml/
**/.vscode/**
**/out/**
**/bin/**
.vs/**/*
**/*.sln
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: please add a new line at the end.

Copy link
Author

Choose a reason for hiding this comment

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

done

248 changes: 248 additions & 0 deletions .pipelines/threadjobs-official.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
name: ThreadJob-ModuleBuild-$(Build.BuildId)
trigger: none
pr: none

schedules:
- cron: '0 3 * * 1'
displayName: Weekly Build
branches:
include:
- onebranch-pipelines
always: true

parameters:
- name: 'publishOfficialToPowerShellGallery'
displayName: 'Publish official module to PowerShell gallery'
type: boolean
default: false
- name : 'publishProxyToPowerShellGallery'
displayName: 'Publish proxy module to PowerShell gallery'
type: boolean
default: false

variables:
BuildConfiguration: Release
DOTNET_NOLOGO: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
DOTNET_CLI_TELEMETRY_OPTOUT: 1
POWERSHELL_TELEMETRY_OPTOUT: 1
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
WindowsContainerImage: onebranch.azurecr.io/windows/ltsc2022/vse2022:latest

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:
release:
category: NonAzure
featureFlags:
WindowsHostVersion:
Version: 2022
Network: Netlock
globalSdl: # https://aka.ms/obpipelines/sdl
asyncSdl:
enabled: true
forStages: [build]
#credscan:
# enabled: true
# scanfolder: $(Build.SourcesDirectory)
# suppressionsFile: $(Build.SourcesDirectory)\.config\suppress.json
stages:
- stage: build
jobs:
- job: main
displayName: Build package
pool:
type: windows
variables:
- name: ob_outputDirectory
value: $(Build.SourcesDirectory)/out
#- name: ob_sdl_credscan_suppressionsFile
# value: $(Build.SourcesDirectory)\.config\suppress.json
steps:
- pwsh: |
Write-Verbose -Verbose ((Get-Item $(Build.SourcesDirectory)).FullName)
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't ((Get-Item $(Build.SourcesDirectory)).FullName) just give you $(Build.SourcesDirectory) as the result?

Copy link
Author

Choose a reason for hiding this comment

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

Yes

Get-ChildItem $(Build.SourcesDirectory) -Recurse -File -Name | Write-Verbose -Verbose
$manifestData = Import-PowerShellDataFile -Path src/Microsoft.PowerShell.ThreadJob.psd1
$moduleVersion = $manifestData.ModuleVersion
Write-Host "##vso[task.setvariable variable=version;isOutput=true]$moduleVersion"
if ($manifestData.PrivateData.PsData.Prerelease) {
$prerel = $manifestData.PrivateData.PSData.Prerelease
$nupkgVersion = "${moduleVersion}-${prerel}"
} else {
$nupkgVersion = $moduleVersion
}
Write-Host "##vso[task.setvariable variable=nupkgversion;isOutput=true]$nupkgVersion"
Copy link
Member

Choose a reason for hiding this comment

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

I don't see nupkgversion gets used anywhere below ...

Copy link
Author

Choose a reason for hiding this comment

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

This is a relic of the pipeline I copied.

Copy link
Author

Choose a reason for hiding this comment

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

removed unnecessary lines

name: package
displayName: Get version from project properties
- task: onebranch.pipeline.version@1
displayName: Set OneBranch version
inputs:
system: Custom
customVersion: $(package.version)
Copy link
Member

Choose a reason for hiding this comment

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

where does package.version come from?

Copy link
Author

Choose a reason for hiding this comment

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

The following is in the pwsh task and sets version:

$manifestData = Import-PowerShellDataFile -Path src/Microsoft.PowerShell.ThreadJob.psd1
$moduleVersion = $manifestData.ModuleVersion
Write-Host "##vso[task.setvariable variable=version;isOutput=true]$moduleVersion"

Then the pwsh task is named package

name: package

So to access version, its using the task name as a prefix.

- task: UseDotNet@2
displayName: Use .NET SDK
inputs:
packageType: sdk
useGlobalJson: true
- pwsh: |
Get-ChildItem | Write-Verbose -Verbose
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 -MinimumVersion 1.0.5
.\build.ps1 -clean -Build -BuildConfiguration Release -BuildFramework netstandard2.0
displayName: Build
- task: onebranch.pipeline.signing@1
displayName: Sign 1st-party files
inputs:
command: sign
signing_profile: external_distribution
search_root: $(Build.SourcesDirectory)/out
files_to_sign: |
**/*.psd1;
**/*.ps1xml;
**/*.psm1;
**/Microsoft.PowerShell.*.dll;
- task: ArchiveFiles@2
displayName: Zip module
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/out/Microsoft.PowerShell.ThreadJob
includeRootFolder: false
archiveType: zip
archiveFile: out/Microsoft.PowerShell.ThreadJob-v$(package.version).zip
- task: ArchiveFiles@2
displayName: Zip module
inputs:
rootFolderOrFile: $(Build.SourcesDirectory)/out/ThreadJob
includeRootFolder: false
archiveType: zip
archiveFile: out/ThreadJob-v$(package.version).zip
Copy link
Member

Choose a reason for hiding this comment

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

Where does package.version come from? Also, it looks like you are assuming the ThreadJob and Microsoft.PowerShell.ThreadJob have the same version, which is not necessaries correct.

Copy link
Author

Choose a reason for hiding this comment

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

Origins of package.version answered above.

Yes that is true! I need to update the versioning!

Two different versionings in pipeline updated.

- pwsh: |
Get-ChildItem | Write-Verbose -Verbose
Write-Verbose -Verbose -Message "Install Microsoft.PowerShell.ThreadJob module"
Copy-Item -Path $(Build.SourcesDirectory)/out/Microsoft.PowerShell.ThreadJob -Destination ($env:PSModulePath -split ';')[0] -Recurse -Force
Write-Verbose -Verbose -Message "Test ThreadJob module manifest"
Test-ModuleManifest -Path $(Build.SourcesDirectory)/out/ThreadJob/ThreadJob.psd1
Comment on lines +128 to +131
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to install the Microsoft.PowerShell.ThreadJob module here? Also, do you need to run Test-ModuleManifest because ThreadJob.psd1 gets changed during the build process?

Copy link
Author

Choose a reason for hiding this comment

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

This was a tricky situation. The proxy module ThreadJob.psd1 defines a dependency

RequiredModules = @('Microsoft.PowerShell.ThreadJob')

The build/signing (I forgot which one was throwing the error) required that Microsoft.PowerShell.ThreadJob is present on the machine.

.\build.ps1 -Publish
Write-Verbose -Verbose ((Get-Item .).FullName)
Write-Verbose -Verbose ((Get-Item $(Build.SourcesDirectory)).FullName)
Copy link
Member

Choose a reason for hiding this comment

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

Same here, wouldn't ((Get-Item $(Build.SourcesDirectory)).FullName) just return $(Build.SourcesDirectory) as the result?

Copy link
Author

Choose a reason for hiding this comment

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

yes

Get-ChildItem $(Build.SourcesDirectory) -Recurse -File -Name | Write-Verbose -Verbose
displayName: Package module
- task: onebranch.pipeline.signing@1
displayName: Sign NuGet package
inputs:
command: sign
signing_profile: external_distribution
search_root: $(Build.SourcesDirectory)
files_to_sign: "**/*.nupkg"
Copy link
Member

Choose a reason for hiding this comment

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

Does this signed .nupkg file get published as an artifact? I don't find how it's used.

- stage: manual
dependsOn: build
jobs:
- 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
- stage: release_official_MicrosoftPowerShellThreadJob_module
displayName: release official
variables:
ob_release_environment: PPE
drop: $(Pipeline.Workspace)/drop_build_main
version: $[ stageDependencies.build.main.outputs['package.version'] ]
dependsOn: [build, manual]
condition: ${{ parameters.publishOfficialToPowerShellGallery }}
jobs:
- job: publish
templateContext:
inputs:
- input: pipelineArtifact
artifactName: drop_build_main
displayName: Publish to PowerShell Gallery
pool:
type: release
os: linux
variables:
- group: ThreadJob_Gallery_API
steps:
- task: Bash@3
inputs:
targetType: inline
script: |
sudo tdnf install -y powershell
displayName: Install PowerShell
- task: powershell@2
inputs:
pwsh: true
targetType: inline
script: |
Write-Verbose -Verbose ((Get-Item $(Pipeline.Workspace)).FullName)
Get-ChildItem $(Pipeline.Workspace) -Recurse -File -Name | Write-Verbose -Verbose
Write-Verbose -Verbose -Message "Set up CFS repository"
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted -ErrorAction Continue
Write-Verbose -Verbose -Message "Install PSResourceGet module"
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.0.5 -ErrorAction Continue -Force
Copy link
Member

Choose a reason for hiding this comment

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

This runs on Linux, do you know the version of PowerShell installed? I guess it would be 7.4.x, and in that case the PSResourceGet module is in-box.

Copy link
Author

Choose a reason for hiding this comment

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

Trying is find out if this is necessary

Write-Verbose -Verbose -Message "Publish module to PSGallery"
Publish-PSResource -ApiKey $env:GalleryPAT -Repository PSGallery -Path $(Pipeline.Workspace)/Microsoft.PowerShell.ThreadJob
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you don't need an env var?

Suggested change
Publish-PSResource -ApiKey $env:GalleryPAT -Repository PSGallery -Path $(Pipeline.Workspace)/Microsoft.PowerShell.ThreadJob
Publish-PSResource -ApiKey $(ChungJustinAPIKey) -Repository PSGallery -Path $(Pipeline.Workspace)/Microsoft.PowerShell.ThreadJob

Copy link
Author

Choose a reason for hiding this comment

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

Maybe? Do you think this needs to be changed?

Copy link
Member

Choose a reason for hiding this comment

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

Please help me understand, if you call Publish-PSResource -Path to publish, will the published .nupkg file signed?

Copy link
Author

Choose a reason for hiding this comment

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

Looking into this and testing if Publish-PSResource will do the trick.
I think I will need to use the NugetCommand task anyway.

env:
GalleryPAT: $(ChungJustinAPIKey)
displayName: Publish to PowerShell Gallery
- stage: release_proxy_ThreadJob_module
displayName: release proxy
variables:
ob_release_environment: PPE
drop: $(Pipeline.Workspace)/drop_build_main
version: $[ stageDependencies.build.main.outputs['package.version'] ]
dependsOn: [build, manual]
condition: ${{ parameters.publishProxyToPowerShellGallery }}
jobs:
- job: publish
templateContext:
inputs:
- input: pipelineArtifact
artifactName: drop_build_main
displayName: Publish to PowerShell Gallery
pool:
type: release
os: linux
variables:
- group: ThreadJob_Gallery_API
steps:
- task: Bash@3
inputs:
targetType: inline
script: |
sudo tdnf install -y powershell
displayName: Install PowerShell
- task: powershell@2
inputs:
pwsh: true
targetType: inline
script: |
Write-Verbose -Verbose ((Get-Item $(Pipeline.Workspace)).FullName)
Get-ChildItem $(Pipeline.Workspace) -Recurse -File -Name | Write-Verbose -Verbose
Write-Verbose -Verbose -Message "Set up CFS repository"
Register-PSRepository -Name CFS -SourceLocation "https://pkgs.dev.azure.com/powershell/PowerShell/_packaging/powershell/nuget/v2" -InstallationPolicy Trusted -ErrorAction Continue
Write-Verbose -Verbose -Message "Install PSResourceGet module"
Install-Module -Repository CFS -Name Microsoft.PowerShell.PSResourceGet -MinimumVersion 1.0.5 -ErrorAction Continue -Force
Write-Verbose -Verbose -Message "Install Microsoft.PowerShell.ThreadJob module"
Copy-Item -Path $(Pipeline.Workspace)/Microsoft.PowerShell.ThreadJob -Destination ($env:PSModulePath -split ':')[0] -Recurse -Force -Verbose
Write-Verbose -Verbose -Message "Test ThreadJob module manifest"
Test-ModuleManifest -Path $(Pipeline.Workspace)/ThreadJob/ThreadJob.psd1
Comment on lines +241 to +243
Copy link
Member

Choose a reason for hiding this comment

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

Can you please help me understand why this testing is needed?

Copy link
Author

Choose a reason for hiding this comment

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

That is to test and confirm the dependency in ThreadJob.psd1 and check that Microsoft.PowerShell.ThreadJob is installed on the machine.

Write-Verbose -Verbose -Message "Publish module to PSGallery"
Publish-PSResource -ApiKey $env:GalleryPAT -Repository PSGallery -Path $(Pipeline.Workspace)/ThreadJob
env:
GalleryPAT: $(ChungJustinAPIKey)
displayName: Publish to PowerShell Gallery
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: add a new line.

9 changes: 6 additions & 3 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ param (
[ValidateSet("Debug", "Release")]
[string] $BuildConfiguration = "Debug",

[ValidateSet("net461")]
[string] $BuildFramework = "net461"
[ValidateSet("netstandard2.0")]
[string] $BuildFramework = "netstandard2.0"
)
Copy link
Member

Choose a reason for hiding this comment

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

The $Signed parameter may need to be removed.


Import-Module -Name "$PSScriptRoot/buildtools.psd1" -Force

$config = Get-BuildConfiguration -ConfigPath $PSScriptRoot

$script:ModuleName = $config.ModuleName
$script:ProxyModuleName = $config.ProxyModuleName
$script:SrcPath = $config.SourcePath
$script:OutDirectory = $config.BuildOutputPath
$script:ProxyOutDirectory = $config.BuildOutputPath
Copy link
Member

Choose a reason for hiding this comment

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

Is this script variable used anywhere?

$script:SignedDirectory = $config.SignedOutputPath
$script:TestPath = $config.TestPath

Expand All @@ -53,7 +55,7 @@ if ($env:TF_BUILD) {
Write-Host "##$vstsCommandString"
}

. $PSScriptRoot/dobuild.ps1
. $PSScriptRoot/doBuild.ps1

if ($Clean -and (Test-Path $OutDirectory))
{
Expand All @@ -73,6 +75,7 @@ if ($Clean -and (Test-Path $OutDirectory))
if (-not (Test-Path $OutDirectory))
{
$script:OutModule = New-Item -ItemType Directory -Path (Join-Path $OutDirectory $ModuleName)
$script:ProxyOutModule = New-Item -itemType Directory -Path (Join-Path $OutDirectory $ProxyModuleName)
}
else
{
Expand Down
35 changes: 16 additions & 19 deletions buildtools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the MIT License.

$ConfigurationFileName = 'package.config.json'
Import-Module -Name PowerShellGet -MinimumVersion 3.0.18
Import-Module -Name Microsoft.PowerShell.PSResourceGet -Force

function Get-BuildConfiguration {
[CmdletBinding()]
Expand Down Expand Up @@ -36,6 +36,7 @@ function Get-BuildConfiguration {
$configObj.TestPath = Join-Path $projectRoot -ChildPath $configObj.TestPath
$configObj.HelpPath = Join-Path $projectRoot -ChildPath $configObj.HelpPath
$configObj.BuildOutputPath = Join-Path $projectRoot -ChildPath $configObj.BuildOutputPath

if ($configObj.SignedOutputPath) {
$configObj.SignedOutputPath = Join-Path $projectRoot -ChildPath $configObj.SignedOutputPath
}
Expand Down Expand Up @@ -69,32 +70,28 @@ function Publish-ModulePackage
)

Write-Verbose -Verbose -Message "Creating new local package repo"
$config = Get-BuildConfiguration
$localRepoName = 'packagebuild-local-repo'
$localRepoLocation = Join-Path -Path ([System.io.path]::GetTempPath()) -ChildPath $localRepoName
if (Test-Path -Path $localRepoLocation) {
Remove-Item -Path $localRepoLocation -Recurse -Force -ErrorAction Ignore
}
$null = New-Item -Path $localRepoLocation -ItemType Directory -Force
$localRepoLocation = $config.BuildOutputPath

Write-Verbose -Verbose -Message "Registering local package repo: $localRepoName"
Register-PSResourceRepository -Name $localRepoName -Uri $localRepoLocation -Trusted -Force

Write-Verbose -Verbose -Message "Publishing package to local repo: $localRepoName"
$config = Get-BuildConfiguration
if (! $Signed.IsPresent) {
Copy link
Member

Choose a reason for hiding this comment

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

$Signed is no longer required for Publish-ModulePackage, then you should remove that parameter and update all the places where Publish-ModulePacage gets called.

$modulePath = Join-Path -Path $config.BuildOutputPath -ChildPath $config.ModuleName
} else {
$modulePath = Join-Path -Path $config.SignedOutputPath -ChildPath $config.ModuleName
}
$modulePath = Join-Path -Path $config.BuildOutputPath -ChildPath $config.ModuleName

# Proxy module
Write-Verbose -Verbose -Message "Publishing proxy module to local repo: $localRepoName"
$proxyModulePath = Join-Path -Path $config.BuildOutputPath -ChildPath $config.ProxyModuleName
Publish-PSResource -Path $proxyModulePath -Repository $localRepoName -SkipDependenciesCheck -Confirm:$false -Verbose

# Official module
Write-Verbose -Verbose -Message "Publishing official module to local repo: $localRepoName"
Publish-PSResource -Path $modulePath -Repository $localRepoName -SkipDependenciesCheck -Confirm:$false -Verbose

if ($env:TF_BUILD) {
Write-Verbose -Verbose -Message "Uploading module nuget package artifact to AzDevOps"
$artifactName = "nupkg"
$artifactPath = (Get-ChildItem -Path $localRepoLocation -Filter "$($config.ModuleName)*.nupkg").FullName
$artifactPath = Resolve-Path -Path $artifactPath
Write-Host "##vso[artifact.upload containerfolder=$artifactName;artifactname=$artifactName;]$artifactPath"
}
$artifactPath = (Get-ChildItem -Path $localRepoLocation -Filter "$($config.ModuleName)*.nupkg").FullName
$artifactPath = Resolve-Path -Path $artifactPath
Copy link
Member

Choose a reason for hiding this comment

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

This call seems redundant

Write-Verbose -Verbose -Message "ArtifactPath: $artifactPath"

Write-Verbose -Verbose -Message "Unregistering local package repo: $localRepoName"
Unregister-PSResourceRepository -Name $localRepoName -Confirm:$false
Expand Down
Loading