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

Archive module preview 1 PR #131

Merged
merged 43 commits into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
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.
Jul 12, 2022
7512b08
Add project files.
Jul 12, 2022
aff9728
added path helper, archive entry
Jul 12, 2022
e535995
updated path helper
Jul 12, 2022
04adc0b
resolved bug where GetEntryName was throwing an ArgumentException
Jul 12, 2022
915f344
fixed a bug, started work on zip support
Jul 13, 2022
c05e063
worked on zip archive support
Jul 13, 2022
ef66ef9
added ArchiveFactory class
Jul 13, 2022
dde4deb
imporved zip support
Jul 13, 2022
fcde5dd
fixed a bug in tests, added error handling for DestinationPath
Jul 14, 2022
636444d
fixed bug in tests where Test-ZipArchive was not working correctly
Jul 14, 2022
50e0da3
added tests for DestinationPath
Jul 15, 2022
5cede7e
added additional tests, added TODOs
Jul 17, 2022
88ea929
updated tests
Jul 18, 2022
3dffd1d
added resx files for messages, refactored code, updated structure, etc.
Jul 19, 2022
63490c6
refactored PathHelper class
Jul 19, 2022
7986a1e
worked on automatically determining archive format based on Destinati…
Jul 19, 2022
e062f64
added support for determining archive format automatically based on D…
Jul 19, 2022
8fd551e
fixed a bug with archive format warning, added TarArchive file
Jul 19, 2022
d872cf8
renamed Action to WriteMode, fixed bug with compressing directories, …
Jul 20, 2022
bc49871
fixed bug where the directory structure of directories was not being …
Jul 20, 2022
6ee7ccb
addded exception handling to PathHelper class
Jul 21, 2022
3fc29de
removed files from git, removed tar support for preview release, adde…
Jul 21, 2022
bf53c33
updated build script, updated exception handling in PathHelper
Jul 21, 2022
5b355a6
used FileSystemInfo instead of String to store full path information
Jul 25, 2022
615994b
updated checking for the same source path and destination path
Jul 25, 2022
33d863d
updated build configuration
Jul 25, 2022
29be220
merged tests branch with CI branch
Jul 25, 2022
fd9b327
updated project version with prelease info, removed tar support after…
ayousuf23 Jul 25, 2022
cb98554
updated CI config, fixed bug with missing error message, fixed tests
ayousuf23 Jul 26, 2022
7780be0
updated CI to build module and run tests across all platforms
ayousuf23 Jul 26, 2022
68ffa8f
updated CI to run tests, added and reorganized tests, solved a bug wh…
ayousuf23 Jul 26, 2022
03ce64a
used pascal case for ArchiveFormat enum members, refactored some code…
ayousuf23 Jul 29, 2022
d9c0e8e
fixed formatting for multiple files, updated csproj to generate Messa…
ayousuf23 Jul 29, 2022
d384f50
fixed missing quotation mark in CI config, updated switch code in Arc…
ayousuf23 Jul 29, 2022
3ae0355
added assertions to prevent possible null error, added RequiredVersio…
ayousuf23 Aug 1, 2022
abeb7a2
added localized messages for Add, Create, and progress bar text, mino…
ayousuf23 Aug 2, 2022
8373aca
added copyright header, removed usage of DS in tests, minor formattin…
ayousuf23 Aug 3, 2022
f7c2af4
updated .gitignore, added explanation for why ArchiveAddition.EntryNa…
ayousuf23 Aug 4, 2022
f7cdfd2
updated Compress-Archive cmdlet to resolve a path one at a time rathe…
ayousuf23 Aug 4, 2022
b5e23c2
fixed a bug where PathNotFound error was not thrown, fixed a bug when…
ayousuf23 Aug 4, 2022
fcaaa8e
added custom assertions for testing zip archives
ayousuf23 Aug 6, 2022
dc557a5
updated CI to run tests using new assertion, updated README with Azur…
ayousuf23 Aug 8, 2022
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
77 changes: 39 additions & 38 deletions .azdevops/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,51 +27,52 @@ stages:
displayName: Build module
steps:

- task: UseDotNet@2
displayName: 'Get .NET 7.0 SDK'
inputs:
packageType: sdk
version: 7.x
includePreviewVersions: true

- pwsh: |
& $(Build.SourcesDirectory)\SimpleBuild.ps1
displayName: Build Microsoft.PowerShell.Archive module
condition: succeededOrFailed()


- pwsh: |
dir "$(BuildOutDir)\*" -Recurse
dir "$(BuildOutDir)/*" -Recurse
displayName: Show BuildOutDirectory

- template: Sbom.yml@ComplianceRepo
parameters:
BuildDropPath: "$(BuildOutDir)"
Build_Repository_Uri: 'https://github.com/PowerShell/Microsoft.PowerShell.Archive'
PackageName: $(PackageName)
PackageVersion: $(PackageVersion)
- task: CopyFiles@2
displayName: 'Copy build'
inputs:
sourceFolder: '$(BuildOutDir)'
contents: '**'
targetFolder: '$(Build.ArtifactStagingDirectory)/Microsoft.PowerShell.Archive'

- pwsh: |
dir "$(BuildOutDir)\*" -Recurse
displayName: Show BuildOutDirectory
dir "$(Build.ArtifactStagingDirectory)/*" -Recurse
- publish: '$(Build.ArtifactStagingDirectory)/Microsoft.PowerShell.Archive'
displayName: 'Publish module build'
artifact: ModuleBuild

- pwsh: |
$signSrcPath = "$(BuildOutDir)"
# Set signing src path variable
$vstsCommandString = "vso[task.setvariable variable=signSrcPath]${signSrcPath}"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
$signOutPath = "$(Build.SourcesDirectory)\signed\Microsoft.PowerShell.Archive"
$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

- pwsh: |
Copy-Item -Path "$(signSrcPath)\*" -Destination "$(signOutPath)"
displayName: Fake Signing

- pwsh: |
Compress-Archive -Path "$(signOutPath)\*" -DestinationPath "$(System.ArtifactsDirectory)\Microsoft.PowerShell.Archive.zip"
displayName: Create Microsoft.PowerShell.Archive.zip
- stage: Test
dependsOn: Build
displayName: Run tests
jobs:
- template: runtest.yml
parameters:
vmImageName: windows-2019
jobName: run_test_windows
jobDisplayName: Run Windows tests

- publish: $(System.ArtifactsDirectory)\Microsoft.PowerShell.Archive.zip
artifact: SignedModule
- template: runtest.yml
parameters:
vmImageName: ubuntu-latest
jobName: run_test_linux
jobDisplayName: Run Linux tests

- template: runtest.yml
parameters:
vmImageName: macos-latest
jobName: run_test_macos
jobDisplayName: Run macOS tests
47 changes: 47 additions & 0 deletions .azdevops/RunTests.ps1
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
}

# Import the built module
Import-Module "$env:PIPELINE_WORKSPACE/ModuleBuild/Microsoft.PowerShell.Archive.psd1"

$pesterRequiredVersion = "5.3.3"

# 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
}
105 changes: 105 additions & 0 deletions .azdevops/build.ps1
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" }
@{ 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
}
138 changes: 138 additions & 0 deletions .azdevops/build.yml
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.
Loading