Skip to content

Commit

Permalink
refactor: use submodules (#11) +semver: minor
Browse files Browse the repository at this point in the history
* refactor: rename step function

* refactor: turn step function into submodule

* feat: add bump type function

* ci(renovate): pin digest and recommended

* ci: move tests launcher to build

* ci: pwsh continuous deployment

* ci: remove codacy

* ci: increase coverage target

* ci: don't run tests twice

* docs: fix renamed and added commands

* refactor: rename repository

* refactor: rename powershell module
  • Loading branch information
ArwynFr committed Oct 2, 2024
1 parent 77fbc90 commit a1fd9b0
Show file tree
Hide file tree
Showing 20 changed files with 338 additions and 205 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
root = true

[*]
indent_style = space

[*.{ps1,psd1,psm1}]
indent_size = 2
80 changes: 44 additions & 36 deletions .github/README.adoc
Original file line number Diff line number Diff line change
@@ -1,36 +1,44 @@
= StepSemVer

StepSemVer is a pwsh module used to increment semantic versions number.

https://www.powershellgallery.com/packages/StepSemVer[image:https://img.shields.io/powershellgallery/v/StepSemVer?style=for-the-badge[PowerShell Gallery]] https://www.powershellgallery.com/packages/StepSemVer[image:https://img.shields.io/powershellgallery/dt/StepSemVer?style=for-the-badge[PowerShell Gallery]]

== Rules and standards

The following documents provide additional information on rules and standards applying to this project :

- link:/LICENSE[MIT License]

== How to use the module

This module contains a single command :

=== Step-SemVer

Returns a semantic version that increments an existing value.

```Powershell
Step-SemVer
[[-Version] <semver>]
[-BumpType] {major | minor | patch}
[[-PreRelease] <string>]
[[-Build] <string>]
[<CommonParameters>]
```

`-Version`:: *Required* and *Pipelinable*. Current version from which to do the increment.

`-BumpType`:: *Required*. Must be one of `major`, `minor`, or `patch`. The new version number is incremented based on this value.

`-PreRelease`:: *Optional*. If specified, sets the pre-release value of the new version.

`-Build`:: *Optional*. If specified, sets the build value of the new version.
= ArwynFr.SemanticVersion

A powershell module used to increment semantic version numbers.

https://www.powershellgallery.com/packages/ArwynFr.SemanticVersion[image:https://img.shields.io/powershellgallery/v/ArwynFr.SemanticVersion?style=for-the-badge[PowerShell Gallery]] https://www.powershellgallery.com/packages/ArwynFr.SemanticVersion[image:https://img.shields.io/powershellgallery/dt/ArwynFr.SemanticVersion?style=for-the-badge[PowerShell Gallery]] link:/LICENSE[image:https://img.shields.io/github/license/ArwynFr/pwsh-SemanticVersion?style=for-the-badge[GitHub License]]

You can download and install this powershell module from PSGallery:

```Powershell
Install-Module ArwynFr.SemanticVersion
```

== ConvertTo-SemanticVersionBump

This function returns `major`, `minor` or `patch` depending on the presence of a `+semver: major` or `+semver: minor` tag in the commit message. It is intended to be used with `Step-SemanticVersion`.

```Powershell
ConvertTo-SemanticVersionBump
[[-CommitMessage] <string>]
[<CommonParameters>]
```

`-CommitMessage`:: *Required* and *Pipelinable*. A commit message string that the command will use as an input.

== Step-SemanticVersion

Returns an incremented semantic version number.

```Powershell
Step-SemanticVersion
[[-Version] <semver>]
[-BumpType] {major | minor | patch}
[[-PreRelease] <string>]
[[-Build] <string>]
[<CommonParameters>]
```

`-Version`:: *Required* and *Pipelinable*. Current version from which to do the increment.

`-BumpType`:: *Required*. Must be one of `major`, `minor`, or `patch`. The new version number is incremented based on this value.

`-PreRelease`:: *Optional*. If specified, sets the pre-release value of the new version.

`-Build`:: *Optional*. If specified, sets the build value of the new version.
8 changes: 8 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended",
"docker:pinDigests",
":disableDependencyDashboard"
]
}
35 changes: 20 additions & 15 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
name: continuous deployment

on:
workflow_dispatch:
push:
branches: [main]

jobs:
deployment:
uses: ArwynFr/ArwynFr/.github/workflows/pwsh-deployment.yaml@main
with:
manifest: ./StepSemVer/StepSemVer.psd1
source: ./StepSemVer/
secrets:
PSGALLERY_APIKEY: ${{ secrets.PSGALLERY_APIKEY }}
name: deployment

on:
workflow_dispatch:
push:
branches: [main]

jobs:
deployment:
runs-on: ubuntu-latest
steps:
- name: Checkout source files
uses: actions/checkout@v4

- name: Run continuous deployment
shell: pwsh
run: ./build/Start-Deployment.ps1 -Verbose
env:
PSGALLERY_APIKEY: ${{ secrets.PSGALLERY_APIKEY }}
GH_TOKEN: ${{ github.token }}
33 changes: 17 additions & 16 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
name: continuous integration

on:
workflow_dispatch:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
integration:
uses: ArwynFr/ArwynFr/.github/workflows/pwsh-integration.yaml@main
with:
tests: ./tests/Start-Tests.ps1
secrets:
CODACY_PROJECT_TOKEN: ${{ secrets.CODACY_PROJECT_TOKEN }}
name: integration

on:
workflow_dispatch:
pull_request:
branches: [main]

jobs:
integration:
runs-on: ubuntu-latest
steps:
- name: Checkout source files
uses: actions/checkout@v4

- name: Run tests
shell: pwsh
run: ./build/Start-Tests.ps1 -Verbose
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
25 changes: 25 additions & 0 deletions ArwynFr.SemanticVersion/ArwynFr.SemanticVersion.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@{
Author = 'ArwynFr'
CompanyName = 'www.arwyn.fr'
Copyright = '(c) 2019-2023 - ArwynFr - MIT license'

ModuleVersion = '0.1.0'
GUID = 'b4209e98-7072-45f3-bb89-ce520a182558'
Description = 'A powershell module used to increment semantic version numbers'
HelpInfoURI = 'https://github.com/ArwynFr/pwsh-SemanticVersion#readme'

PrivateData = @{
ProjectUri = 'https://github.com/ArwynFr/pwsh-SemanticVersion'
LicenseUri = 'https://github.com/ArwynFr/pwsh-SemanticVersion/blob/main/LICENSE'
}

NestedModules = @(
'ConvertTo-SemanticVersionStep/ConvertTo-SemanticVersionStep.psd1'
'Step-SemanticVersion/Step-SemanticVersion.psd1'
)

FunctionsToExport = @(
'ConvertTo-SemanticVersionStep'
'Step-SemanticVersion'
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
ModuleVersion = '0.1.0'
RootModule = 'ConvertTo-SemanticVersionStep.psm1'
FunctionsToExport = @( 'ConvertTo-SemanticVersionStep' )
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function ConvertTo-SemanticVersionStep {
[CmdletBinding()]
[OutputType([string])]
param (
[Parameter(Mandatory, ValueFromPipeline)]
[string]
$CommitMessage
)

Process {
switch -Wildcard ($CommitMessage) {
'*+semver: major*' { 'major' }
'*+semver: minor*' { 'minor' }
Default { 'patch' }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@{
ModuleVersion = '0.1.0'
RootModule = 'Step-SemanticVersion.psm1'
FunctionsToExport = @( 'Step-SemanticVersion' )
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
function Step-SemVer {
[CmdletBinding()]
[OutputType([semver])]
param (
[Parameter(ValueFromPipeline)]
[semver]
$Version,

[Parameter(Mandatory)]
[ValidateSet('major', 'minor', 'patch')]
[string]
$BumpType,

[Parameter()]
[string]
$PreRelease = '',

[Parameter()]
[string]
$Build = ''
)

Process {

if ('major' -eq $BumpType) {
return [semver]::new($Version.Major + 1, 0, 0, $PreRelease, $Build)
}

if ('minor' -eq $BumpType) {
return [semver]::new($Version.Major, $Version.Minor + 1, 0, $PreRelease, $Build)
}

return [semver]::new($Version.Major, $Version.Minor, $Version.Patch + 1, $PreRelease, $Build)
}
function Step-SemanticVersion {
[CmdletBinding()]
[OutputType([semver])]
param (
[Parameter(ValueFromPipeline)]
[semver]
$Version,

[Parameter(Mandatory)]
[ValidateSet('major', 'minor', 'patch')]
[string]
$BumpType,

[Parameter()]
[string]
$PreRelease = '',

[Parameter()]
[string]
$Build = ''
)

Process {

if ('major' -eq $BumpType) {
return [semver]::new($Version.Major + 1, 0, 0, $PreRelease, $Build)
}

if ('minor' -eq $BumpType) {
return [semver]::new($Version.Major, $Version.Minor + 1, 0, $PreRelease, $Build)
}

return [semver]::new($Version.Major, $Version.Minor, $Version.Patch + 1, $PreRelease, $Build)
}
}
42 changes: 21 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
MIT License

Copyright (c) 2019 Arwyn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2019 ArwynFr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
20 changes: 0 additions & 20 deletions StepSemVer/StepSemVer.psd1

This file was deleted.

29 changes: 29 additions & 0 deletions build/Start-Deployment.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[CmdletBinding(SupportsShouldProcess)]
param ()


$RootPath = Join-Path $PSScriptRoot .. | Convert-Path
$ModulePath = Join-Path $RootPath ArwynFr.SemanticVersion

Import-Module $ModulePath -Force
$CurrentVersion = (gh release view --json tagName | ConvertFrom-Json).tagName
$CommitMessage = [string] (git log -1 --pretty=%B)
$Increment = $CommitMessage | ConvertTo-SemanticVersionStep
$TargetVersion = $CurrentVersion | Step-SemanticVersion -BumpType $Increment -PreRelease $PreRelease

"Increment = $Increment" | Write-Verbose
"CurrentVersion = $CurrentVersion" | Write-Verbose
"TargetVersion = $TargetVersion" | Write-Verbose

Get-ChildItem $ModulePath -Recurse -Filter *.psd1 | ForEach-Object {
Update-ModuleManifest -ModuleVersion $TargetVersion -Path $_ -WhatIf:$WhatIfPreference
}

Publish-Module -Path $ModulePath -NuGetApiKey $env:PSGALLERY_APIKEY -WhatIf:$WhatIfPreference

if ($PSCmdlet.ShouldProcess($TargetVersion, 'gh release create')) {
gh release create $TargetVersion --generate-notes
git tag --force "v$($TargetVersion.Major).$($TargetVersion.Minor)"
git tag --force "v$($TargetVersion.Major)"
git push origin --tags --force
}
Loading

0 comments on commit a1fd9b0

Please sign in to comment.