Skip to content

Commit 632258a

Browse files
committed
makefile fixes
1 parent 726bdb4 commit 632258a

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

makefile

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ TEST_PROJECT = ./Tests/VaultSharp.Extensions.Configuration.Test/VaultSharp.E
1313
PROJECT_TO_PUBLISH = ./Source/VaultSharp.Extensions.Configuration/VaultSharp.Extensions.Configuration.csproj
1414

1515
# Output Directories
16-
PUBLISH_DIR = ./publish
17-
PUBLISH_APP_DIR = $(PUBLISH_DIR)/App # Specific dir for the published app
16+
PUBLISH_DIR = .\publish
1817

1918
# Version Info (Consider making this dynamic, e.g., from git tag or a file)
2019
VERSION = 1.0.0
@@ -30,17 +29,35 @@ DOTNET = dotnet
3029
# Shell settings (use bash for more features if needed)
3130
SHELL = /bin/sh
3231

32+
# -----------------------------------------------------------------------------
33+
# Cross-platform Shell Helper
34+
# -----------------------------------------------------------------------------
35+
# Use 'pwsh' if available, otherwise fallback to 'powershell' on Windows
36+
ifeq ($(OS),Windows_NT)
37+
SHELL := pwsh.exe
38+
POWERSHELL := pwsh.exe
39+
MD = if (!(Test-Path '$(PUBLISH_DIR)')) { New-Item -ItemType Directory -Path '$(PUBLISH_DIR)' | Out-Null }
40+
RM = if (Test-Path '$(PUBLISH_DIR)') { Remove-Item -Recurse -Force '$(PUBLISH_DIR)' }
41+
LS = Test-Path "$(PUBLISH_DIR)\*.nupkg"
42+
else
43+
SHELL := /bin/bash
44+
POWERSHELL := pwsh
45+
MD = mkdir -p $(PUBLISH_DIR)
46+
RM = rm -rf $(PUBLISH_DIR)
47+
LS = ls $(PUBLISH_DIR)/*.nupkg 1> /dev/null 2>&1
48+
endif
49+
3350
# -----------------------------------------------------------------------------
3451
# Phony Targets (Targets that don't represent files)
3552
# -----------------------------------------------------------------------------
36-
.PHONY: all Default Clean Restore Build Test Pack Publish Push help
53+
.PHONY: all Default Clean Restore Build Test Pack Push help
3754

3855
# -----------------------------------------------------------------------------
3956
# Default Target
4057
# -----------------------------------------------------------------------------
4158
# The first target is the default if none is specified on the command line.
4259
# Maps to Cake's "Default" task which depends on "Publish".
43-
Default: Publish
60+
Default: Pack
4461

4562
all: Default # Common alias for the main default action
4663

@@ -89,32 +106,21 @@ Test: Build
89106
# Depends on Build
90107
Pack: Build
91108
@echo "--- Packing NuGet Packages (Version: $(VERSION)) ---"
92-
# Ensure publish dir exists for output
93-
mkdir -p $(PUBLISH_DIR)
109+
$(DOTNET) --version > /dev/null 2>&1 && (mkdir -p $(PUBLISH_DIR)) || (powershell -Command "if (!(Test-Path '$(PUBLISH_DIR)')) { New-Item -ItemType Directory -Path '$(PUBLISH_DIR)' | Out-Null }")
94110
$(DOTNET) pack $(SOLUTION) --configuration $(CONFIGURATION) --no-build --no-restore -o $(PUBLISH_DIR) /p:PackageVersion=$(VERSION) /p:Version=$(VERSION)
95111
@echo "Packaging complete. Packages in $(PUBLISH_DIR)"
96112

97-
# Publish the application
98-
# Depends on Test (ensures tests pass before publishing)
99-
# Might also depend on Pack if publish consumes packed artifacts, but typically depends on Build/Test.
100-
Publish: Test
101-
@echo "--- Publishing Application (Version: $(VERSION)) ---"
102-
# Ensure publish app dir exists
103-
mkdir -p $(PUBLISH_APP_DIR)
104-
$(DOTNET) publish $(PROJECT_TO_PUBLISH) --configuration $(CONFIGURATION) --no-build --no-restore -o $(PUBLISH_APP_DIR) /p:Version=$(VERSION)
105-
@echo "Publish complete. Application in $(PUBLISH_APP_DIR)"
106-
107113
# Push NuGet packages to the source
108114
# Depends on Pack
109115
Push: Pack
110116
@echo "--- Pushing NuGet Packages ---"
111-
# Check if NUGET_API_KEY is set (Makefile equivalent of .WithCriteria)
112-
$(if $(NUGET_API_KEY), \
113-
find $(PUBLISH_DIR) -name "*.nupkg" -exec $(DOTNET) nuget push {} --api-key $(NUGET_API_KEY) --source $(NUGET_SOURCE) \; , \
114-
@echo "NUGET_API_KEY not set. Skipping push. Set it via environment or 'make Push NUGET_API_KEY=your_key'" \
115-
)
117+
ifeq ($(OS),Windows_NT)
118+
$(DOTNET) nuget push "$(PUBLISH_DIR)\*.nupkg" --source $(NUGET_SOURCE) --api-key $(NUGET_API_KEY);
119+
else
120+
$(DOTNET) nuget push $(PUBLISH_DIR)/*.nupkg --source $(NUGET_SOURCE) --api-key $(NUGET_API_KEY);
121+
endif
116122
@echo "Push attempt finished."
117-
123+
118124

119125
# -----------------------------------------------------------------------------
120126
# Help Target
@@ -129,7 +135,6 @@ help:
129135
@echo " Build Build the solution"
130136
@echo " Test Run unit tests"
131137
@echo " Pack Create NuGet packages"
132-
@echo " Publish Publish the application"
133138
@echo " Push Push NuGet packages to the source (requires NUGET_API_KEY)"
134139
@echo ""
135140
@echo "Variables:"

0 commit comments

Comments
 (0)