Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The RealeseNote of module manifest are not update in build task #358

Closed
NicolasBn opened this issue Apr 12, 2022 · 9 comments · Fixed by #364
Closed

The RealeseNote of module manifest are not update in build task #358

NicolasBn opened this issue Apr 12, 2022 · 9 comments · Fixed by #364
Labels
bug The issue is a bug.

Comments

@NicolasBn
Copy link
Collaborator

NicolasBn commented Apr 12, 2022

Problem description

The task 'Create_changelog_release_output' doesn't update the module manifest in build process.

You can see the problem in the module build with 0.112.1+ version of Sampler.

https://synedgy.visualstudio.com/Sampler/_build/results?buildId=1468&view=logs&j=bce26a94-9049-50eb-6c1c-385ccbec51f9&t=512e4b73-7a3e-57af-0534-ae809c1351da&l=137

the error message : No valid manifest found for project '<moduleName>'. Cannot update the Release Notes.

The problem came from the -AsNewBuild parameter added to Set-SamplerTaskVariable dot sourcing in task.

. Set-SamplerTaskVariable -AsNewBuild

With this parameter, the $builtModuleManifest variable is not initiate.

Verbose logs

No valid manifest found for project 'Sampler'. Cannot update the Release Notes.

How to reproduce

Use 0.121.1+ version of Sampler in your pipeline

Expected behavior

Release Note are added in manifest.

Current behavior

ReleaseNote are empty.

Suggested solution

Moved the initialization of $builtModuleManifest outside of -AsNewBuild condition.

Operating system the target node is running

Windows 10

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      7.2.2
PSEdition                      Core
GitCommitId                    7.2.2
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module version used

0.112.3
@johlju johlju added bug The issue is a bug. help wanted The issue is up for grabs for anyone in the community. labels Apr 14, 2022
@DrIOSX
Copy link

DrIOSX commented Apr 25, 2022

I can confirm I'm experiencing this with the latest version of the sampler. I haven't found a good combination of previous modules in the requirements.psd1 allows it to work consistently.

Any guidance on how to get versioning to work? Workarounds?

Also, when using appveyor, I'm getting the following result:

ERROR: The term 'Get-SamplerAbsolutePath' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again..

@johlju
Copy link
Collaborator

johlju commented Apr 25, 2022

Someone needs to send in a PR to fix those, @NicolasBn had a suggestion how this can be fixed so it sounds like a simple change but haven’t looked into it myself.

Please open a new issue for the AppVeyor problem so we can track problems individually.

@johlju
Copy link
Collaborator

johlju commented Apr 28, 2022

This problem seems that -AsNewBuild was added to this row when support for Choco packages was introduced

# Get the vales for task variables, see https://github.com/gaelcolas/Sampler#task-variables.
# Adding -AsNewBuild otherwise the version is not resolved when not module manifest (i.e. Choco Package)
. Set-SamplerTaskVariable -AsNewBuild

-AsNewBuild was only meant to be used for the build module task and then all other tasks should get the module version number from the module manifest. AsNewBuild should never been added to the above line, but removing -AsNewBuild from the above line will break Choco packages since they do not have a module manifest.

We cannot just move the below initialization of $BuiltModuleManifest as suggested by @NicolasBn since Get-SamplerBuiltModuleManifest returns the expected module manifest path regardless if it exist or not, then the task Create_changelog_release_output will try to modify a non-existent module manifest, also breaking Choco packages.

$GetBuiltModuleManifestParams = @{
OutputDirectory = $OutputDirectory
BuiltModuleSubdirectory = $BuiltModuleSubDirectory
ModuleName = $ProjectName
VersionedOutputDirectory = $VersionedOutputDirectory
ErrorAction = 'Stop'
}
$BuiltModuleManifest = Get-SamplerBuiltModuleManifest @GetBuiltModuleManifestParams
if ($BuiltModuleManifest)
{
$BuiltModuleManifest = (Get-Item -Path $BuiltModuleManifest -ErrorAction 'SilentlyContinue').FullName
}

$BuiltModuleBase = Get-SamplerBuiltModuleBase @PSBoundParameters
Get-SamplerAbsolutePath -Path ('{0}.psd1' -f $ModuleName) -RelativeTo $BuiltModuleBase

We could workaround this move the above code, and change the Get-SamplerBuiltModuleManifest to return $null if the module manifest does not exist, to make sure the variable $BuiltModuleManifest is $null for Choco packages, and a valid path when it is a module package.

BUT, the best approach would be to remove AsNewBuild that introduced the bug, and evaluate if it is a choco package, change this:

if ($AsNewBuild.IsPresent)

to something like:

 if ($AsNewBuild.IsPresent -or $IsChocoPackage) 

This change would be best so that all tasks always get the module version from the module manifest for module packages, and those packages that do not have module manifest get the version the same way as the build does, e.g. GitVersion.

@NicolasBn
Copy link
Collaborator Author

NicolasBn commented May 2, 2022

Is $IsChocoPackage already assigned in Sampler?

If no, we need to found a way to implement it. Maybe in Build.yaml?

@johlju
Copy link
Collaborator

johlju commented May 2, 2022

There is a lot of parameters in the Choco task, I'm hoping we could detect one of those in the current session by adding one of these choco parameters to the release.module.build.ps1 and that will be our "IsChocoPackage". 🙂

[Parameter()]
[System.String]
$ChocolateyPackageSource = (property ChocolateyPackageSource 'Chocolatey'),
# Base directory of all output (default to 'output')
[Parameter()]
[string]
$OutputDirectory = (property OutputDirectory (Join-Path -Path $BuildRoot -ChildPath 'output')),
[Parameter()]
[string]
$RequiredModulesDirectory = (property RequiredModulesDirectory $(Join-Path -Path $OutputDirectory -ChildPath 'RequiredModules')),
[Parameter()]
[string]
# Sub-Folder (or absolute path) of the Chocolatey build output folder (relative to $OutputDirectory)
$ChocolateyBuildOutput = (property ChocolateyBuildOutput 'choco'),
[Parameter()]
[string[]]
# The Chocolatey Package IDs (name) to build. Can be * to build all of them.
$ChocolateyPackageId = (property ChocolateyPackageId '*'),
[Parameter()]
[string]
# Version for the package(s), leave empty if you prefer the version to be managed by GitVersion or Build.yaml.
# There is only one version for all packages of a repository, but maybe another task can replace the version in nuspec (i.e. AutoUpdate)
$ChocolateyPackageVersion = (property ChocolateyPackageVersion ''),
[Parameter()]
[string]
$ReleaseNotesPath = (property ReleaseNotesPath (Join-Path $OutputDirectory 'ReleaseNotes.md')),
[Parameter()]
[string]
$ChangelogPath = (property ChangelogPath 'CHANGELOG.md'),
[Parameter()]
[string]
$ChocoPushSource = (property ChocoPushSource ''),
[Parameter()]
[string]
$ChocoPushSourceApiKey = (property ChocoPushSourceApiKey ''),
[Parameter()]
[string]
$SkipChocoPush = (property SkipChocoPush ''),

For example if we would to add the following parameter to release.module.build.ps1:

$ChocolateyPackageId = (property ChocolateyPackageId '')

Then it should give use either a package id or * in $ChocolateyPackageId, so then instead of this

if ($AsNewBuild.IsPresent)

We should be able to do this:

$isChocoPackage = -not ([string]::IsNullOrEmpty($ChocolateyPackageId))

if ($AsNewBuild.IsPresent -or $isChocoPackage) 

@johlju
Copy link
Collaborator

johlju commented May 2, 2022

But we should really test this out on a actual choco repository so we don't break anything again trying to fix this issue 🙂
My hope is that someone have such repo laying around in the public so we can test this. 🙂

@johlju
Copy link
Collaborator

johlju commented May 3, 2022

@gaelcolas was kind to make a test repo public: https://github.com/SynEdgy/MyChocoPackage. Though Geal has not built it for a long time so it is not certain it works with current version of Sampler without some modifications.

@johlju
Copy link
Collaborator

johlju commented May 3, 2022

So my theory in #358 (comment) did not work since Invoke-Build runs all tasks and sets all default values so the parameter $ChocolateyPackageId will always contain * regardless if a task in that file has run or not. So I move to the backup plan and looking for a folder 'output/choco' that the parameter $ChocolateyBuildOutput holds.

@johlju
Copy link
Collaborator

johlju commented May 3, 2022

I have sent in PR #364. Appreciate if someone here can review it.

johlju added a commit that referenced this issue May 13, 2022
- The module manifest is now correctly updated with release notes from the
  changelog. Fixes #358
@johlju johlju removed the help wanted The issue is up for grabs for anyone in the community. label May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants