Skip to content

Commit

Permalink
Skip creating Resources/Icons zip if nothing has changed
Browse files Browse the repository at this point in the history
Speeds up building when not required (git is required)
  • Loading branch information
maforget committed Jul 5, 2024
1 parent 76e48c0 commit 9836be8
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions CompressIconFolders.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,50 @@ if (-not (Test-Path $iconDirectory)) {
exit 1
}

# Use Git to check for changes in the Resources/Icons directory
$gitChangedFiles = git status --porcelain | Select-String -Pattern "^.+/Resources/Icons/"

$folders = Get-ChildItem -Path $iconDirectory -Directory

# Iterate through each folder
foreach ($folder in $folders) {
# Define the full path to the folder and the destination zip file
$folderPath = Join-Path -Path $folder.FullName -ChildPath "*.*"
$destinationPath = "$($folder.FullName).zip"

# Check if the zip file exists
$zipExists = Test-Path $destinationPath

# Determine if we need to update the zip file
$updateRequired = $false
if ($zipExists) {
if ($gitChangedFiles.Count -gt 0) {
foreach ($changedFile in $gitChangedFiles) {
if ($changedFile -like "*$($folder.Name)/*") {
$updateRequired = $true
Write-Output "$destinationPath exists, but there are changes, updating it."
break
}
}
}
} else {
$updateRequired = $true
Write-Output "$destinationPath doesn't exists, need to create it."
}

# Compress the folder into a zip file
Compress-Archive -Path $folderPath -DestinationPath $destinationPath -Force
if ($updateRequired) {
# Compress the folder into a zip file
Compress-Archive -Path $folderPath -DestinationPath $destinationPath -Force
} else {
Write-Output "$destinationPath is up to date. No action required."
}


# Check if the zip file was created successfully
if (Test-Path $destinationPath) {
# Delete the original folder if the zip file exists
Remove-Item -Path $folder.FullName -Recurse -Force
} else {
Write-Error "Failed to create $destinationPath"
exit 1
}
}
}

0 comments on commit 9836be8

Please sign in to comment.