Skip to content

Commit

Permalink
Merge pull request #2875 from PrismLibrary/ci-consolidated-fix
Browse files Browse the repository at this point in the history
Use script file to consolidate resources
  • Loading branch information
dansiegel authored Jun 9, 2023
2 parents 264869a + a888ab7 commit ed88922
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 44 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ on:
- Directory.Packages.props
- xunit.runner.json
- 'src/**'
pull_request:
branches: [ master ]
paths:
- .github/workflows/ci.yml

jobs:
build-prism-core:
Expand Down Expand Up @@ -91,6 +95,9 @@ jobs:
needs: [build-prism-core, build-prism-wpf, build-prism-forms, build-prism-uno, build-prism-maui]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download Core
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -122,28 +129,9 @@ jobs:
path: artifacts\Maui

- name: Consolidate Artifacts
run: |
# Ensure artifacts directory is clean
Get-ChildItem .\ -Include artifacts -Recurse | ForEach-Object ($_) { Remove-Item $_.Fullname -Force -Recurse }
mkdir artifacts\binaries
mkdir artifacts\nuget
$platforms = @('Forms', 'Wpf', 'Uno', 'Maui')
$platformNuGet = $platforms | ForEach-Object { Join-Path -Path .\artifacts -ChildPath "$_\NuGet" }
$platformBinary = $platforms | ForEach-Object { Join-Path -Path .\artifacts -ChildPath "$_\Release" }
Get-ChildItem $platformNuGet -Filter '*.nupkg' | Where-Object { $_.Name.StartsWith('Prism.Core') -eq $false } | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\nuget }else { Write-Warning "File already exists: $($_.FullName)" } }
Get-ChildItem $platformNuGet -Filter '*.snupkg' | Where-Object { $_.Name.StartsWith('Prism.Core') -eq $false } | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\nuget }else { Write-Warning "File already exists: $($_.FullName)" } }
Get-ChildItem $platformBinary | Where-Object { $_.Name -ne 'Core' } | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\binaries }else { Write-Warning "File already exists: $($_.FullName)" } }
Get-ChildItem .\artifacts\Core\NuGet -Filter '*.nupkg' | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\nuget }else { Write-Warning "File already exists: $($_.FullName)" } }
Get-ChildItem .\artifacts\Core\NuGet -Filter '*.snupkg' | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\nuget }else { Write-Warning "File already exists: $($_.FullName)" } }
Get-ChildItem .\artifacts\Core\Release | ForEach-Object { if(!(Test-Path -Path $_.FullName)) { Copy-Item $_.FullName .\artifacts\binaries }else { Write-Warning "File already exists: $($_.FullName)" } }
Remove-Item artifacts\Core -Recurse
Remove-Item artifacts\Wpf -Recurse
Remove-Item artifacts\Forms -Recurse
Remove-Item artifacts\Uno -Recurse
Remove-Item artifacts\Maui -Recurse
Get-ChildItem .\artifacts\nuget | ForEach-Object { Write-Host $_.FullName }
run: build\consolidate-artifacts.ps1
shell: powershell


- name: Upload Consolidated NuGets
uses: actions/upload-artifact@v3
Expand Down
27 changes: 5 additions & 22 deletions .github/workflows/start-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ jobs:
needs: [build-prism-core, build-prism-wpf, build-prism-forms, build-prism-uno]
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Download Core
uses: actions/download-artifact@v3
with:
Expand Down Expand Up @@ -114,28 +117,8 @@ jobs:
path: artifacts\Maui

- name: Consolidate Artifacts
run: |
mkdir artifacts\binaries
$platforms = @('Forms', 'Wpf', 'Uno', 'Maui')
$platformNuGet = $platforms | ForEach-Object { Join-Path -Path .\artifacts -ChildPath "$_\NuGet" }
$platformBinary = $platforms | ForEach-Object { Join-Path -Path .\artifacts -ChildPath "$_\Release" }
Get-ChildItem $platformNuGet -Filter '*.nupkg' | Where-Object { $_.Name.StartsWith('Prism.Core') -eq $false } | ForEach-Object { Copy-Item $_.FullName .\artifacts }
Get-ChildItem $platformNuGet -Filter '*.snupkg' | Where-Object { $_.Name.StartsWith('Prism.Core') -eq $false } | ForEach-Object { Copy-Item $_.FullName .\artifacts }
Get-ChildItem $platformBinary | Where-Object { $_.Name -ne 'Core' } | ForEach-Object { Copy-Item $_.FullName .\artifacts\binaries -Recurse }
Get-ChildItem .\artifacts\Core\NuGet -Filter '*.nupkg' | ForEach-Object { Copy-Item $_.FullName .\artifacts }
Get-ChildItem .\artifacts\Core\NuGet -Filter '*.snupkg' | ForEach-Object { Copy-Item $_.FullName .\artifacts }
Get-ChildItem .\artifacts\Core\Release | ForEach-Object { Copy-Item $_.FullName .\artifacts\binaries -Recurse }
Compress-Archive -Path (Get-ChildItem .\artifacts\binaries) -DestinationPath .\artifacts\binaries.zip
Remove-Item artifacts\Core -Recurse
Remove-Item artifacts\Wpf -Recurse
Remove-Item artifacts\Forms -Recurse
Remove-Item artifacts\Uno -Recurse
Remove-Item artifacts\Maui -Recurse
Remove-Item artifacts\binaries -Recurse
Get-ChildItem .\artifacts | ForEach-Object { Write-Host $_.FullName }
run: build\consolidate-artifacts.ps1
shell: powershell

- name: Upload Consolidated NuGets
uses: actions/upload-artifact@v3
Expand Down
64 changes: 64 additions & 0 deletions build/consolidate-artifacts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Ensure artifacts directory is clean

$executionRoot = Get-Location
$artifactsRoot = $executionRoot, 'artifacts' -join '\'
$binariesRoot = $executionRoot, 'artifacts', 'binaries' -join '\'
$nugetRoot = $executionRoot, 'artifacts', 'nuget' -join '\'
Get-ChildItem .\ -Include $binariesRoot -Recurse | ForEach-Object ($_) { Remove-Item $_.Fullname -Force -Recurse }
Get-ChildItem .\ -Include $nugetRoot -Recurse | ForEach-Object ($_) { Remove-Item $_.Fullname -Force -Recurse }
New-Item -Path $binariesRoot -ItemType Directory -Force > $null
New-Item -Path $nugetRoot -ItemType Directory -Force > $null
$platforms = @('Forms', 'Wpf', 'Uno', 'Maui')

$core = @("Prism.Core", "Prism.Events", "Prism.dll", "Prism.pdb", "Prism.xml")
$allowedExtensions = @('.dll', '.pdb', '.xml', '.pri', '.nupkg', '.snupkg')
$files = Get-ChildItem -Path $artifactsRoot -Filter "*" -Recurse | Where-Object { (Test-Path -Path $_.FullName -PathType Leaf) -and $_.FullName.StartsWith($binariesRoot) -eq $false -and $_.FullName.StartsWith($nugetRoot) -eq $false -and ($allowedExtensions -contains [System.IO.Path]::GetExtension($_.FullName)) }

if ($files.Count -eq 0)
{
$stringBuilder = New-Object System.Text.StringBuilder
$stringBuilder.AppendLine("Execution Root: $executionRoot")
$stringBuilder.AppendLine("Artifacts:")
Get-ChildItem $artifactsRoot | ForEach-Object { $stringBuilder.AppendLine($_.FullName) }
$stringBuilder.AppendLine("No files found to copy")
Write-Error -Message $stringBuilder.ToString()
exit 1
}

foreach($file in $files)
{
Write-Output "Processing $($file)"
if ($file -match ($platforms -join '|') -and $file -match ($core -join '|'))
{
# Ignore Prism.Core / Prism.Events built with platforms
continue
}
elseif ($file -like "*.nupkg" -or $file -like "*.snupkg")
{
Write-Output "Copying $($file.FullName) to $nugetRoot"
Copy-Item $file.FullName $nugetRoot
}
elseif ($file -like "*.dll" -or $file -like "*.pdb" -or $file -like "*.xml" -or $file -like "*.pri")
{
if($file.FullName-like ($platforms -join '|') -or $file.FullName -like 'Core')
{
continue
}

Write-Output "Getting TFM Directory Name for $($file.FullName)"
$parentDirName = Split-Path -Path (Split-Path -Path $file.FullName -Parent) -Leaf

Write-Output "Determining Copy Path for $parentDirName"
$copyPath = Join-Path $binariesRoot -ChildPath $parentDirName

if ((Test-Path -Path $copyPath -PathType Container) -eq $false)
{
Write-Output "Creating $copyPath"
New-Item -Path $copyPath -ItemType Directory -Force > $null
}
Write-Output "Copying $($file.FullName) to $copyPath"
Copy-Item $file.FullName $copyPath
}
}

Get-ChildItem $artifactsRoot | Where-Object { $_.Name -ne 'binaries' -and $_.Name -ne 'nuget' } | ForEach-Object { Remove-Item $_.FullName -Force -Recurse }

0 comments on commit ed88922

Please sign in to comment.