Skip to content

Commit

Permalink
Add configuration for builddate attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
tboby committed Oct 27, 2024
1 parent 3ad640c commit 3f952c3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ There's really only one property that matters for these targets, and that's `Cha
| - | - |---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ChangelogFile | string | - | Points to the changelog file to parse. Note that the value is relative to the _project_ root by default, so a repository-wide changelog would require this property be set to a different value, for example in a Directory.Build.props file |
| GenerateVersionForUnreleasedChanges | boolean | true | If set, the assembly/package version and release notes will be set from Unreleased changes, if any are present. |
| GenerateAssemblyBuildDateAttribute | boolean | true | If set, an assembly metadata attribute named "BuildDate" will be generated with the date (YYYY-MM-DD) of the parsed release. |

## API

Expand Down
9 changes: 5 additions & 4 deletions src/build/Core.targets
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
</Ionide.KeepAChangelog.Tasks.ParseChangeLogs>
</Target>

<Target Name="SetVersionFromChangelog" DependsOnTargets="GetChangelogVersion">
<Target Name="SetVersionFromChangelog" DependsOnTargets="GetChangelogVersion"
BeforeTargets="GetAssemblyVersion;GenerateAssemblyInfo" >
<PropertyGroup Condition="'@(CurrentReleaseChangelog)' != ''">
<!-- Set the version to the version of the latest release -->
<Version>%(CurrentReleaseChangelog.Identity)</Version>
Expand All @@ -42,10 +43,10 @@
<_ReleaseDate>%(UnreleasedChangelog.Date)</_ReleaseDate>
</PropertyGroup>

<ItemGroup Condition="'@(_ReleaseDate)' != '' and '$(GenerateAssemblyInfo)' == 'true'">
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(GenerateRepositoryUrlAttribute)' == 'true' and ('$(RepositoryUrl)' != '' or '$(PublishRepositoryUrl)' == 'true')">
<ItemGroup Condition="'$(_ReleaseDate)' != '' and '$(GenerateAssemblyInfo)' == 'true'">
<AssemblyAttribute Include="System.Reflection.AssemblyMetadataAttribute" Condition="'$(GenerateAssemblyBuildDateAttribute)' == 'true'">
<_Parameter1>BuildDate</_Parameter1>
<_Parameter2>%(_ReleaseDate)</_Parameter2>
<_Parameter2>$(_ReleaseDate)</_Parameter2>
</AssemblyAttribute>
</ItemGroup>
</Target>
Expand Down
2 changes: 2 additions & 0 deletions src/build/Ionide.KeepAChangelog.Tasks.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
<PropertyGroup>
<!-- If set, the assembly/package version and release notes will be set from Unreleased changes, if any are present -->
<GenerateVersionForUnreleasedChanges Condition="'$(GenerateVersionForUnreleasedChanges)' == ''">true</GenerateVersionForUnreleasedChanges>
<!-- If true, assembly metadata for the build date of the release will be written -->
<GenerateAssemblyBuildDateAttribute Condition="'$(GenerateAssemblyBuildDateAttribute)' == ''">true</GenerateAssemblyBuildDateAttribute>
</PropertyGroup>
</Project>
39 changes: 22 additions & 17 deletions tests/IntegrationTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,29 @@ type IntegrationTests() =

member val testPackageVersion = null with get, set

member this.AddPackageReference(projectName: string) =
Command.Run(
"dotnet",
CmdLine.empty
|> CmdLine.appendPrefix "add" projectName
|> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks"
// |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.``
|> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]"
|> CmdLine.toString,
workingDirectory = Workspace.fixtures.``.``
)
member this.AddPackageReference(projectName: string) : Task =
task {
let! struct (_, _) =
Command.ReadAsync(
"dotnet",
CmdLine.empty
|> CmdLine.appendPrefix "add" projectName
|> CmdLine.appendPrefix "package" "Ionide.KeepAChangelog.Tasks"
// |> CmdLine.appendPrefix "--source" VirtualWorkspace.``test-nupkgs``.``.``
|> CmdLine.appendPrefix "--version" $"[{this.testPackageVersion}]"
|> CmdLine.toString,
workingDirectory = Workspace.fixtures.``.``
)

()
}

[<TestMethod>]
member this.``works for absolute path with keep a changelog``() : Task =
task {
let projectName = "WorksForAbsolutePathWithKeepAChangelog.fsproj"

this.AddPackageReference projectName
// this.AddPackageReference projectName

let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName

Expand All @@ -116,7 +121,7 @@ type IntegrationTests() =
task {
let projectName = "WorksForRelativePathWithKeepAChangelog.fsproj"

this.AddPackageReference projectName
do! this.AddPackageReference projectName

let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName

Expand All @@ -140,7 +145,7 @@ type IntegrationTests() =
task {
let projectName = "FailIfChangelogNotSpecified.fsproj"

this.AddPackageReference projectName
do! this.AddPackageReference projectName

let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName

Expand All @@ -164,7 +169,7 @@ type IntegrationTests() =
task {
let projectName = "FailIfChangelogDoesNotExist.fsproj"

this.AddPackageReference projectName
do! this.AddPackageReference projectName

let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName

Expand All @@ -188,7 +193,7 @@ type IntegrationTests() =
task {
let projectName = "WorksForUnreleased.fsproj"

this.AddPackageReference projectName
do! this.AddPackageReference projectName

let! struct (stdout, _) = Utils.packAndGetPackageProperties projectName

Expand All @@ -212,7 +217,7 @@ type IntegrationTests() =
task {
let projectName = "WorksForUnreleased.fsproj"

this.AddPackageReference projectName
do! this.AddPackageReference projectName

let! struct (stdout, _) =
Utils.packAndGetPackagePropertiesWithExtraArg
Expand Down

0 comments on commit 3f952c3

Please sign in to comment.