potatoqualitee / psmodulecache

This action makes caching PowerShell modules from the PowerShell Gallery easy for Linux, Windows and macOS runners.
MIT License
31 stars 12 forks source link

PsModuleCache Vnext #29

Closed LaurentDardenne closed 2 years ago

LaurentDardenne commented 2 years ago

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.

LaurentDardenne commented 2 years ago
Use actions/cache@v3.0.6 **v3.0.6 Latest Marketplace** Add example for clojure lein project dependencies by @shivamarora1 in PR #835 Update toolkit's cache npm module to latest. Bump cache version to v3.0.6 by @pdotl in PR #887 Fix issue #809 where cache save/restore was failing for Amazon Linux 2 runners due to older tar version Fix issue #833 where cache save was not working for caching github workspace directory **v3.0.5** Removed error handling by consuming actions/cache 3.0 toolkit, Now cache server error handling will be done by toolkit. **v3.0.4** In this release, we have fixed the tar creation error while trying to create it with path as ~/ home folder on ubuntu-latest. **v3.0.3** Fixed avoiding empty cache save when no files are available for caching. (#624) **v3.0.2** This release adds the support for dynamic cache size cap on GHES. **v3.0.1** Added support for caching from GHES 3.5. Fixed download issue for files > 2GB during restore. **v2.1.4** Make caching more verbose #650 Use GNU tar on macOS if available #701 **v2.1.7** Support 10GB cache upload using the latest version 1.0.8 of @actions/cache **v2.1.6** Catch unhandled "bad file descriptor" errors that sometimes occurs when the cache server returns non-successful response (#596) **v2.1.5** Fix permissions error seen when extracting caches with GNU tar that were previously created using BSD tar (#527) **v2.1.3** Upgrades @actions/core to v1.2.6 for CVE-2020-15228. This action was not using the affected methods. Fix error handling in uploadChunk where 400-level errors were not being detected and handled correctly **v2.1.2** Adds input to limit the chunk upload size, useful for self-hosted runners with slower upload speeds No-op when executing on GHES **v2.1.1** Update @actions/cache package to v1.0.2 which allows cache action to use posix format when taring files. **v2.1.0** Replaces the http-client with the Azure Storage SDK for NodeJS when downloading cache content from Azure. This should help improve download performance and reliability as the SDK downloads files in 4 MB chunks, which can be parallelized and retried independently Display download progress and speed
LaurentDardenne commented 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"

image

With the values :

 modules-to-cache: "safeguard-ps,PnP.PowerShell::"
 allow-prerelease: "true"
 updatable: "true"

image

LaurentDardenne commented 2 years ago

'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
LaurentDardenne commented 2 years ago

FYI : Runner 'macos-latest' allow Powershell for the shell parameter