Skip to content

Commit

Permalink
Merge pull request #30 from ShaunLawrie/prerelease
Browse files Browse the repository at this point in the history
Refactor for testability
  • Loading branch information
ShaunLawrie authored Feb 25, 2024
2 parents 114f661 + fad74ce commit 93384c6
Show file tree
Hide file tree
Showing 123 changed files with 4,606 additions and 440 deletions.
92 changes: 69 additions & 23 deletions .github/workflows/build-test-publish.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Publish to PSGallery
env:
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }}
on:
push:
branches:
- main
- prerelease
- main
- prerelease

permissions:
contents: write
Expand All @@ -14,56 +14,102 @@ jobs:
publish-to-psgallery:
name: Publish
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
if: github.ref == 'refs/heads/main' && github.repository_owner == 'ShaunLawrie'
steps:
- name: Check out repository code
uses: actions/checkout@v3
- 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" }
$newVersion = [version]::new($version.Major, $version.Minor + 1, 0)
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
$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'
if: github.ref == 'refs/heads/prerelease' && github.repository_owner == 'ShaunLawrie'
steps:
- name: Check out repository code
uses: actions/checkout@v3
- 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" }
$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
$onlineVersions = Find-Module -Name PwshSpectreConsole -AllowPrerelease -AllVersions
$latestStableVersion = $onlineVersions | Where-Object { $_.Version -notlike "*prerelease*" } | Sort-Object -Property Version -Descending | Select-Object -First 1 -ExpandProperty Version
$latestStableVersion = [version]$latestStableVersion
$latestPrereleaseVersion = $onlineVersions | Where-Object { $_.Version -like "*prerelease*" } | Sort-Object -Property 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]
# 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($latestStableVersion.Major, $latestStableVersion.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 = '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
- name: Upload Snapshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: Snapshots
path: PwshSpectreConsole.Tests/@snapshots/*.txt
1 change: 1 addition & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy
if: github.repository_owner == 'ShaunLawrie'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/unit-test-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Run Unit Tests
on:
push:

permissions:
contents: write

jobs:
unit-test:
name: Unit Test
runs-on: ubuntu-latest
if: github.repository_owner != 'ShaunLawrie' || !(github.ref == 'refs/heads/main' && github.ref == 'refs/heads/prerelease')
steps:
- name: Check out repository code
uses: actions/checkout@v4
- name: Unit Test
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
& .\PwshSpectreConsole\Build.ps1
$env:PSModulePath = @($env:PSModulePath, ".\PwshSpectreConsole\") -join ":"
$PSVersionTable | Out-Host
Get-Module Pester -ListAvailable | Out-Host
Invoke-Pester -CI -ExcludeTag "ExcludeCI"
- name: Upload Snapshots
if: failure()
uses: actions/upload-artifact@v4
with:
name: Snapshots
path: PwshSpectreConsole.Tests/@snapshots/*.txt
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pnpm-debug.log*

# Exclude packages folder
PwshSpectreConsole/packages
PwshSpectreConsole.Tests/packages

# Exclude working folder
Working/
8 changes: 4 additions & 4 deletions PwshSpectreConsole.Docs/UpdateDocs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if($null -eq $module) {

$module | Save-MarkdownHelp -OutputPath "$PSScriptRoot\src\content\docs\reference\" -IncludeYamlHeader -YamlHeaderInformationType Metadata -ExcludeFile "*.gif", "*.png"

$new = @("New-SpectreChartItem.md", "Get-SpectreDemoColors.md", "Get-SpectreDemoEmoji.md")
$new = @("New-SpectreChartItem.md", "Get-SpectreDemoColors.md", "Get-SpectreDemoEmoji.md", "Format-SpectreJson.md")
$experimental = @("Get-SpectreImageExperimental.md", "Invoke-SpectreScriptBlockQuietly.md")

$newTag = @"
Expand Down Expand Up @@ -46,7 +46,7 @@ $groups = @(

$docs = Get-ChildItem "$PSScriptRoot\src\content\docs\reference\" -Filter "*.md" -Recurse
foreach($doc in $docs) {
if($remove -contains $doc.Name) {
if($remove -contains $doc.Name -or $doc.Name -notlike "*-*") {
Remove-Item $doc.FullName
continue
}
Expand All @@ -68,13 +68,13 @@ foreach($doc in $docs) {
New-Item -ItemType Directory -Path "$PSScriptRoot\src\content\docs\reference\$($group.Name)" -Force | Out-Null
$content = Get-Content $doc.FullName -Raw
Remove-Item $doc.FullName
$content = $content -replace '```PowerShell', '```powershell' -replace '(?m)^.+\n^[\-]{10,99}', ''
$content = $content -replace '```PowerShell', '```powershell' -replace '(?m)^.+\n^[\-]{10,99}', '' -replace "`r", ""
if($experimental -contains $doc.Name) {
$content = $content -replace '(?s)^---', "---`n$experimentalTag"
} elseif($new -contains $doc.Name) {
$content = $content -replace '(?s)^---', "---`n$newTag"
}
$content | Out-File $outLocation
$content | Out-File $outLocation -NoNewline
}

# Build the docs site
Expand Down
Binary file added PwshSpectreConsole.Docs/public/json.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PwshSpectreConsole.Docs/public/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@ title: Set-SpectreColors







### Synopsis
Sets the accent color and default value color for Spectre Console.



---


### Description

This function sets the accent color and default value color for Spectre Console. The accent color is used for highlighting important information, while the default value color is used for displaying default values.
Expand All @@ -19,8 +26,11 @@ An example of the accent color is the highlight used in `Read-SpectreSelection`:
An example of the default value color is the default value displayed in `Read-SpectreText`:
![Default value color example](/defaultcolor.png)



---


### Examples
Sets the accent color to Red and the default value color to Yellow.

Expand All @@ -33,27 +43,47 @@ Sets the accent color to Green and keeps the default value color as Grey.
Set-SpectreColors -AccentColor Green
```


---


### Parameters
#### **AccentColor**

The accent color to set. Must be a valid Spectre Console color name. Defaults to "Blue".






|Type |Required|Position|PipelineInput|
|----------|--------|--------|-------------|
|`[String]`|false |1 |false |



#### **DefaultValueColor**

The default value color to set. Must be a valid Spectre Console color name. Defaults to "Grey".






|Type |Required|Position|PipelineInput|
|----------|--------|--------|-------------|
|`[String]`|false |2 |false |





---


### Syntax
```powershell
Set-SpectreColors [[-AccentColor] <String>] [[-DefaultValueColor] <String>] [<CommonParameters>]
```

Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,41 @@ title: Get-SpectreDemoColors







### Synopsis
Retrieves a list of Spectre Console colors and displays them with their corresponding markup.
![Spectre color demo](/colors.png)



---


### Description

The Get-SpectreDemoColors function retrieves a list of Spectre Console colors and displays them with their corresponding markup.
It also provides information on how to use the colors as parameters for commands or in Spectre Console markup.



---


### Examples
Displays a list of Spectre Console colors and their corresponding markup.

```powershell
PS> Get-SpectreDemoColors
```


---


### Syntax
```powershell
Get-SpectreDemoColors [<CommonParameters>]
```

Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,50 @@ title: Get-SpectreDemoEmoji







### Synopsis
Retrieves a collection of emojis available in Spectre Console.
![Example emojis](/emoji.png)



---


### Description

The Get-SpectreDemoEmoji function retrieves a collection of emojis available in Spectre Console. It displays the general emojis, faces, and provides information on how to use emojis in Spectre Console markup.



---


### Examples
Retrieves and displays the collection of emojis available in Spectre Console.

```powershell
Get-SpectreDemoEmoji
```


---


### Notes
Emoji support is dependent on the operating system, terminal, and font support. For more information on Spectre Console markup and emojis, refer to the following links:
- Spectre Console Markup: https://spectreconsole.net/markup
- Spectre Console Emojis: https://spectreconsole.net/appendix/emojis



---


### Syntax
```powershell
Get-SpectreDemoEmoji [<CommonParameters>]
```

Loading

0 comments on commit 93384c6

Please sign in to comment.