Skip to content

Commit 27537fa

Browse files
committed
move UpdateNuspec.ps1 to action directory, bump version only if needed
1 parent 8addc70 commit 27537fa

3 files changed

Lines changed: 52 additions & 13 deletions

File tree

Scripts/UpdateNuspec.ps1 renamed to .github/actions/update-nuspec-file/UpdateNuspec.ps1

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ param (
44
[Parameter(Mandatory = $true)]
55
[string] $NuspecPath,
66
[string[]] $AdditionalFiles = @(),
7-
[string[]] $ExternalCsprojDependencies = @()
7+
[string[]] $ExternalCsprojDependencies = @(),
8+
[switch] $SkipVersionBump = $false
89
)
910

1011
if (!(Test-Path -Path $csprojPath)) {
@@ -288,18 +289,21 @@ $nuspecXml.package.AppendChild($filesNode) | Out-Null
288289

289290

290291
# Increment version
291-
$currentTargetFrameworks = @(([xml](Get-Content $NuspecPath)).package.metadata.dependencies.group.targetFramework)
292-
$hasTargetFrameworksChanged = [Bool](Compare-Object -ReferenceObject $rootTargetFrameworks -DifferenceObject $currentTargetFrameworks)
293-
294-
$currentVersion = $nuspecXml.package.metadata.version
295-
$versionSplitted = $currentVersion -split '\.'
296-
if ($hasTargetFrameworksChanged) {
297-
$versionSplitted[1] = ([int]$versionSplitted[1]) + 1
298-
$versionSplitted[2] = 0
299-
} else {
300-
$versionSplitted[2] = ([int]$versionSplitted[2]) + 1
292+
if (-not $SkipVersionBump) {
293+
$currentTargetFrameworks = @(([xml](Get-Content $NuspecPath)).package.metadata.dependencies.group.targetFramework)
294+
$hasTargetFrameworksChanged = [Bool](Compare-Object -ReferenceObject $rootTargetFrameworks -DifferenceObject $currentTargetFrameworks)
295+
296+
$currentVersion = $nuspecXml.package.metadata.version
297+
$versionSplitted = $currentVersion -split '\.'
298+
if ($hasTargetFrameworksChanged) {
299+
$versionSplitted[1] = ([int]$versionSplitted[1]) + 1
300+
$versionSplitted[2] = 0
301+
} else {
302+
$versionSplitted[2] = ([int]$versionSplitted[2]) + 1
303+
}
304+
$nuspecXml.package.metadata.version = $versionSplitted -join '.'
301305
}
302-
$nuspecXml.package.metadata.version = $versionSplitted -join '.'
306+
303307

304308
# Update commit hash
305309
$commitAttr = $nuspecXml.CreateAttribute('commit')

.github/actions/update-nuspec-file/action.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
additional-files:
1414
required: false
1515
description: "Allowed values: string[]"
16+
is-version-bump-enabled:
17+
required: false
18+
description: "Allowed values: true | false"
1619
runs:
1720
using: "composite"
1821
steps:
@@ -62,7 +65,12 @@ runs:
6265
additional_files_param="-AdditionalFiles $additional_files_paths"
6366
fi
6467
65-
cmd="pwsh -Command ./Scripts/UpdateNuspec.ps1 -CsprojPath './${{ inputs.project }}/${{ inputs.project }}.csproj' -NuspecPath './${{ inputs.project }}/${{ inputs.project }}.nuspec' $external_dependencies_param $additional_files_param"
68+
skip_version_bump_param=""
69+
if [ "${{ inputs.is-version-bump-enabled }}" != "true" ]; then
70+
skip_version_bump_param="-SkipVersionBump"
71+
fi
72+
73+
cmd="pwsh -Command ./.github\actions\update-nuspec-file\UpdateNuspec.ps1 -CsprojPath './${{ inputs.project }}/${{ inputs.project }}.csproj' -NuspecPath './${{ inputs.project }}/${{ inputs.project }}.nuspec' $external_dependencies_param $additional_files_param $skip_version_bump_param"
6674
echo $cmd
6775
eval "$cmd"
6876
echo "Finished"

.github/workflows/update-nuspec.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,19 @@ jobs:
130130
with:
131131
branch: ${{ steps.set-branch-name.outputs.value }}
132132
hard-reset: true
133+
- name: IsVersionBumpEnabled
134+
id: is-version-bump-enabled
135+
shell: pwsh
136+
run: |
137+
$lastVersionTag = (git tag -l "EncryptedConfigValue.Module/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
138+
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.Module\EncryptedConfigValue.Module.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
139+
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
140+
"value=$($newestVersion -ne $nuspecVersion)" >> $env:GITHUB_OUTPUT
133141
- uses: ./.github/actions/update-nuspec-file
134142
with:
135143
GITHUB_TOKEN: ${{ secrets.PAT }}
136144
project: ${{ steps.set-project-name.outputs.value }}
145+
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
137146
external-dependencies-sources: |
138147
EncryptedConfigValue
139148
additional-files: |
@@ -177,10 +186,19 @@ jobs:
177186
with:
178187
branch: ${{ steps.set-branch-name.outputs.value }}
179188
hard-reset: true
189+
- name: IsVersionBumpEnabled
190+
id: is-version-bump-enabled
191+
shell: pwsh
192+
run: |
193+
$lastVersionTag = (git tag -l "EncryptedConfigValue.AspNetCore/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
194+
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.AspNetCore\EncryptedConfigValue.AspNetCore.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
195+
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
196+
"value=$($newestVersion -ne $nuspecVersion)" >> $env:GITHUB_OUTPUT
180197
- uses: ./.github/actions/update-nuspec-file
181198
with:
182199
GITHUB_TOKEN: ${{ secrets.PAT }}
183200
project: ${{ steps.set-project-name.outputs.value }}
201+
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
184202
additional-files: |
185203
./Readme.md
186204
- uses: ./.github/actions/commit-changes
@@ -222,10 +240,19 @@ jobs:
222240
with:
223241
branch: ${{ steps.set-branch-name.outputs.value }}
224242
hard-reset: true
243+
- name: IsVersionBumpEnabled
244+
id: is-version-bump-enabled
245+
shell: pwsh
246+
run: |
247+
$lastVersionTag = (git tag -l "EncryptedConfigValue.Cli/*" | Sort-Object { [version]($_ -split '/' | Select-Object -Last 1) } | Select-Object -Last 1) -split '/' | Select-Object -Last 1
248+
$nuspecVersion = (Select-String -Path .\EncryptedConfigValue.Cli\EncryptedConfigValue.Cli.nuspec -Pattern '<version>(.*?)</version>' | ForEach-Object { $_.Matches.Groups[1].Value })
249+
$newestVersion = @($lastVersionTag, $nuspecVersion) | Sort-Object { [version]($_ -replace "net", "") } -Descending | Select-Object -First 1
250+
"value=$($newestVersion -ne $nuspecVersion)" >> $env:GITHUB_OUTPUT
225251
- uses: ./.github/actions/update-nuspec-file
226252
with:
227253
GITHUB_TOKEN: ${{ secrets.PAT }}
228254
project: ${{ steps.set-project-name.outputs.value }}
255+
is-version-bump-enabled: ${{ steps.is-version-bump-enabled.outputs.value }}
229256
external-dependencies-sources: |
230257
EncryptedConfigValue
231258
additional-files: |

0 commit comments

Comments
 (0)