-
Notifications
You must be signed in to change notification settings - Fork 12
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
base: master
Are you sure you want to change the base?
Conversation
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
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.' |
There was a problem hiding this comment.
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.
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 | ||
|
||
} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -595,11 +598,23 @@ public ThreadJob( | |||
WarningRecord lockdownWarning = null; | |||
if (Environment.OSVersion.Platform.ToString().Equals("Win32NT", StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swap operands
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); |
There was a problem hiding this comment.
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.
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:
.config/tsaoptions.json
to configure instance URL, project name, area path, codebase name, notification aliases, and tools.global.json
to specify the .NET SDK version to use.Build Script Enhancements:
build.ps1
to support building withnetstandard2.0
and added support for a proxy module. [1] [2] [3]buildtools.psm1
to useMicrosoft.PowerShell.PSResourceGet
instead ofPowerShellGet
and added logic to publish both the official and proxy modules. [1] [2]Pipeline Definitions:
.pipelines/threadjobs-official.yml
to define a pipeline for building and releasing theThreadJob
module, including stages for building, manual validation, and publishing to the PowerShell Gallery.Dependency Management:
.github/dependabot.yml
to configure Dependabot for managing dependencies in the project.nuget.config
to use the PowerShellCore public packages feed.Module Versioning:
Microsoft.PowerShell.ThreadJob.psd1
to increment the module version from2.1.1
to2.2.0
.PR Context