Skip to content

Commit f8e2cae

Browse files
authored
fix(build): pass VERSION arg through taskfile build and pack steps (#112)
* fix(generator): handle missing AssemblyInformationalVersion gracefully - Fallback to `AssemblyName.Version` when `AssemblyInformationalVersionAttribute` is unavailable. - Default to "unknown" if both values are missing. * fix(tests): update regex pattern in `GeneratedCodeAttributeRegex` - Enhanced regex to match version strings with a "+" suffix, e.g., `1.2.3+buildinfo`. - Adjusted formatting for better readability and maintenance. * feat(build): add support for custom versioning via `VERSION` variable - Introduced `VERSION` variable in `taskfile.yaml` for custom build versioning. - Updated `build`, `pack`, and `publish` tasks to include `/p:Version` when `VERSION` is defined. - Enforced `VERSION` requirement for `publish` and `pack-local` tasks. * fix(generator): simplify fallback logic for AssemblyInformationalVersion - Removed fallback to `AssemblyName.Version` when `AssemblyInformationalVersion` is unavailable. - Simplified assignment logic to default directly to "unknown". * refactor(taskfile): rename `pack-local` task to `publish-local` - Updated task name for clarity and consistency with its purpose. - No changes to functionality or dependencies. * fix(taskfile): include version in `publish-local` log output - Updated `echo` command to display the `VERSION` being published. - Enhances logging clarity during local NuGet publishing. * fix(workflows): update workflow templates to use latest version - Updated `publish-preview.yml` and `publish-release.yml` to reference `main` instead of `v8.0`. - Adjusted `release` event trigger syntax in `publish-release.yml` for consistency. - Ensures workflows use the latest updates from the shared templates. * fix(taskfile): include version in `publish` log output - Updated `echo` command to display the `VERSION` being published. - Improves logging clarity during NuGet package publishing.
1 parent 52de3fd commit f8e2cae

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

.github/workflows/publish-preview.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions: write-all
1616

1717
jobs:
1818
publish:
19-
uses: LayeredCraft/devops-templates/.github/workflows/publish-preview.yml@v8.0
19+
uses: LayeredCraft/devops-templates/.github/workflows/publish-preview.yml@main
2020
with:
2121
solution: LayeredCraft.DynamoMapper.slnx
2222
dotnetVersion: |

.github/workflows/publish-release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ name: Publish Release
22

33
on:
44
release:
5-
types: [published]
5+
types: [ published ]
66

77
permissions: write-all
88

99
jobs:
1010
publish:
11-
uses: LayeredCraft/devops-templates/.github/workflows/publish-release.yml@v8.0
11+
uses: LayeredCraft/devops-templates/.github/workflows/publish-release.yml@main
1212
with:
1313
solution: LayeredCraft.DynamoMapper.slnx
1414
dotnetVersion: |

src/LayeredCraft.DynamoMapper.Generators/Emitters/MapperEmitter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ private static string GeneratedCodeAttribute
1717
var generatorName = assembly.GetName().Name;
1818
var generatorVersion =
1919
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
20-
?.InformationalVersion ??
21-
assembly.GetName().Version?.ToString() ?? "unknown";
20+
?.InformationalVersion ?? "unknown";
2221

2322
field =
2423
$"""[global::System.CodeDom.Compiler.GeneratedCode("{generatorName}", "{generatorVersion}")]""";

taskfile.yaml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ version: '3'
33
dotenv:
44
- .env
55

6+
vars:
7+
VERSION: '{{.VERSION | default ""}}'
8+
69
tasks:
710
format:
811
desc: Reformat the solution
@@ -36,7 +39,7 @@ tasks:
3639
deps: [ restore ]
3740
cmds:
3841
- echo "🔨 Building Release"
39-
- dotnet build --configuration Release --no-restore
42+
- dotnet build --configuration Release --no-restore {{if .VERSION}}/p:Version="{{.VERSION}}"{{end}}
4043
- echo "✅ Release build complete"
4144

4245
pack:
@@ -45,26 +48,30 @@ tasks:
4548
deps: [ build ]
4649
cmds:
4750
- echo "📦 Packing Packages"
48-
- dotnet pack --configuration Release --no-build --output ./nupkg
51+
- dotnet pack --configuration Release --no-build --output ./nupkg {{if .VERSION}}/p:Version="{{.VERSION}}"{{end}}
4952
- echo "✅ Packed"
5053

5154
publish:
5255
desc: Publish the package to a package registry
5356
silent: true
57+
requires:
58+
vars: [ VERSION ]
5459
deps: [ pack ]
5560
cmds:
56-
- echo "🚀 Publishing"
61+
- echo "🚀 Publishing version {{.VERSION}}"
5762
- dotnet nuget push ./nupkg/*.nupkg --source https://api.nuget.org/v3/index.json --api-key $NUGET_API_KEY_LOCAL --skip-duplicate
5863
- echo "✨ Published"
5964

60-
pack-local:
65+
publish-local:
6166
desc: Package and publish to local NuGet source for use in other solutions
6267
silent: true
68+
requires:
69+
vars: [ VERSION ]
6370
deps: [ pack ]
6471
vars:
6572
LOCAL_NUGET_SOURCE: '{{.LOCAL_NUGET_SOURCE | default "~/LocalNuGetPackages"}}'
6673
cmds:
67-
- echo "📦 Publishing to local NuGet source"
74+
- echo "📦 Publishing version {{.VERSION}} to local NuGet source"
6875
- mkdir -p {{.LOCAL_NUGET_SOURCE}}
6976
- cp -f ./nupkg/*.nupkg {{.LOCAL_NUGET_SOURCE}}/
7077
- echo "✅ Published to {{.LOCAL_NUGET_SOURCE}}"

0 commit comments

Comments
 (0)