-
-
Notifications
You must be signed in to change notification settings - Fork 73
142 lines (123 loc) · 5.78 KB
/
update-module.yml
File metadata and controls
142 lines (123 loc) · 5.78 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
name: 'Update module version'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
on:
workflow_dispatch:
permissions:
contents: write
jobs:
update-module:
name: Update module version
runs-on: windows-latest
steps:
- uses: actions/checkout@v6
with:
ref: main
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install and cache PowerShell modules
id: psmodulecache
uses: potatoqualitee/psmodulecache@v6.2.1
with:
modules-to-cache: MarkdownPS
shell: powershell
# Update the version number in the module manifest
- name: Update module version number
id: update-version
shell: powershell
run: |
$ModulePath = "${{ github.workspace }}\Evergreen"
$ManifestPath = "${{ github.workspace }}\Evergreen\Evergreen.psd1"
# Importing the manifest to determine the version
$Manifest = Test-ModuleManifest -Path $ManifestPath
Write-Host "Old version is: $($Manifest.Version)"
[System.String]$NewVersion = New-Object -TypeName "System.Version" -ArgumentList ((Get-Date -Format "yyMM"), ($Manifest.Version.Minor + 3 ), 0)
Write-Host "New version is: $NewVersion"
# Update the manifest with the new version value and fix the weird string replace bug
$functionList = ((Get-ChildItem -Path (Join-Path -Path $ModulePath -ChildPath "Public")).BaseName)
Update-ModuleManifest -Path $ManifestPath -ModuleVersion $NewVersion -FunctionsToExport $functionList
(Get-Content -Path $ManifestPath) -replace 'PSGet_$module', $module | Set-Content -Path $ManifestPath
(Get-Content -Path $ManifestPath) -replace 'NewManifest', $module | Set-Content -Path $ManifestPath
(Get-Content -Path $ManifestPath) -replace 'FunctionsToExport = ','FunctionsToExport = @(' | Set-Content -Path $ManifestPath
(Get-Content -Path $ManifestPath) -replace "$($functionList[-1])'", "$($functionList[-1])')" | Set-Content -Path $ManifestPath -Force
echo "newversion=$NewVersion" >> $env:GITHUB_OUTPUT
# Update the change log with the new version number
- name: Update CHANGELOG.md
id: update-changelog
shell: powershell
run: |
$changeLog = "${{ github.workspace }}\changelog.md"
$replaceString = "^## VERSION$"
$content = Get-Content -Path $changeLog
if ($content -match $replaceString) {
$content -replace $replaceString, "## ${{steps.update-version.outputs.newversion}}" | Set-Content -Path $changeLog
}
else {
Write-Host "No match in $changeLog for '## VERSION'. Manual update of CHANGELOG required." -ForegroundColor Cyan
}
# Update the list of supported apps in APPS.md
- name: Update APPS.md
id: update-apps
shell: powershell
run: |
Import-Module -Name "$env:GITHUB_WORKSPACE\Evergreen" -Force
Update-Evergreen
Import-Module -Name MarkdownPS
$OutFile = [System.IO.Path]::Combine($env:GITHUB_WORKSPACE, "apps.md")
$markdown = New-MDHeader -Text "$((Find-EvergreenApp).Count) Supported applications" -Level 1
$markdown += "`n"
$line = "Evergreen supports the following applications:"
$markdown += $line
$markdown += "`n`n"
$markdown += Find-EvergreenApp | New-MDTable
$markdown | Out-File -FilePath $OutFile -NoNewline -Force -Encoding "Utf8"
# Import GPG key so that we can sign the commit
- name: Import GPG key
id: import_gpg
uses: crazy-max/ghaction-import-gpg@v7
with:
gpg_private_key: ${{ secrets.GPGKEY }}
passphrase: ${{ secrets.GPGPASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_config_global: true
git_tag_gpgsign: true
git_push_gpgsign: false
git_committer_name: ${{ secrets.COMMIT_NAME }}
git_committer_email: ${{ secrets.COMMIT_EMAIL }}
- name: Commit changes
id: commit
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: "Update module ${{steps.update-version.outputs.newversion}}"
commit_user_name: ${{ secrets.COMMIT_NAME }}
commit_user_email: ${{ secrets.COMMIT_EMAIL }}
- name: "Changes have been detected"
if: steps.commit.outputs.changes_detected == 'true'
run: echo "Changes committed."
- name: "No changes have been detected"
if: steps.commit.outputs.changes_detected == 'false'
run: echo "No changes detected."
- name: Create and Push Tag
if: steps.commit.outputs.changes_detected == 'true'
shell: pwsh
run: |
$Module = Test-ModuleManifest -Path "$env:GITHUB_WORKSPACE\Evergreen\Evergreen.psd1"
if ($null -ne $Module) {
$tagName = "v$($Module.Version.ToString())"
Write-Host "Creating tag: $tagName"
# Create annotated tag (no GPG signature needed)
git tag -a $tagName -m "Release version $($Module.Version.ToString())"
# Push the tag with verbose output
git push origin $tagName --verbose
if ($LASTEXITCODE -eq 0) {
Write-Host "Tag $tagName created and pushed successfully" -ForegroundColor Green
}
else {
Write-Host "Failed to push tag. Exit code: $LASTEXITCODE" -ForegroundColor Red
exit $LASTEXITCODE
}
}
else {
Write-Host "Failed to read module manifest" -ForegroundColor Red
exit 1
}