-
Notifications
You must be signed in to change notification settings - Fork 5
55 lines (46 loc) · 2.56 KB
/
check-zipped-module-version.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: CheckZippedModuleVersions
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Check Zipped Module Versions Against Source
run: |
$moduleVersionRegex = [regex]"(?:ModuleVersion\s?=\s?')([\d\.]*)'"
$zippedModules = Get-ChildItem -path psmodules
$allManifestFiles = Get-ChildItem -path src -Filter *.psd1 -Recurse -File
ForEach ($zippedModule in $zippedModules) {
$zipFile = [System.IO.Compression.zipfile]::OpenRead($zippedModule.FullName)
$zippedManifests = $zipFile.Entries | Where-Object { $_.Name -like "*.psd1" }
Foreach ($zippedManifest in $zippedManifests) {
$stream = $zippedManifest.Open()
$streamReader = New-Object System.IO.StreamReader($stream)
$content = $streamReader.ReadToEnd()
If ($zippedModuleVersionMatches = $moduleVersionRegex.matches($content)) {
If ($zippedModuleVersionMatches.count -eq 1) {
$zippedModuleVersion = $zippedModuleVersionMatches[0].Groups[1].Value
$manifestFile = $allManifestFiles | Where-Object { $_.PSChildName -eq $zippedManifest.Name }
If ($manifestFile) {
$manifestContent = Get-Content $manifestFile.FullName
If ($manifestVersionMatches = $moduleVersionRegex.matches($manifestContent)) {
If ($manifestVersionMatches.count -eq 1) {
$manifestVersion = $manifestVersionMatches[0].Groups[1].Value
If ($manifestVersion -ne $zippedModuleVersion) {
Write-Host "Module version mismatch for $($zippedManifest.Name):" -ForegroundColor Red
Write-Host " Manifest version: $manifestVersion" -ForegroundColor Red
Write-Host " Zipped version: $zippedModuleVersion" -ForegroundColor Red
throw "Module zip '$($zippedManifest.Name)' mismatch!"
}
Write-Verbose "zip: $zippedModuleVersion src: $manifestVersion"
}
}
}
}
}
}
}