diff --git a/README.md b/README.md index 8e0cd4f..10c7d7a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This project is inspired from: - [ShubhamTatvamasi/free-disk-space-action](https://github.com/ShubhamTatvamasi/free-disk-space-action) - [ThewApp/free-actions](https://github.com/ThewApp/free-actions) -> **⚠ī¸ Important:** This documentation is v0.5.0 based; To view other version's documentation, please visit the [versions list](https://github.com/hugoalh/disk-space-optimizer-ghaction/tags) and select the correct version. +> **⚠ī¸ Important:** This documentation is v0.7.0 based; To view other version's documentation, please visit the [versions list](https://github.com/hugoalh/disk-space-optimizer-ghaction/tags) and select the correct version. ## 🌟 Feature @@ -44,7 +44,7 @@ This project is inspired from: ### GitHub Actions -- **Target Version:** Runner >= v2.303.0, &: +- **Target Version:** Runner >= v2.308.0, &: - PowerShell >= v7.2.0 - **Require Permission:** *N/A* @@ -58,80 +58,110 @@ jobs: ## 🧩 Input +> **ℹī¸ Notice:** All of the inputs are optional; Use this action without any input will default to do nothing. + ### `input_listdelimiter` -**\[Optional\]** `` Delimiter when the input is accept list of values, by regular expression. +`` Delimiter when the input is accept list of values, by regular expression. ### `operate_async` > **đŸ§Ē Experimental:** This is in testing, maybe available in the latest version and/or future version. -**\[Optional\]** `` Whether to operate in asynchronously to reduce the operation duration. +`` Whether to operate in asynchronously to reduce the operation duration. ### `operate_sudo` -**(>= v0.6.0) \[Optional\]** `` Whether to execute this action in sudo mode on non-Windows environment. This can set to `True` in order to able operate protected resources on non-Windows environment. +`` Whether to execute this action in sudo mode on non-Windows environment. This can set to `True` in order to able operate protected resources on non-Windows environment. ### `general_include` -**\[Optional\]** `` Remove general item, by regular expression and [general list][list], separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). +`` Remove general item, by regular expression and [general list][list], separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). ### `general_exclude` -**\[Optional\]** `` Exclude remove general item, by regular expression and [general list][list], separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). +`` Exclude remove general item, by regular expression and [general list][list], separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). ### `docker_include` -**\[Optional\]** `` Remove Docker image, by regular expression, separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). +`` Remove Docker image, by regular expression, separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). ### `docker_exclude` -**\[Optional\]** `` Exclude remove Docker image, by regular expression, separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). +`` Exclude remove Docker image, by regular expression, separate each name by [list delimiter (input `input_listdelimiter`)](#input_listdelimiter). ### `docker_prune` -**\[Optional\]** `` Whether to prune Docker all of the dangling images. +`` Whether to prune Docker all of the dangling images. ### `docker_clean` -**\[Optional\]** `` Whether to remove Docker cache, include all of the: +`` Whether to remove Docker cache, include all of the: - build caches - stopped/unused containers - dangling and/or unreferenced images - unused networks +### `apt_enable` + +`` Whether to optimize via APT. Only affect general optimization. + ### `apt_prune` -**\[Optional\]** `` Whether to prune APT (Advanced Packaging Tools) all of the packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. +`` Whether to prune APT (Advanced Packaging Tools) all of the packages that were automatically installed to satisfy dependencies for other packages and are now no longer needed. ### `apt_clean` -**\[Optional\]** `` Whether to remove APT (Advanced Packaging Tools) cache, include the local repository of retrieved package files. +`` Whether to remove APT (Advanced Packaging Tools) cache, include the local repository of retrieved package files. + +### `chocolatey_enable` + +`` Whether to optimize via Chocolatey. Only affect general optimization. + +### `homebrew_enable` + +`` Whether to optimize via Homebrew. Only affect general optimization. ### `homebrew_prune` -**\[Optional\]** `` Whether to prune Homebrew all of the packages that were only installed as a dependency of other packages and are now no longer needed. +`` Whether to prune Homebrew all of the packages that were only installed as a dependency of other packages and are now no longer needed. ### `homebrew_clean` -**\[Optional\]** `` Whether to remove Homebrew cache, include all of the: +`` Whether to remove Homebrew cache, include all of the: - outdated downloads - old versions of installed formulae - stale lock files +### `npm_enable` + +`` Whether to optimize via NPM. Only affect general optimization. + ### `npm_prune` -**\[Optional\]** `` Whether to prune NPM (NodeJS Package Manager) all of the extraneous packages. +`` Whether to prune NPM (NodeJS Package Manager) all of the extraneous packages. ### `npm_clean` -**\[Optional\]** `` Whether to remove NPM (NodeJS Package Manager) cache. +`` Whether to remove NPM (NodeJS Package Manager) cache. + +### `pipx_enable` + +`` Whether to optimize via Pipx. Only affect general optimization. + +### `wmic_enable` + +`` Whether to optimize via WMIC. Only affect general optimization. + +### `fs_enable` + +`` Whether to optimize via file system. ### `os_swap` -**\[Optional\]** `` Whether to remove system page/swap file. +`` Whether to remove system page/swap file. ## 🧩 Output @@ -145,7 +175,7 @@ jobs: runs-on: "ubuntu-latest" steps: - name: "Optimize Disk Space" - uses: "hugoalh/disk-space-optimizer-ghaction@v0.6.0" + uses: "hugoalh/disk-space-optimizer-ghaction@v0.7.0" with: operate_sudo: "True" general_include: ".+" diff --git a/SECURITY.md b/SECURITY.md index bd02d0c..9e4e18e 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -13,6 +13,7 @@ | **Versions** | **Status** | **Target - GitHub Actions Runner** | **Target - PowerShell** | |:-:|:-:|:-:|:-:| +| v0.7.X | ✔ī¸ | >= v2.308.0 | >= v7.2.0 | | v0.6.X | ✔ī¸ | >= v2.303.0 | >= v7.2.0 | | v0.5.X | ✔ī¸ | >= v2.303.0 | >= v7.2.0 | | v0.4.X | 👎{🧓} | >= v2.303.0 | >= v7.2.0 | diff --git a/action.yml b/action.yml index 7ea104e..82ced61 100644 --- a/action.yml +++ b/action.yml @@ -38,6 +38,10 @@ inputs: description: "{Boolean} Whether to remove Docker cache." required: false default: "False" + apt_enable: + description: "{Boolean} Whether to optimize via APT." + required: false + default: "True" apt_prune: description: "{Boolean} Whether to prune APT package." required: false @@ -46,6 +50,14 @@ inputs: description: "{Boolean} Whether to remove APT cache." required: false default: "False" + chocolatey_enable: + description: "{Boolean} Whether to optimize via Chocolatey." + required: false + default: "True" + homebrew_enable: + description: "{Boolean} Whether to optimize via Homebrew." + required: false + default: "True" homebrew_prune: description: "{Boolean} Whether to prune Homebrew package." required: false @@ -54,6 +66,10 @@ inputs: description: "{Boolean} Whether to remove Homebrew cache." required: false default: "False" + npm_enable: + description: "{Boolean} Whether to optimize via NPM." + required: false + default: "True" npm_prune: description: "{Boolean} Whether to prune NPM package." required: false @@ -62,38 +78,22 @@ inputs: description: "{Boolean} Whether to remove NPM cache." required: false default: "False" - os_swap: - description: "{Boolean} Whether to remove system page/swap file." - required: false - default: "False" - dockerimage_include: - description: "{RegEx[]} Remove Docker image." - required: false - deprecationMessage: "Replaced by input `docker_include`!" - dockerimage_exclude: - description: "{RegEx[]} Exclude remove Docker image." - required: false - deprecationMessage: "Replaced by input `docker_exclude`!" - cache_apt: - description: "{Boolean} Whether to remove APT cache." - required: false - deprecationMessage: "Replaced by inputs `apt_prune` and `apt_clean`!" - cache_docker: - description: "{Boolean} Whether to remove Docker cache." + pipx_enable: + description: "{Boolean} Whether to optimize via Pipx." required: false - deprecationMessage: "Replaced by inputs `docker_prune` and `docker_clean`!" - cache_homebrew: - description: "{Boolean} Whether to remove Homebrew cache." + default: "True" + wmic_enable: + description: "{Boolean} Whether to optimize via WMIC." required: false - deprecationMessage: "Replaced by inputs `homebrew_prune` and `homebrew_clean`!" - cache_npm: - description: "{Boolean} Whether to remove NPM cache." + default: "True" + fs_enable: + description: "{Boolean} Whether to optimize via file system." required: false - deprecationMessage: "Replaced by inputs `npm_prune` and `npm_clean`!" - swap: - description: "{Boolean} Whether to remove Linux Swap Space." + default: "True" + os_swap: + description: "{Boolean} Whether to remove system page/swap file." required: false - deprecationMessage: "Replaced by input `os_swap`!" + default: "False" runs: using: "composite" steps: @@ -136,22 +136,29 @@ runs: } shell: "pwsh" env: - INPUT_APT_CLEAN: "${{inputs.cache_apt || inputs.apt_clean}}" - INPUT_APT_PRUNE: "${{inputs.cache_apt || inputs.apt_prune}}" - INPUT_DOCKER_CLEAN: "${{inputs.cache_docker || inputs.docker_clean}}" - INPUT_DOCKER_EXCLUDE: "${{inputs.dockerimage_exclude || inputs.docker_exclude}}" - INPUT_DOCKER_INCLUDE: "${{inputs.dockerimage_include || inputs.docker_include}}" - INPUT_DOCKER_PRUNE: "${{inputs.cache_docker || inputs.docker_prune}}" + INPUT_APT_CLEAN: "${{inputs.apt_clean}}" + INPUT_APT_ENABLE: "${{inputs.apt_enable}}" + INPUT_APT_PRUNE: "${{inputs.apt_prune}}" + INPUT_CHOCOLATEY_ENABLE: "${{inputs.chocolatey_enable}}" + INPUT_DOCKER_CLEAN: "${{inputs.docker_clean}}" + INPUT_DOCKER_EXCLUDE: "${{inputs.docker_exclude}}" + INPUT_DOCKER_INCLUDE: "${{inputs.docker_include}}" + INPUT_DOCKER_PRUNE: "${{inputs.docker_prune}}" + INPUT_FS_ENABLE: "${{inputs.fs_enable}}" INPUT_GENERAL_EXCLUDE: "${{inputs.general_exclude}}" INPUT_GENERAL_INCLUDE: "${{inputs.general_include}}" - INPUT_HOMEBREW_CLEAN: "${{inputs.cache_homebrew || inputs.homebrew_clean}}" - INPUT_HOMEBREW_PRUNE: "${{inputs.cache_homebrew || inputs.homebrew_prune}}" + INPUT_HOMEBREW_CLEAN: "${{inputs.homebrew_clean}}" + INPUT_HOMEBREW_ENABLE: "${{inputs.homebrew_enable}}" + INPUT_HOMEBREW_PRUNE: "${{inputs.homebrew_prune}}" INPUT_INPUT_LISTDELIMITER: "${{inputs.input_listdelimiter}}" - INPUT_NPM_CLEAN: "${{inputs.cache_npm || inputs.npm_clean}}" - INPUT_NPM_PRUNE: "${{inputs.cache_npm || inputs.npm_prune}}" + INPUT_NPM_CLEAN: "${{inputs.npm_clean}}" + INPUT_NPM_ENABLE: "${{inputs.npm_enable}}" + INPUT_NPM_PRUNE: "${{inputs.npm_prune}}" INPUT_OPERATE_ASYNC: "${{inputs.operate_async}}" INPUT_OPERATE_SUDO: "${{inputs.operate_sudo}}" - INPUT_OS_SWAP: "${{inputs.swap || inputs.os_swap}}" + INPUT_OS_SWAP: "${{inputs.os_swap}}" + INPUT_PIPX_ENABLE: "${{inputs.pipx_enable}}" + INPUT_WMIC_ENABLE: "${{inputs.wmic_enable}}" continue-on-error: true - name: "Setup PowerShell Toolkit (Sudo)" if: "${{inputs.operate_sudo == 'True'}}" diff --git a/main.ps1 b/main.ps1 index 954b1b8..265c834 100644 --- a/main.ps1 +++ b/main.ps1 @@ -149,15 +149,22 @@ Function Test-StringMatchRegEx { Where-Object -FilterScript { $_.Length -gt 0 } ) ?? @() [Boolean]$InputAptClean = [Boolean]::Parse($Env:INPUT_APT_CLEAN) +[Boolean]$InputAptEnable = [Boolean]::Parse($Env:INPUT_APT_ENABLE) [Boolean]$InputAptPrune = [Boolean]::Parse($Env:INPUT_APT_PRUNE) +[Boolean]$InputChocolateyEnable = [Boolean]::Parse($Env:INPUT_CHOCOLATEY_ENABLE) [Boolean]$InputDockerClean = [Boolean]::Parse($Env:INPUT_DOCKER_CLEAN) [Boolean]$InputDockerPrune = [Boolean]::Parse($Env:INPUT_DOCKER_PRUNE) +[Boolean]$InputFsEnable = [Boolean]::Parse($Env:INPUT_FS_ENABLE) [Boolean]$InputHomebrewClean = [Boolean]::Parse($Env:INPUT_HOMEBREW_CLEAN) +[Boolean]$InputHomebrewEnable = [Boolean]::Parse($Env:INPUT_HOMEBREW_ENABLE) [Boolean]$InputHomebrewPrune = [Boolean]::Parse($Env:INPUT_HOMEBREW_PRUNE) [Boolean]$InputNpmClean = [Boolean]::Parse($Env:INPUT_NPM_CLEAN) +[Boolean]$InputNpmEnable = [Boolean]::Parse($Env:INPUT_NPM_ENABLE) [Boolean]$InputNpmPrune = [Boolean]::Parse($Env:INPUT_NPM_PRUNE) [Boolean]$InputOperateAsync = [Boolean]::Parse($Env:INPUT_OPERATE_ASYNC) [Boolean]$InputOsSwap = [Boolean]::Parse($Env:INPUT_OS_SWAP) +[Boolean]$InputPipxEnable = [Boolean]::Parse($Env:INPUT_PIPX_ENABLE) +[Boolean]$InputWmicEnable = [Boolean]::Parse($Env:INPUT_WMIC_ENABLE) Write-Host -Object 'Resolve operation.' [String[]]$DockerImageListRaw = @() [String[]]$DockerImageRemove = @() @@ -176,14 +183,14 @@ If ($InputGeneralInclude.Count -gt 0) { Select-Object -ExpandProperty 'Collection' | Where-Object -FilterScript { (Test-StringMatchRegEx -Item $_.Name -Matcher $InputGeneralInclude) -and !(Test-StringMatchRegEx -Item $_.Name -Matcher $InputGeneralExclude) } | Where-Object -FilterScript { - ($RegistryApt.IsExist -and $Null -ine $_.APT) -or - ($RegistryChocolatey.IsExist -and $Null -ine $_.Chocolatey) -or - ($RegistryHomebrew.IsExist -and $Null -ine $_.Homebrew) -or - ($RegistryNpm.IsExist -and $Null -ine $_.NPM) -or - ($RegistryPipx.IsExist -and $Null -ine $_.Pipx) -or - ($RegistryWmic.IsExist -and $Null -ine $_.WMIC) -or - $Null -ine $_.Env -or - $Null -ine $_.($OsPathPropertyName) + ($InputAptEnable -and $RegistryApt.IsExist -and $Null -ine $_.APT) -or + ($InputChocolateyEnable -and $RegistryChocolatey.IsExist -and $Null -ine $_.Chocolatey) -or + ($InputHomebrewEnable -and $RegistryHomebrew.IsExist -and $Null -ine $_.Homebrew) -or + ($InputNpmEnable -and $RegistryNpm.IsExist -and $Null -ine $_.NPM) -or + ($InputPipxEnable -and $RegistryPipx.IsExist -and $Null -ine $_.Pipx) -or + ($InputWmicEnable -and $RegistryWmic.IsExist -and $Null -ine $_.WMIC) -or + ($InputFsEnable -and $Null -ine $_.Env) -or + ($InputFsEnable -and $Null -ine $_.($OsPathPropertyName)) } } If ($RegistryDocker.IsExist -and $InputDockerInclude.Count -gt 0 -and $InputOperateAsync) { @@ -281,31 +288,31 @@ Function Invoke-GeneralOptimizeOperation { $Null -ine $_.($OsPathPropertyName) ) } - If ($RegistryAPT.IsExist -and $QueueAPT.Count -gt 0) { + If ($InputAPTEnable -and $RegistryAPT.IsExist -and $QueueAPT.Count -gt 0) { Write-Host -Object "[ASYNC] Remove APT package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/APT" -ScriptBlock $RegistryApt.ScriptRemove -ArgumentList @(, $QueueAPT) } - If ($RegistryChocolatey.IsExist -and $QueueChocolatey.Count -gt 0) { + If ($InputChocolateyEnable -and $RegistryChocolatey.IsExist -and $QueueChocolatey.Count -gt 0) { Write-Host -Object "[ASYNC] Remove Chocolatey package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/Chocolatey" -ScriptBlock $RegistryChocolatey.ScriptRemove -ArgumentList @(, $QueueChocolatey) } - If ($RegistryHomebrew.IsExist -and $QueueHomebrew.Count -gt 0) { + If ($InputHomebrewEnable -and $RegistryHomebrew.IsExist -and $QueueHomebrew.Count -gt 0) { Write-Host -Object "[ASYNC] Remove Homebrew package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/Homebrew" -ScriptBlock $RegistryHomebrew.ScriptRemove -ArgumentList @(, $QueueHomebrew) } - If ($RegistryNpm.IsExist -and $QueueNPM.Count -gt 0) { + If ($InputNpmEnable -and $RegistryNpm.IsExist -and $QueueNPM.Count -gt 0) { Write-Host -Object "[ASYNC] Remove NPM package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/NPM" -ScriptBlock $RegistryNpm.ScriptRemove -ArgumentList @(, $QueueNPM) } - If ($RegistryPipx.IsExist -and $QueuePipx.Count -gt 0) { + If ($InputPipxEnable -and $RegistryPipx.IsExist -and $QueuePipx.Count -gt 0) { Write-Host -Object "[ASYNC] Remove Pipx package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/Pipx" -ScriptBlock $RegistryPipx.ScriptRemove -ArgumentList @(, $QueuePipx) } - If ($RegistryWmic.IsExist -and $QueueWMIC.Count -gt 0) { + If ($InputWmicEnable -and $RegistryWmic.IsExist -and $QueueWMIC.Count -gt 0) { Write-Host -Object "[ASYNC] Remove WMIC package with postpone #$Index." $Null = Start-Job -Name "$Index/PM/WMIC" -ScriptBlock $RegistryWmic.ScriptRemove -ArgumentList @(, $QueueWMIC) } - If ($QueueFSPlain.Count -gt 0) { + If ($InputFsEnable -and $QueueFSPlain.Count -gt 0) { ForEach ($FSPlain In $QueueFSPlain) { Write-Host -Object "[ASYNC] Remove $($FSPlain.Description) file with postpone #$Index." $Null = Start-Job -Name "$Index/FSPlain/$($FSPlain.Name)" -ScriptBlock { @@ -326,7 +333,7 @@ Function Invoke-GeneralOptimizeOperation { } } } - If ($QueueFSRest.Count -gt 0) { + If ($InputFsEnable -and $QueueFSRest.Count -gt 0) { $Null = Wait-Job -Name "$Index/PM/*" -ErrorAction 'SilentlyContinue' ForEach ($FSRest In $QueueFSRest) { Write-Host -Object "[ASYNC] Remove $($FSRest.Description) file with postpone #$Index." @@ -352,37 +359,37 @@ Function Invoke-GeneralOptimizeOperation { } Else { ForEach ($Item In $Queue) { - If ($RegistryAPT.IsExist -and $Null -ine $Item.APT) { + If ($InputAPTEnable -and $RegistryAPT.IsExist -and $Null -ine $Item.APT) { Write-Host -Object "Remove $($Item.Description) via APT." Invoke-Command -ScriptBlock $RegistryApt.ScriptRemove -ArgumentList @(, $Item.APT) | Write-GitHubActionsDebug } - If ($RegistryChocolatey.IsExist -and $Null -ine $Item.Chocolatey) { + If ($InputChocolateyEnable -and $RegistryChocolatey.IsExist -and $Null -ine $Item.Chocolatey) { Write-Host -Object "Remove $($Item.Description) via Chocolatey." Invoke-Command -ScriptBlock $RegistryChocolatey.ScriptRemove -ArgumentList @(, $Item.Chocolatey) | Write-GitHubActionsDebug } - If ($RegistryHomebrew.IsExist -and $Null -ine $Item.Homebrew) { + If ($InputHomebrewEnable -and $RegistryHomebrew.IsExist -and $Null -ine $Item.Homebrew) { Write-Host -Object "Remove $($Item.Description) via Homebrew." Invoke-Command -ScriptBlock $RegistryHomebrew.ScriptRemove -ArgumentList @(, $Item.Homebrew) | Write-GitHubActionsDebug } - If ($RegistryNpm.IsExist -and $Null -ine $Item.NPM) { + If ($InputNpmEnable -and $RegistryNpm.IsExist -and $Null -ine $Item.NPM) { Write-Host -Object "Remove $($Item.Description) via NPM." Invoke-Command -ScriptBlock $RegistryNpm.ScriptRemove -ArgumentList @(, $Item.NPM) | Write-GitHubActionsDebug } - If ($RegistryPipx.IsExist -and $Null -ine $Item.Pipx) { + If ($InputPipxEnable -and $RegistryPipx.IsExist -and $Null -ine $Item.Pipx) { Write-Host -Object "Remove $($Item.Description) via Pipx." Invoke-Command -ScriptBlock $RegistryPipx.ScriptRemove -ArgumentList @(, $Item.Pipx) | Write-GitHubActionsDebug } - If ($RegistryWmic.IsExist -and $Null -ine $Item.WMIC) { + If ($InputWmicEnable -and $RegistryWmic.IsExist -and $Null -ine $Item.WMIC) { Write-Host -Object "Remove $($Item.Description) via WMIC." Invoke-Command -ScriptBlock $RegistryWmic.ScriptRemove -ArgumentList @(, $Item.WMIC) | Write-GitHubActionsDebug } - If ($Null -ine $Item.Env -or $Null -ine $Item.($OsPathPropertyName)) { + If ($InputFsEnable -and ($Null -ine $Item.Env -or $Null -ine $Item.($OsPathPropertyName))) { Write-Host -Object "Remove $($Item.Description) files." ForEach ($EnvName In $Item.Env) { [String]$EnvValue = Get-Content -LiteralPath "Env:\$EnvName" -ErrorAction 'SilentlyContinue'