Skip to content

Commit

Permalink
Adding Release assets feature + fix BuiltModuleSubdirectory (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaelcolas authored Jul 2, 2021
1 parent fd5cf1e commit d314a29
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
70 changes: 27 additions & 43 deletions .build/tasks/New-Release.GitHub.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -53,58 +53,17 @@ 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'"

$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")
Expand Down Expand Up @@ -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
}
Expand All @@ -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'"

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
4 changes: 3 additions & 1 deletion build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d314a29

Please sign in to comment.