-
Notifications
You must be signed in to change notification settings - Fork 4
98 lines (96 loc) · 3.68 KB
/
Deploy.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
name: Deploy
on:
push:
branches: [ main ]
workflow_dispatch:
defaults:
run:
shell: pwsh
jobs:
Deploy:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Discover Changes
run: |
$changedModules = $(git diff --name-only HEAD HEAD~)
$changedModules
$files = $changedModules -split ' ' | ForEach-Object{[System.IO.FileInfo] $_}
$modules = @()
foreach ($file in $files)
{
if((Test-Path $file.FullName)){
$fileDirectoryParent = $file.Directory.Parent
if ($fileDirectoryParent -and $fileDirectoryParent.Name -eq "Modules") {
$modules += $file.Directory
}
}
}
$modules.Length
if($modules.Length -eq 0){
exit
}
$changedModulesPath = mkdir -Name "StagingChangedModules\" -Force
For ($i=0; $i -lt $modules.Length; $i++)
{
$module = $modules[$i]
Copy-Item -Path $module.FullName -Destination $changedModulesPath -Recurse -Force
}
- name: Update Changed Modules
run: |
if(!(Test-Path StagingChangedModules)) {
Write-Host "No modules changed"
exit
}
$moduleFolders = Get-ChildItem StagingChangedModules
foreach ($item in $moduleFolders){
$moduleName = $item.Name
$manifest = Get-ChildItem $item.PSPath | Where-Object{$_.Name -like "*psd1"}
if(!$manifest){
Write-Error "The manifest for $moduleName was not found"
}
$content = Get-Content $manifest.PSPath | ForEach-Object{
$_
if ($_ -match "ModuleVersion"){
$version = [System.Version]($_ -split "'")[1]
}
}
$major = 0
$minor = 0
$build = 0
$minorRev = 1
if($version.Major -gt 0){$major = $version.Major}
if($version.Minor -gt 0){$minor = $version.Minor}
if($version.Build -gt 0){$build = $version.Build}
if($version.MinorRevision -gt 0){$minorRev = $version.MinorRevision + 1}
$updatedVersion = New-Object -TypeName system.Version -ArgumentList $major, $minor, $build, $minorRev
$PushPath = ".\Modules\" +($manifest.PSChildName).Substring(0, $manifest.PSChildName.length - 5 ) + "\"+ ($manifest.PSChildName)
$PublishPath = ".\StagingChangedModules\" +($manifest.PSChildName).Substring(0, $manifest.PSChildName.length - 5 ) + "\"+ ($manifest.PSChildName)
Update-ModuleManifest -Path $PushPath -ModuleVersion $updatedVersion
Update-ModuleManifest -Path $PublishPath -ModuleVersion $updatedVersion
Write-Host "$moduleName's version was updated from $version to $updatedVersion"
}
- name: Push Changes
run: |
if(!(Test-Path StagingChangedModules)) {
Write-Host "No modules changed"
exit
}
git config --global user.email "[email protected]"
git config --global user.name "worseTyler"
git add Modules/\*.psd1
git commit -m "[skip ci] Commit from build agent"
git push
- name: Publish To Gallery
run: |
if(!(Test-Path StagingChangedModules)) {
Write-Host "No modules changed"
Write-Host "Nothing to Publish"
exit
}
$moduleFolders = Get-ChildItem StagingChangedModules
foreach ($item in $moduleFolders){
Publish-Module -Path $item.FullName -NuGetApiKey ${{ secrets.POWERSHELL_GALLERY_API_KEY }} -Verbose
}