Closed LaurentDardenne closed 2 years ago
I plan to change the default allow-prerelease parameter to false instead of true. The basic use of the cache, at least for me, is to validate code using modules with a stable version (Pester, PSSA).
To date the allow-prerelease parameter concerns all the modules present in 'module-to-cache', to have a unitary management of the prerelease the addition of a parameter 'module-to-cache-with-prerelease' can be considered .
For the moment the modified version allows to have for the same module the stable version and the last published prerelease:
PnP.PowerShell:1.11.0,PnP.PowerShell::
with allow-prerelease to true.
To allow this and simplify the code I don't check for module name duplication in 'module-to-cache'.
With the values :
modules-to-cache: "safeguard-ps,PnP.PowerShell::"
allow-prerelease: "false"
updatable: "true"
With the values :
modules-to-cache: "safeguard-ps,PnP.PowerShell::"
allow-prerelease: "true"
updatable: "true"
'allow-prerelease' parameter is removed.
Now we have two behaviors for saving a module, with or without prerelease:
modules-to-cache:
description: "Name of PowerShell modules to cache from registered PsRepositories (PowerShell Gallery by default)"
required: false
modules-to-cache-prerelease:
description: "Name of prerelease PowerShell modules to cache from registered PsRepositories (PowerShell Gallery by default). Uses the -AllowPrerelease parameter during Save-Module."
required: false
Both parameters are declared optional in the Action but checked in the cmdlet, since one or the other or both can be used.
Example of usage related to the 'prefixidentifier' parameter:
$AllCaches=(gh api -H "Accept: application/vnd.github+json" /repos/PSLDA/psmodulecache/actions/caches|ConvertFrom-Json).actions_caches
Foreach ($Cache in $AllCaches)
{
#The 'prefixidentifier' parameter of the psmoduleCache Action must be 'true'
$WkfName=$Cache.key -replace '^(.*?)-.*$','$1'
Add-Member -InputObject $Cache -MemberType NoteProperty -Name WorkflowName -Value $wkfName
}
Then we can group the caches by workflow name:
$Caches=$AllCaches|Group-Object WorkflowName -AsHashTable
Here you will find another implementation which is built around a module instead of a script. This means that the code no longer has anything to do with the main.ps1 script. I commented on the intentions, even though it may seem unnecessary.
What is now taken into account:
The module code is very verbose, I used many simple functions, moreover the rules are coupled to the parsing of the parameters. I considered using PSRule (https://github.com/microsoft/PSRule) to avoid this, but haven't tested to make sure it's relevant. Finally the use of Powershell classes can perhaps simplify the code. The documentation remains to be done.
Let me know if this is okay with you.