Skip to content

Commit

Permalink
Merge pull request #60 from LaurentDardenne/FixAcceptLicence
Browse files Browse the repository at this point in the history
Fix accept licence
  • Loading branch information
LaurentDardenne authored Feb 2, 2024
2 parents ed1190e + ebe0af2 commit 4f287b2
Show file tree
Hide file tree
Showing 13 changed files with 740 additions and 176 deletions.
73 changes: 3 additions & 70 deletions .github/workflows/MatrixCacheForIssue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,80 +71,13 @@ jobs:
id: psmodulecache
uses: ./
with:
modules-to-cache: InvokeBuild:5.10.4,PSModuleCache\Duplicate,Az:9.3.0
modules-to-cache-prerelease: "OnlyPrereleaseVersion::"
modules-to-cache: "PSModuleCache\\DependencyRequiresAcceptanceOfTheLicense::"
shell: pwsh
updatable: "true"

- name: Get required modules on Windows PowerShell
shell: pwsh
run: |
Import-Module 'Duplicate'
Write-Host "Duplicate '$(Get-Module Duplicate | Select-Object Name, Version, RepositorySourceLocation)'"
Import-Module 'AZ'
Write-Host "AZ '$(Get-Module AZ | Select-Object Name, Version, RepositorySourceLocation)'"
# test-posh:
# runs-on: windows-latest
# steps:
# - uses: actions/checkout@v4.1.0
# - name: Run Pester tests (PowerShell)
# run: |

# $global:iswindows = $true
# $CloudsmithRepositoryName = 'psmodulecache'
# $CloudsmithUriLocation = 'https://nuget.cloudsmith.io/psmodulecache/test/v2/'

# #$CloudsmithPrivateUriLocation = 'https://nuget.cloudsmith.io/psmodulecache/privatepsmodulecache/v2/'

# $RemoteRepositories = @(
# [PsCustomObject]@{
# name = 'OttoMatt'
# publishlocation = 'https://www.myget.org/F/ottomatt/api/v2/package'
# sourcelocation = 'https://www.myget.org/F/ottomatt/api/v2'
# },

# [PsCustomObject]@{
# name = $CloudsmithRepositoryName
# publishlocation = $CloudsmithUriLocation
# sourcelocation = $CloudsmithUriLocation
# }
# )

# Try {
# Get-PackageSource PSModuleCache -ErrorAction Stop >$null
# } catch {
# if ($_.CategoryInfo.Category -ne 'ObjectNotFound') {
# throw $_
# } else {
# Register-PackageSource -Name $CloudsmithRepositoryName -Location $CloudsmithUriLocation -Trusted -ProviderName NuGet > $null
# }
# }

# #Register additionnal repositories with credential
# # Register-PackageSource -Name $CloudsmithPrivateRepositoryName -Location $CloudsmithPrivateUriLocation -Trusted -Credential $credential -ProviderName NuGet > $null

# foreach ($Repository in $RemoteRepositories) {
# $Name = $Repository.Name
# try {
# Get-PSRepository $Name -ErrorAction Stop >$null
# } catch {
# if ($_.CategoryInfo.Category -ne 'ObjectNotFound') {
# throw $_
# } else {
# $Parameters = @{
# Name = $Name
# SourceLocation = $Repository.SourceLocation
# PublishLocation = $Repository.PublishLocation
# InstallationPolicy = 'Trusted'
# }
# Write-Output "Register repository '$($Repository.Name)'"
# # An invalid Web Uri is managed by Register-PSRepository
# Register-PSRepository @Parameters > $null
# }
# }
# }
# find-Module 'Duplicate' -IncludeDependencies |Select Name,Version,Repository
# shell: powershell
Import-Module 'modulerequirelicenseacceptance'
Write-Host "modulerequirelicenseacceptance '$(Get-Module modulerequirelicenseacceptance | Select-Object Name, Version, RepositorySourceLocation)'"
2 changes: 1 addition & 1 deletion .github/workflows/Pester.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Pester
on: [push, pull_request]
on: [push, pull_request,workflow_dispatch]

jobs:
test-pwsh:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Release Notes

### v6.1

* Fix (#59). Modules requesting acceptance of a license triggered an exception. Now licenses are always accepted.

### v6.0

* Add support for the modules dependencies. Module paths to be saved in cache are unique.
Expand Down
2 changes: 1 addition & 1 deletion PSModuleCache.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

RootModule = 'PSModuleCache'

ModuleVersion = '2.0'
ModuleVersion = '2.1'

CompatiblePSEditions = @()

Expand Down
4 changes: 2 additions & 2 deletions PSModuleCache.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Enum CacheType{

Import-LocalizedData -BindingVariable PSModuleCacheResources -FileName PSModuleCache.Resources.psd1 -ErrorAction Stop

New-Variable -Name ActionVersion -Option ReadOnly -Scope Script -Value '6.0'
New-Variable -Name ActionVersion -Option ReadOnly -Scope Script -Value '6.1'

New-Variable -Name Delimiter -Option ReadOnly -Scope Script -Value '-'

Expand Down Expand Up @@ -1092,7 +1092,7 @@ function Save-ModuleCache {
# If the version is different then Save-Module completes the contents of the directory with the new version.
Write-Debug "Save-Module -Path $ModulePath -name $($ModuleCacheInformation.Name) -version $($ModuleCacheInformation.Version) -allow $($ModuleCacheInformation.Allowprerelease) -repo $($ModuleCacheInformation.Repository)"

Save-Module @Parameters -Path $ModulePath -Force -ErrorAction Stop
Save-Module @Parameters -Path $ModulePath -ErrorAction Stop -AcceptLicense -Force

#Once the module and its dependencies are written to disk, we check the naming convention.
#Changing $WarningPreference in the caller's scope has no impact on this module's scope.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ It is possible to configure a cache with an automatic update, the module search
6. [Using powershell on Windows](#example6)
6. [Cache key construction method](#buildcachekey)
7. [Cache limits](#cachelimits)
8. [Known issues](#knownissues)
8. [Acceptance of a license](#acceptancelicense)
9. [Known issues](#knownissues)

## How to use it <a name="howto"></a>

Expand Down Expand Up @@ -484,6 +485,10 @@ This allows to find the caches associated with a workflow when using [GitHub Cli

A repository can have up to 5GB of caches. Once the 5GB limit is reached, older caches will be evicted based on when the cache was last accessed. Caches that are not accessed within the last week (7 days) will also be evicted.

## Acceptance of a license <a name="acceptancelicense"></a>

If a module requires acceptance of a license, it is automatically accepted.

## Known issues <a name="knownissues"></a>

* The following setting is allowed:
Expand Down
Binary file modified test/Dependencies/Dependencies.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4f287b2

Please sign in to comment.