- 
                Notifications
    You must be signed in to change notification settings 
- Fork 39
Archive module preview 1 PR #131
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
          
     Merged
      
      
            SeeminglyScience
  merged 43 commits into
  PowerShell:master
from
ayousuf23:merge-with-master
  
      
      
   
  Aug 11, 2022 
      
    
  
     Merged
                    Changes from 37 commits
      Commits
    
    
            Show all changes
          
          
            43 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      7711837
              
                Add .gitattributes, .gitignore, and README.md.
              
              
                 7512b08
              
                Add project files.
              
              
                 aff9728
              
                added path helper, archive entry
              
              
                 e535995
              
                updated path helper
              
              
                 04adc0b
              
                resolved bug where GetEntryName was throwing an ArgumentException
              
              
                 915f344
              
                fixed a bug, started work on zip support
              
              
                 c05e063
              
                worked on zip archive support
              
              
                 ef66ef9
              
                added ArchiveFactory class
              
              
                 dde4deb
              
                imporved zip support
              
              
                 fcde5dd
              
                fixed a bug in tests, added error handling for DestinationPath
              
              
                 636444d
              
                fixed bug in tests where Test-ZipArchive was not working correctly
              
              
                 50e0da3
              
                added tests for DestinationPath
              
              
                 5cede7e
              
                added additional tests, added TODOs
              
              
                 88ea929
              
                updated tests
              
              
                 3dffd1d
              
                added resx files for messages, refactored code, updated structure, etc.
              
              
                 63490c6
              
                refactored PathHelper class
              
              
                 7986a1e
              
                worked on automatically determining archive format based on Destinati…
              
              
                 e062f64
              
                added support for determining archive format automatically based on D…
              
              
                 8fd551e
              
                fixed a bug with archive format warning, added TarArchive file
              
              
                 d872cf8
              
                renamed Action to WriteMode, fixed bug with compressing directories, …
              
              
                 bc49871
              
                fixed bug where the directory structure of directories was not being …
              
              
                 6ee7ccb
              
                addded exception handling to PathHelper class
              
              
                 3fc29de
              
                removed files from git, removed tar support for preview release, adde…
              
              
                 bf53c33
              
                updated build script, updated exception handling in PathHelper
              
              
                 5b355a6
              
                used FileSystemInfo instead of String to store full path information
              
              
                 615994b
              
                updated checking for the same source path and destination path
              
              
                 33d863d
              
                updated build configuration
              
              
                 29be220
              
                merged tests branch with CI branch
              
              
                 fd9b327
              
                updated project version with prelease info, removed tar support after…
              
              
                ayousuf23 cb98554
              
                updated CI config, fixed bug with missing error message, fixed tests
              
              
                ayousuf23 7780be0
              
                updated CI to build module and run tests across all platforms
              
              
                ayousuf23 68ffa8f
              
                updated CI to run tests, added and reorganized tests, solved a bug wh…
              
              
                ayousuf23 03ce64a
              
                used pascal case for ArchiveFormat enum members, refactored some code…
              
              
                ayousuf23 d9c0e8e
              
                fixed formatting for multiple files, updated csproj to generate Messa…
              
              
                ayousuf23 d384f50
              
                fixed missing quotation mark in CI config, updated switch code in Arc…
              
              
                ayousuf23 3ae0355
              
                added assertions to prevent possible null error, added RequiredVersio…
              
              
                ayousuf23 abeb7a2
              
                added localized messages for Add, Create, and progress bar text, mino…
              
              
                ayousuf23 8373aca
              
                added copyright header, removed usage of DS in tests, minor formattin…
              
              
                ayousuf23 f7c2af4
              
                updated .gitignore, added explanation for why ArchiveAddition.EntryNa…
              
              
                ayousuf23 f7cdfd2
              
                updated Compress-Archive cmdlet to resolve a path one at a time rathe…
              
              
                ayousuf23 b5e23c2
              
                fixed a bug where PathNotFound error was not thrown, fixed a bug when…
              
              
                ayousuf23 fcaaa8e
              
                added custom assertions for testing zip archives
              
              
                ayousuf23 dc557a5
              
                updated CI to run tests using new assertion, updated README with Azur…
              
              
                ayousuf23 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Load the module | ||
| $module = Get-Module -Name "Microsoft.PowerShell.Archive" | ||
| if ($null -ne $module) | ||
| { | ||
| Remove-Module $module | ||
|         
                  ayousuf23 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| } | ||
|  | ||
| # Import the built module | ||
| Import-Module "$env:PIPELINE_WORKSPACE/ModuleBuild/Microsoft.PowerShell.Archive.psd1" | ||
|  | ||
| $pesterRequiredVersion = "5.3.3" | ||
|         
                  ayousuf23 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
|  | ||
| # If Pester 5.3.3 is not installed, install it | ||
| $shouldInstallPester = $true | ||
|  | ||
| if ($pesterModules = Get-Module -Name "Pester" -ListAvailable) { | ||
| foreach ($module in $pesterModules) { | ||
| if ($module.Version.ToString() -eq $pesterRequiredVersion) { | ||
| $shouldInstallPester = $false | ||
| break | ||
| } | ||
| } | ||
| } | ||
|  | ||
| if ($shouldInstallPester) { | ||
| Install-Module -Name "Pester" -RequiredVersion $pesterRequiredVersion -Force | ||
| } | ||
|  | ||
| # Load Pester | ||
| Import-Module -Name "Pester" -RequiredVersion $pesterRequiredVersion | ||
|  | ||
| # Run tests | ||
| $OutputFile = "$PWD/build-unit-tests.xml" | ||
| $results = $null | ||
| $results = Invoke-Pester -Script ./Tests/Compress-Archive.Tests.ps1 -OutputFile $OutputFile -PassThru -OutputFormat NUnitXml -Show Failed, Context, Describe, Fails | ||
| Write-Host "##vso[artifact.upload containerfolder=testResults;artifactname=testResults]$OutputFile" | ||
| if(!$results -or $results.FailedCount -gt 0 -or !$results.TotalCount) | ||
| { | ||
| throw "Build or tests failed. Passed: $($results.PassedCount) Failed: $($results.FailedCount) Total: $($results.TotalCount)" | ||
| } | ||
|  | ||
| # Unload module | ||
| $module = Get-Module -Name "Microsoft.PowerShell.Archive" | ||
| if ($null -ne $module) | ||
| { | ||
| Remove-Module $module | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| [CmdletBinding(SupportsShouldProcess=$true)] | ||
| param ( | ||
| [switch]$test, | ||
| [switch]$build, | ||
| [switch]$publish, | ||
| [switch]$signed, | ||
| [switch]$package, | ||
| [switch]$coverage, | ||
| [switch]$CopySBOM, | ||
| [string]$SignedPath | ||
| ) | ||
|  | ||
|  | ||
| $root = (Resolve-Path -Path "${PSScriptRoot}/../")[0] | ||
| $Name = "Microsoft.PowerShell.Archive" | ||
| $BuildOutputDir = Join-Path $root "\src\bin\Release" | ||
| $ManifestPath = "${BuildOutputDir}\${Name}.psd1" | ||
| $ManifestData = Import-PowerShellDataFile -Path $ManifestPath | ||
| $Version = $ManifestData.ModuleVersion | ||
|  | ||
| $SignRoot = "${root}\signed\${Name}" | ||
| $SignVersion = "$SignRoot\$Version" | ||
|  | ||
| $PubBase = "${root}\out" | ||
| $PubRoot = "${PubBase}\${Name}" | ||
| $PubDir = "${PubRoot}\${Version}" | ||
|  | ||
| if (-not $test -and -not $build -and -not $publish -and -not $package) { | ||
| throw "must use 'build', 'test', 'publish', 'package'" | ||
| } | ||
|  | ||
| [bool]$verboseValue = $PSBoundParameters['Verbose'].IsPresent ? $PSBoundParameters['Verbose'].ToBool() : $false | ||
|  | ||
| $FileManifest = @( | ||
| @{ SRC = "${$BuildOutputDir}"; NAME = "Microsoft.PowerShell.Archive.dll"; SIGN = $true ; DEST = "OUTDIR" } | ||
|         
                  ayousuf23 marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| @{ SRC = "${$BuildOutputDir}"; NAME = "Microsoft.PowerShell.Archive.psm1"; SIGN = $true ; DEST = "OUTDIR" } | ||
| ) | ||
|  | ||
| if ($build) { | ||
| Write-Verbose -Verbose -Message "No action for build" | ||
| } | ||
|  | ||
| # this takes the files for the module and publishes them to a created, local repository | ||
| # so the nupkg can be used to publish to the PSGallery | ||
| function Export-Module | ||
| { | ||
| [System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")] | ||
| param() | ||
| if ( $signed ) { | ||
| $packageRoot = $SignedPath | ||
| } | ||
| else { | ||
| $packageRoot = $PubRoot | ||
| } | ||
|  | ||
| if ( -not (test-path $packageRoot)) { | ||
| throw "'$PubDir' does not exist" | ||
| } | ||
|  | ||
| # now constuct a nupkg by registering a local repository and calling publish module | ||
| $repoName = [guid]::newGuid().ToString("N") | ||
| Register-PSRepository -Name $repoName -SourceLocation $packageRoot -InstallationPolicy Trusted | ||
| Publish-Module -Path $packageRoot -Repository $repoName | ||
| Unregister-PSRepository -Name $repoName | ||
| Get-ChildItem -Recurse -Name $packageRoot | Write-Verbose | ||
| $nupkgName = "{0}.{1}-preview1.nupkg" -f ${Name},${Version} | ||
| $nupkgPath = Join-Path $packageRoot $nupkgName | ||
| if ($env:TF_BUILD) { | ||
| # In Azure DevOps | ||
| Write-Host "##vso[artifact.upload containerfolder=$nupkgName;artifactname=$nupkgName;]$nupkgPath" | ||
| } | ||
| } | ||
|  | ||
| if ($publish) { | ||
| Write-Verbose "Publishing to '$PubDir'" | ||
| if (-not (test-path $PubDir)) { | ||
| $null = New-Item -ItemType Directory $PubDir -Force | ||
| } | ||
| foreach ($file in $FileManifest) { | ||
| if ($signed -and $file.SIGN) { | ||
| $src = Join-Path -Path $PSScriptRoot -AdditionalChildPath $file.NAME -ChildPath signed | ||
| } | ||
| else { | ||
| $src = Join-Path -Path $file.SRC -ChildPath $file.NAME | ||
| } | ||
| $targetDir = $file.DEST -creplace "OUTDIR","$PubDir" | ||
| if (-not (Test-Path $src)) { | ||
| throw ("file '" + $src + "' not found") | ||
| } | ||
| if (-not (Test-Path $targetDir)) { | ||
| $null = New-Item -ItemType Directory $targetDir -Force | ||
| } | ||
| Copy-Item -Path $src -destination $targetDir -Verbose:$verboseValue | ||
|  | ||
| } | ||
| } | ||
|  | ||
| # this copies the manifest before creating the module nupkg | ||
| # if -CopySBOM is used. | ||
| if ($package) { | ||
| if($CopySBOM) { | ||
| #Copy-Item -Recurse -Path "signed/_manifest" -Destination $SignVersion | ||
| } | ||
| Export-Module | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| name: Microsoft.PowerShell.Archive-$(Build.BuildId) | ||
| trigger: none | ||
|  | ||
| pr: none | ||
|  | ||
| variables: | ||
| DOTNET_CLI_TELEMETRY_OPTOUT: 1 | ||
| POWERSHELL_TELEMETRY_OPTOUT: 1 | ||
|  | ||
| resources: | ||
| repositories: | ||
| - repository: ComplianceRepo | ||
| type: github | ||
| endpoint: ComplianceGHRepo | ||
| name: PowerShell/compliance | ||
| ref: master | ||
|  | ||
| stages: | ||
| - stage: Build | ||
| displayName: Build | ||
| pool: | ||
| name: 1ES | ||
| demands: | ||
| - ImageOverride -equals PSMMS2019-Secure | ||
| jobs: | ||
| - job: Build_Job | ||
| displayName: Build Microsoft.PowerShell.Archive | ||
| variables: | ||
| - group: ESRP | ||
| steps: | ||
| - checkout: self | ||
|  | ||
| - task: UseDotNet@2 | ||
| displayName: 'Get .NET 7.0 SDK' | ||
| inputs: | ||
| packageType: sdk | ||
| version: 7.x | ||
| includePreviewVersions: true | ||
|  | ||
| - pwsh: | | ||
| & $(Build.SourcesDirectory)/Microsoft.PowerShell.Archive/SimpleBuild.ps1 | ||
| displayName: Build Microsoft.PowerShell.Archive module | ||
|  | ||
| - pwsh: | | ||
| dir "$(BuildOutDir)\*" -Recurse | ||
| displayName: Show BuildOutDirectory | ||
|  | ||
| - pwsh: | | ||
| $signSrcPath = "$(BuildOutDir)" | ||
| # Set signing src path variable | ||
| $vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}" | ||
| Write-Host "sending " + $vstsCommandString | ||
| Write-Host "##$vstsCommandString" | ||
| # Get the module version | ||
| $ManifestPath = Join-Path $(BuildOutDir) "Microsoft.PowerShell.Archive.psd1" | ||
| $ManifestData = Import-PowerShellDataFile -Path $ManifestPath | ||
| $Version = $ManifestData.ModuleVersion | ||
| $signOutPath = "$(Build.SourcesDirectory)\signed\Microsoft.PowerShell.Archive\${Version}" | ||
| $null = New-Item -ItemType Directory -Path $signOutPath | ||
| # Set signing out path variable | ||
| $vstsCommandString = "vso[task.setvariable variable=signOutPath]${signOutPath}" | ||
| Write-Host "sending " + $vstsCommandString | ||
| Write-Host "##$vstsCommandString" | ||
| # Set path variable for guardian codesign validation | ||
| $vstsCommandString = "vso[task.setvariable variable=GDN_CODESIGN_TARGETDIRECTORY]${signOutPath}" | ||
| Write-Host "sending " + $vstsCommandString | ||
| Write-Host "##$vstsCommandString" | ||
| displayName: Setup variables for signing | ||
|  | ||
| - checkout: ComplianceRepo | ||
|  | ||
| - task: UseDotNet@2 | ||
| displayName: 'Get .NET 2.1 SDK' | ||
| inputs: | ||
| packageType: sdk | ||
| version: 2.x | ||
| includePreviewVersions: true | ||
|  | ||
| - template: EsrpSign.yml@ComplianceRepo | ||
| parameters: | ||
| # the folder which contains the binaries to sign | ||
| buildOutputPath: $(signSrcPath) | ||
| # the location to put the signed output | ||
| signOutputPath: $(signOutPath) | ||
| # the certificate ID to use | ||
| certificateId: "CP-230012" | ||
| # the file pattern to use, comma separated | ||
| pattern: '*.psd1,*.dll' | ||
|  | ||
| - template: Sbom.yml@ComplianceRepo | ||
| parameters: | ||
| BuildDropPath: $(signOutPath) | ||
| Build_Repository_Uri: 'https://github.com/PowerShell/Microsoft.PowerShell.Archive' | ||
|  | ||
| - pwsh: | | ||
| Get-ChildItem $(signOutPath) -Recurse | Write-Output | ||
|  | ||
| - pwsh: | | ||
| Set-Location "$(Build.SourcesDirectory)" | ||
| # signOutPath points to directory with version number -- we want to point to the parent of that directory | ||
| $ModulePath = Split-Path $(signOutPath) -Parent | ||
| $(Build.SourcesDirectory)/Microsoft.PowerShell.Archive/.azdevops/build.ps1 -package -CopySBOM -signed -SignedPath $ModulePath | ||
| Get-ChildItem -recurse -file -name | Write-Verbose -Verbose | ||
| displayName: package build | ||
|  | ||
| - publish: "$(signSrcPath)" | ||
| artifact: build | ||
| displayName: Publish build | ||
|  | ||
| - stage: compliance | ||
| displayName: Compliance | ||
| dependsOn: Build | ||
| jobs: | ||
| - job: Compliance_Job | ||
| pool: | ||
| name: 1ES # Package ES CodeHub Lab E | ||
| steps: | ||
| - checkout: self | ||
| - checkout: ComplianceRepo | ||
| - download: current | ||
| artifact: build | ||
|  | ||
| - pwsh: | | ||
| Get-ChildItem -Path "$(Pipeline.Workspace)\build" -Recurse | ||
| displayName: Capture downloaded artifacts | ||
| - template: script-module-compliance.yml@ComplianceRepo | ||
| parameters: | ||
| # component-governance | ||
| sourceScanPath: '$(Build.SourcesDirectory)\Microsoft.PowerShell.Archive\src' | ||
| # credscan | ||
| suppressionsFile: '' | ||
| # TermCheck | ||
| optionsRulesDBPath: '' | ||
| optionsFTPath: '' | ||
| # tsa-upload | ||
| codeBaseName: 'PSNativeCommandProxy_2020' | ||
| # selections | ||
| APIScan: false # set to false when not using Windows APIs. | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.