From d314a296e7a34703b6b692f7f9783616a5f5556a Mon Sep 17 00:00:00 2001 From: Gael Date: Fri, 2 Jul 2021 17:00:49 +0200 Subject: [PATCH] Adding Release assets feature + fix BuiltModuleSubdirectory (#16) --- .build/tasks/New-Release.GitHub.build.ps1 | 70 +++++++++-------------- CHANGELOG.md | 2 + build.yaml | 4 +- 3 files changed, 32 insertions(+), 44 deletions(-) diff --git a/.build/tasks/New-Release.GitHub.build.ps1 b/.build/tasks/New-Release.GitHub.build.ps1 index ab09a22..5c7f8ae 100644 --- a/.build/tasks/New-Release.GitHub.build.ps1 +++ b/.build/tasks/New-Release.GitHub.build.ps1 @@ -53,38 +53,9 @@ param ( ) task Publish_release_to_GitHub -if ($GitHubToken -and (Get-Module -Name PowerShellForGitHub -ListAvailable)) { - $OutputDirectory = Get-SamplerAbsolutePath -Path $OutputDirectory -RelativeTo $BuildRoot - "`tOutputDirectory = '$OutputDirectory'" - $BuiltModuleSubdirectory = Get-SamplerAbsolutePath -Path $BuiltModuleSubdirectory -RelativeTo $OutputDirectory - if ($VersionedOutputDirectory) - { - # VersionedOutputDirectory is not [bool]'' nor $false nor [bool]$null - # Assume true, wherever it was set - $VersionedOutputDirectory = $true - } - else - { - # VersionedOutputDirectory may be [bool]'' but we can't tell where it's - # coming from, so assume the build info (Build.yaml) is right - $VersionedOutputDirectory = $BuildInfo['VersionedOutputDirectory'] - } - - $GetBuiltModuleManifestParams = @{ - OutputDirectory = $OutputDirectory - BuiltModuleSubdirectory = $BuiltModuleSubDirectory - ModuleName = $ProjectName - VersionedOutputDirectory = $VersionedOutputDirectory - ErrorAction = 'Stop' - } - - $builtModuleManifest = Get-SamplerBuiltModuleManifest @GetBuiltModuleManifestParams - $builtModuleManifest = (Get-Item -Path $builtModuleManifest).FullName - "`tBuilt Module Manifest = '$builtModuleManifest'" + . Set-SamplerTaskVariable - $builtModuleBase = Get-SamplerBuiltModuleBase @GetBuiltModuleManifestParams - $builtModuleBase = (Get-Item -Path $builtModuleBase).FullName - "`tBuilt Module Base = '$builtModuleBase'" $ReleaseNotesPath = Get-SamplerAbsolutePath -Path $ReleaseNotesPath -RelativeTo $OutputDirectory "`tRelease Notes Path = '$ReleaseNotesPath'" @@ -92,19 +63,7 @@ task Publish_release_to_GitHub -if ($GitHubToken -and (Get-Module -Name PowerShe $ChangelogPath = Get-SamplerAbsolutePath -Path $ChangeLogPath -RelativeTo $ProjectPath "`Changelog Path = '$ChangeLogPath'" - $moduleVersion = Get-BuiltModuleVersion @GetBuiltModuleManifestParams - $moduleVersionObject = Split-ModuleVersion -ModuleVersion $moduleVersion - $moduleVersionFolder = $moduleVersionObject.Version - $preReleaseTag = $moduleVersionObject.PreReleaseString - - "`tModule Version = '$ModuleVersion'" - "`tModule Version Folder = '$moduleVersionFolder'" - "`tPre-release Tag = '$preReleaseTag'" - "`tProject Path = $ProjectPath" - "`tProject Name = $ProjectName" - "`tSource Path = $SourcePath" - "`tBuilt Module Base = $builtModuleBase" # find Module's nupkg $PackageToRelease = Get-ChildItem (Join-Path $OutputDirectory "$ProjectName.$moduleVersion.nupkg") @@ -177,13 +136,36 @@ task Publish_release_to_GitHub -if ($GitHubToken -and (Get-Module -Name PowerShe Write-Build DarkGray "Creating new GitHub release '$ReleaseTag ' at '$remoteURL'." $APIResponse = New-GitHubRelease @releaseParams - Write-Build Green "Release Created. Adding Asset..." + Write-Build Green "Release Created. Adding Assets..." if (Test-Path -Path $PackageToRelease) { $APIResponse | New-GitHubReleaseAsset -Path $PackageToRelease -AccessToken $GitHubToken Write-Build Green "Asset '$PackageToRelease' added." } + if ($ReleaseAssets = $BuildInfo.GitHubConfig.ReleaseAssets) + { + foreach ($assetToRelease in $ReleaseAssets) + { + $assetToRelease = $ExecutionContext.InvokeCommand.ExpandString($assetToRelease) + if (Test-Path -Path $assetToRelease -ErrorAction SilentlyContinue) + { + (Get-Item -Path $assetToRelease -ErrorAction 'SilentlyContinue').FullName | ForEach-Object -Process { + $APIResponse | New-GitHubReleaseAsset -Path $_ -AccessToken $GitHubToken + Write-Build Green " + Adding asset '$_' to the relase $ReleaseTag." + } + } + else + { + Write-Build Yellow " ! Asset '$_' not found." + } + } + } + else + { + Write-Build DarkGray 'No extra asset to add to release.' + } + Write-Build Green "Follow the link -> $($APIResponse.html_url)" Start-Sleep -Seconds 5 # Making a pause to make sure the tag will be available at next Git Pull } @@ -204,6 +186,8 @@ task Create_ChangeLog_GitHub_PR -if ($GitHubToken -and (Get-Module -Name PowerSh # # git fetch --force --tags --prune --progress --no-recurse-submodules origin # # git @('checkout', '--progress', '--force' (git @('rev-parse', "origin/$MainGitBranch"))) + . Set-SamplerTaskVariable + $ChangelogPath = Get-SamplerAbsolutePath -Path $ChangeLogPath -RelativeTo $ProjectPath "`Changelog Path = '$ChangeLogPath'" diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c0d4c5..0b21dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Created module with GitHub tasks from Sampler. +- Support to add assets to GitHub released by defining the `ReleaseAssets` key in `build.yml` GitHubConfig. - Added logo. - Added Get-GHOwnerRepoFromRemoteUrl function. @@ -25,3 +26,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - Fixed typo when adding debug output for GH task. +- Fixed using the `Set-SamplerTaskVariable` in GH tasks. diff --git a/build.yaml b/build.yaml index 0ce0661..2620f92 100644 --- a/build.yaml +++ b/build.yaml @@ -121,8 +121,10 @@ TaskHeader: | # GitHub Configuration # #################################################### GitHubConfig: + ReleaseAssets: + - 'output/CHANGELOG.md' GitHubFilesToAdd: - 'CHANGELOG.md' GitHubConfigUserName: gaelcolas - # GitHubConfigUserEmail: dsccommunity@outlook.com # from Pipeline variable + GitHubConfigUserEmail: psgallery@synedgy.com UpdateChangelogOnPrerelease: false