-
Notifications
You must be signed in to change notification settings - Fork 7
150 lines (137 loc) · 7.58 KB
/
build-test-publish.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
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
143
144
145
146
147
148
149
150
name: Publish to PSGallery
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
on:
push:
branches:
- main
- prerelease
permissions:
contents: write
jobs:
publish-to-psgallery:
name: Publish
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main' && github.repository_owner == 'ShaunLawrie'
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Version Bump
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = "Stop"
& .\PwshSpectreConsole\Build.ps1
$env:PSModulePath = @($env:PSModulePath, ".\PwshSpectreConsole\") -join ":"
Invoke-Pester -CI -ExcludeTag "ExcludeCI"
$version = Get-Module PwshSpectreConsole -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 -ExpandProperty Version
if($null -eq $version) { throw "Failed to load version" }
$onlineVersion = Find-Module -Name PwshSpectreConsole -RequiredVersion $version -ErrorAction SilentlyContinue
$newVersion = [version]::new($version.Major, $version.Minor, $version.Build)
if($null -eq $onlineVersion) {
Write-Warning "Online version doesn't exist, this version $newVersion will be published without a version bump"
} else {
$newVersion = [version]::new($version.Major, $version.Minor, $version.Build + 1)
Write-Host "Bumping version from $version to $newVersion"
Update-ModuleManifest -Path .\PwshSpectreConsole\PwshSpectreConsole.psd1 -ModuleVersion $newVersion
git config --global user.name 'Shaun Lawrie (via GitHub Actions)'
git config --global user.email '[email protected]'
git add PwshSpectreConsole/PwshSpectreConsole.psd1
git commit -m "[skip ci] Bump version to $newVersion"
git push
}
Import-Module .\PwshSpectreConsole\PwshSpectreConsole.psd1 -Force
Publish-Module -Name PwshSpectreConsole -Exclude "Build.ps1" -NugetApiKey $env:PSGALLERY_API_KEY
gh release create "v$newVersion" --target main --generate-notes
- name: Upload Snapshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: Snapshots
path: PwshSpectreConsole.Tests/@snapshots/*.txt
publish-prerelease-to-psgallery:
name: Publish Prerelease
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/prerelease' && github.repository_owner == 'ShaunLawrie'
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Version Bump and Publish
shell: pwsh
env:
GH_TOKEN: ${{ github.token }}
run: |
$ErrorActionPreference = "Stop"
& ./PwshSpectreConsole/Build.ps1
$env:PSModulePath = @($env:PSModulePath, ".\PwshSpectreConsole\") -join ":"
Invoke-Pester -CI -ExcludeTag "ExcludeCI"
$version = Get-Module PwshSpectreConsole -ListAvailable | Sort-Object -Property Version -Descending | Select-Object -First 1 -ExpandProperty Version
if($null -eq $version) { throw "Failed to load version" }
$onlineVersions = Find-Module -Name PwshSpectreConsole -AllowPrerelease -AllVersions
$latestStableVersion = $onlineVersions | Where-Object { $_.Version -notlike "*prerelease*" } | Sort-Object { [version]$_.Version } -Descending | Select-Object -First 1 -ExpandProperty Version
$latestStableVersion = [version]$latestStableVersion
$latestPrereleaseVersion = $onlineVersions | Where-Object { $_.Version -like "*prerelease*" } | Sort-Object {
$version = [version]$_.Version.Split("-")[0]
$version = [version]::new($version.Major, $version.Minor, $version.Build, ($_.Version.Split("-")[1] -replace "prerelease", ""))
return $version
} -Descending | Select-Object -First 1 -ExpandProperty Version
$latestPrereleaseTag = $latestPrereleaseVersion.Split("-prerelease")[1] # format is like -prerelease6, output here is just 6
$latestPrereleaseVersion = [version]$latestPrereleaseVersion.Split("-prerelease")[0]
# Jump to package version if it's been bumped beyond the latest prerelease version
$currentVersion = [version]::new($version.Major, $version.Minor, $version.Build)
if ($latestPrereleaseVersion -lt $currentVersion) {
Write-Host "Latest prerelease version is less than the latest stable version, jumping to $currentVersion"
$newPrereleaseTag = "prerelease1"
$newVersion = $currentVersion
} elseif ($latestPrereleaseVersion -eq $currentVersion) {
Write-Host "Latest prerelease version is the same as the latest stable version, jumping to $currentVersion"
$newPrereleaseTag = "prerelease" + (([int]$latestPrereleaseTag) + 1)
$newVersion = $currentVersion
} else {
# Generate a new prerelease name, psgallery only allows characters 'a-zA-Z0-9' and a hyphen ('-') at the beginning of the prerelease string
$newPrereleaseTag = "prerelease" + (([int]$latestPrereleaseTag) + 1)
# Prerelease will always be at least one minor version above the latest published stable version so when it's merged to main the minor version will get bumped
# To bump a major version the manifest would be edited manually to vnext.0.0 before merging to main
$newVersion = [version]::new($latestPrereleaseVersion.Major, $latestPrereleaseVersion.Minor + 1, 0)
}
if($newVersion -eq $oldVersion) {
Write-Host "Version is not being bumped in prerelease"
} else {
Write-Host "Bumping version from $version to $newVersion"
Update-ModuleManifest -Path .\PwshSpectreConsole\PwshSpectreConsole.psd1 -ModuleVersion $newVersion
git config --global user.name 'Shaun Lawrie (via GitHub Actions)'
git config --global user.email '[email protected]'
git add PwshSpectreConsole/PwshSpectreConsole.psd1
git commit -m "[skip ci] Bump version to $newVersion"
git push
}
# Mark as prerelease
Update-ModuleManifest -Path .\PwshSpectreConsole\PwshSpectreConsole.psd1 -PrivateData @{ Prerelease = "$newPrereleaseTag" }
# Publish pre-release version
Import-Module .\PwshSpectreConsole\PwshSpectreConsole.psd1 -Force
Publish-Module -Name PwshSpectreConsole -Exclude "Build.ps1" -NugetApiKey $env:PSGALLERY_API_KEY -AllowPrerelease
# Create a gh release for it
gh release create "v$newVersion-$newPrereleaseTag" --target prerelease --generate-notes --prerelease
# Publish prerelease docs
Install-Module HelpOut -Scope CurrentUser -RequiredVersion 0.5 -Force
& .\PwshSpectreConsole.Docs\src\powershell\UpdateDocs.ps1 -NonInteractive -Branch "prerelease"
# Push any docs changes
git push
- name: Deploy
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CF_API_TOKEN }}
accountId: ${{ secrets.CF_ACCOUNT_ID }}
workingDirectory: "./PwshSpectreConsole.Docs/dist"
command: pages deploy . --project-name pwshspectreconsole --commit-dirty=true --branch=prerelease
- name: Upload Snapshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: Snapshots
path: PwshSpectreConsole.Tests/@snapshots/*.txt