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

Conversation

jshigetomi
Copy link

@jshigetomi jshigetomi commented Oct 4, 2024

PR Summary

This pull request includes several updates to configuration files, build scripts, and pipeline definitions to enhance the build and release process for the ThreadJob module. The most important changes include adding new configuration files, updating build scripts to support a proxy module, and modifying pipeline definitions for automated builds and releases.

Configuration Updates:

  • Added .config/tsaoptions.json to configure instance URL, project name, area path, codebase name, notification aliases, and tools.
  • Added global.json to specify the .NET SDK version to use.

Build Script Enhancements:

  • Updated build.ps1 to support building with netstandard2.0 and added support for a proxy module. [1] [2] [3]
  • Updated buildtools.psm1 to use Microsoft.PowerShell.PSResourceGet instead of PowerShellGet and added logic to publish both the official and proxy modules. [1] [2]

Pipeline Definitions:

  • Added .pipelines/threadjobs-official.yml to define a pipeline for building and releasing the ThreadJob module, including stages for building, manual validation, and publishing to the PowerShell Gallery.

Dependency Management:

  • Added .github/dependabot.yml to configure Dependabot for managing dependencies in the project.
  • Updated nuget.config to use the PowerShellCore public packages feed.

Module Versioning:

  • Updated Microsoft.PowerShell.ThreadJob.psd1 to increment the module version from 2.1.1 to 2.2.0.

PR Context

Set up CI with Start Right

made pipeline file based on Jim's texteditor

now building with net8.0

added tsa json

added dependabot

fixed yml to sign code.

revert dotnet back to 8.0

revert back to privateassets for PowerShellStandardLibrary

revert back to privateassets for PowerShellStandardLibrary

fixed build.psm1 and yml to fix code signing error

Deleted Microsoft.PowerShell.Threadjob.csproj

Revert "Deleted Microsoft.PowerShell.Threadjob.csproj"

This reverts commit cdc5061.

Deleted Microsoft.PowerShell.ThreadJob.csproj

debugging build...

Merged PR 32351: Revert "Deleted Microsoft.PowerShell.ThreadJob.csproj"

Revert "Deleted Microsoft.PowerShell.ThreadJob.csproj"

Reverted commit `d1f649d9`.

debugging build

Updated nuget.config

fixing powershellget import with netlock

Deleted Microsoft.PowerShell.Threadjob.csproj

trying to install PSResourceGet

Trying to import PSReousrceGet

updated yml

updated yml and moved install of psresourceget to build

updated yml fixed Install-Module line

updated yml fixed version to MinimumVersion

added settings for linux

testing csproj powershel.sdk for unix

testing csproj powershel.sdk for unix

add dll in a separate folder. Fixed issues with relfection.

removed the local dll reference and the unix condition.

conditionally added SMA.Security

added conditional fomatting

using reflection for Security Policy removed dependency to SMA target framework netstandard2.0

updated pipeline with new build command netstandard2.0

fixed an issue with reflection. Abstracted the assembly to a method. Need to figure out a way to not run a process every time and save the SMA dll path.

Added DeployBoxProducts release pipeline update

edits to deploybox pipeline

edits to release pipeline

moved manual validation to a separate stage

removed nuget task and changed to PublishExtension@5 task

Updated threadjobs-official.yml removed download

Updated threadjobs-official.yml fixed dependsOn

changed method of grabbing location of SMA

Updated versions to 3.0.0.
Added proxy module and edited build scripts to publish both.

replaced periods with _ in stage name

removed spaces from stage name

added two separate boolean parameters for proxy and official in the onebranch yaml

fixed error in parameters

removed spaces from stage name

added import threadjob for psd1 required module

Added test module manifest to pipeline

changed import module from dll to entire mdoule

Install-Module instead of import

Copied the Microsoft.PowerShell.ThreadJob module to env:PSModule path

fixed signing. added archive for ThreadJob

Trying to add tfx

fixed indentation

Revert "fixed signing. added archive for ThreadJob"

This reverts commit c3ec125.

trying nugetcommand

Trying Publish-PSResource

trying task: powershell@2

fixed signing again. git revert error

changed gallery api to 2. added verbose messages to release

added error actions for release pwsh script commands

trying to add dotnet sdk

dotnet version 8.x

added pwsh true

changed os to linux

added sudo

force install psresourceget and Register-PSRepositroy -Default instead of -Name PSGallery

fixed official release to Default and removed source location

removed PSGallery registration

added variable group for api key

trying to debug variable group

mapping from env

trying version

trying package.version

moved version variable to job scope and added build as dependson in release

added download current

trying templateContext to pass nupkg artifact to release stage

removed download:current's

removed publish task. trying to find pukg

trying to find nupkg

just checking pipeline.workspace

found the nupkgs

uploading morudle folder and not the jupkg because probably -NupkgPath isn't available yet

outputtig GalleryPAT for validation

gallerypat output

trying runtime expression

moved variable group to stage variable

should work now

added var group as a job variable

added name value for variable apikey

fixed indentation issue with stage variables

switch version order

removed - in group

trying to output env

trying to add it as a stage variable

got rid of ob release environment

moved everything to stage vars. left group only in job vars

removed Gallery[PAT] installing Microsoft.PowerShell.ThreadJob to machine before publishing

added verbose statements and copy-item verbose and test-module manifest for threadjob.psd1

PSModulePath separator is : in linux ; in windows.

Changed version numbers
Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

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

Share my comments early. I will review the Microsoft.PowerShell.ThreadJob.cs tomorrow.

- 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

@@ -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

# 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

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.

Test-ModuleManifest -Path $(Build.SourcesDirectory)/out/ThreadJob/ThreadJob.psd1
.\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

<clear />
</disabledPackageSources>
</configuration>
</configuration>
Copy link
Member

Choose a reason for hiding this comment

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

new line

@{

# Script module or binary module file associated with this manifest.
RootModule = '.\ThreadJob.psm1'
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RootModule = '.\ThreadJob.psm1'
RootModule = 'ThreadJob.psm1'

Copyright = '(c) Microsoft Corporation. All rights reserved.'

# Description of the functionality provided by this module
Description = 'ThreadJob module has been renamed to 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 change to the following, but we need Sean to review and help with the message.

Suggested change
Description = 'ThreadJob module has been renamed to Microsoft.PowerShell.ThreadJob.'
Description = "The ThreadJob module is now deprecated. Please use the 'Microsoft.PowerShell.ThreadJob' module instead."

}
} # End of PrivateData hashtable

}
Copy link
Member

Choose a reason for hiding this comment

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

new line

Set-Alias -Name Start-ThreadJob -Value Microsoft.PowerShell.ThreadJob\Start-ThreadJob
Set-Alias -Name ThreadJob\Start-ThreadJob -Value Microsoft.PowerShell.ThreadJob\Start-ThreadJob

Export-ModuleMember -Alias Start-ThreadJob, ThreadJob\Start-ThreadJob
Copy link
Member

Choose a reason for hiding this comment

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

new line at the end

using System.Text;
using System.Threading;
using System.Reflection;
using System.Diagnostics;
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 this namespace is used anywhere. If so, please remove it and then you don't need the SMA = System.Management.Automation directive below.

image

@@ -595,11 +598,23 @@ public ThreadJob(
WarningRecord lockdownWarning = null;
if (Environment.OSVersion.Platform.ToString().Equals("Win32NT", StringComparison.OrdinalIgnoreCase))
Copy link
Member

Choose a reason for hiding this comment

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

Please use RuntimeInformation.IsOSPlatform(OSPlatform.Windows) instead. It's supported in netstandard2.0.

Comment on lines +601 to +608
Assembly assembly = Assembly.LoadFrom(typeof(PSObject).Assembly.Location);
Type systemPolicy = assembly.GetType("System.Management.Automation.Security.SystemPolicy");
MethodInfo getSystemLockdownPolicy = systemPolicy.GetMethod("GetSystemLockdownPolicy", BindingFlags.Public | BindingFlags.Static);
object lockdownPolicy = getSystemLockdownPolicy.Invoke(null, null);

Type systemEnforcementMode = assembly.GetType("System.Management.Automation.Security.SystemEnforcementMode");
FieldInfo enforce = systemEnforcementMode.GetField("Enforce");
object enforceValue = enforce.GetValue(null);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Assembly assembly = Assembly.LoadFrom(typeof(PSObject).Assembly.Location);
Type systemPolicy = assembly.GetType("System.Management.Automation.Security.SystemPolicy");
MethodInfo getSystemLockdownPolicy = systemPolicy.GetMethod("GetSystemLockdownPolicy", BindingFlags.Public | BindingFlags.Static);
object lockdownPolicy = getSystemLockdownPolicy.Invoke(null, null);
Type systemEnforcementMode = assembly.GetType("System.Management.Automation.Security.SystemEnforcementMode");
FieldInfo enforce = systemEnforcementMode.GetField("Enforce");
object enforceValue = enforce.GetValue(null);
Assembly assembly = typeof(PSObject).Assembly;
Type systemPolicy = assembly.GetType("System.Management.Automation.Security.SystemPolicy");
MethodInfo getSystemLockdownPolicy = systemPolicy.GetMethod("GetSystemLockdownPolicy", BindingFlags.Public | BindingFlags.Static);
object lockdownPolicy = getSystemLockdownPolicy.Invoke(null, Array.Empty<object>());
Type systemEnforcementMode = assembly.GetType("System.Management.Automation.Security.SystemEnforcementMode");
FieldInfo enforce = systemEnforcementMode.GetField("Enforce");
object enforceValue = enforce.GetValue(null);

Copy link
Member

Choose a reason for hiding this comment

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

actually, we should get the required MethodInfo and the value of SystemEnforcementMode.Enforce in the static constructor of this type, so we do the reflection only once per process.

FieldInfo enforce = systemEnforcementMode.GetField("Enforce");
object enforceValue = enforce.GetValue(null);

bool enforceLockdown = lockdownPolicy.Equals(enforceValue);
Copy link
Member

Choose a reason for hiding this comment

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

Swap the operands to make sure it works when lockdownPolicy is null.

Suggested change
bool enforceLockdown = lockdownPolicy.Equals(enforceValue);
bool enforceLockdown = enforceValue.Equals(lockdownPolicy);

MethodInfo[] methods = systemPolicy.GetMethods(BindingFlags.Public | BindingFlags.Static);
MethodInfo getLockdownPolicy = systemPolicy.GetMethod("GetLockdownPolicy", BindingFlags.Public | BindingFlags.Static, null, new Type[] { typeof(string), typeof(SafeHandle) }, null);
lockdownPolicy = getLockdownPolicy.Invoke(null, new object[] { _filePath, null });
enforceLockdown = lockdownPolicy.Equals(enforceValue);
Copy link
Member

Choose a reason for hiding this comment

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

swap operands

Suggested change
enforceLockdown = lockdownPolicy.Equals(enforceValue);
enforceLockdown = enforceValue.Equals(lockdownPolicy);

@@ -1087,7 +1102,21 @@ private ScriptBlock GetScriptBlockFromFile(string filePath, PSCmdlet psCmdlet)

private void SetJobState(JobState jobState, Exception reason, bool disposeRunspace = false)
{
base.SetJobState(jobState, reason);
Copy link
Member

Choose a reason for hiding this comment

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

This is a bug in the PowerShellStandard.Library package. I have reported this to Patrick, who is the owner of that package. He will look into it and release a new version of the package with the fix. We need to delay the release of ThreadJob till that fix is in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants