Skip to content

Commit 18f6977

Browse files
Updated build script.
1 parent 60b3d8e commit 18f6977

File tree

1 file changed

+56
-24
lines changed

1 file changed

+56
-24
lines changed

build.sh

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
#!/usr/bin/env bash
2-
32
set -euo pipefail
3+
44
export USE_FULL_NUMERIC_PROVIDER=true
55

6+
# Safeguards
67

7-
echo "Pulling the latest repository changes"
8-
git pull
8+
if [ -z "${NUGET_API_KEY:-}" ]; then
9+
echo "ERROR: NUGET_API_KEY is not set in the environment."
10+
echo "Add: export NUGET_API_KEY=\"<your-nuget-api-key>\" to your shell profile."
11+
exit 1
12+
fi
913

14+
if [ -z "${GITHUB_TOKEN:-}" ]; then
15+
echo "ERROR: GITHUB_TOKEN is not set in the environment."
16+
echo "Add: export GITHUB_TOKEN=\"<your-github-pat-with-write:packages>\" to your shell profile."
17+
exit 1
18+
fi
19+
20+
# Git Preparation
21+
22+
echo "Pulling the latest repository changes"
23+
git pull --ff-only
1024

1125
echo "Checking out main branch"
1226
git checkout main
1327

14-
1528
echo "Obtaining release version"
1629
VERSION=$(grep "<Version>" Directory.Build.props | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/')
1730

@@ -22,43 +35,62 @@ fi
2235

2336
echo "Detected release version: $VERSION"
2437

25-
2638
echo "Checking out release branch"
2739
git checkout release
2840

29-
3041
echo "Merging main branch into release branch"
31-
git merge main
32-
42+
git merge --no-ff main -m "Merging main into release with version: $VERSION"
3343

3444
echo "Pushing release branch to origin"
3545
git push origin release
3646

47+
# Build, Test, and Pack
48+
49+
echo "Restoring .NET solution"
50+
dotnet restore
51+
52+
echo "Building .NET solution (Release)"
53+
dotnet build --configuration Release --no-restore
54+
55+
echo "Running tests (Release)"
56+
dotnet test --configuration Release --no-build
57+
58+
echo "Packing projects (Release)"
59+
dotnet pack --configuration Release --no-build
60+
61+
# Create Git Tag
3762

38-
echo "Building and testing .NET solution"
39-
dotnet build --configuration Release
40-
dotnet test --configuration Release
63+
echo "Creating annotated tag: v$VERSION"
64+
git tag -a "v$VERSION" -m "Release v$VERSION"
65+
git push origin "v$VERSION"
4166

67+
# Publish Helpers
4268

43-
echo "Creating new tag with version: $VERSION"
44-
git tag "$VERSION"
45-
git push origin "$VERSION"
69+
PACKAGES=(
70+
"OnixLabs.Core"
71+
"OnixLabs.DependencyInjection"
72+
"OnixLabs.Numerics"
73+
"OnixLabs.Security"
74+
"OnixLabs.Security.Cryptography"
75+
)
4676

77+
# Push to GitHub Packages
4778

4879
echo "Pushing packages to GitHub package registry"
49-
dotnet nuget push "OnixLabs.Core/bin/Release/OnixLabs.Core.$VERSION.nupkg" --source "github"
50-
dotnet nuget push "OnixLabs.DependencyInjection/bin/Release/OnixLabs.DependencyInjection.$VERSION.nupkg" --source "github"
51-
dotnet nuget push "OnixLabs.Numerics/bin/Release/OnixLabs.Numerics.$VERSION.nupkg" --source "github"
52-
dotnet nuget push "OnixLabs.Security/bin/Release/OnixLabs.Security.$VERSION.nupkg" --source "github"
53-
dotnet nuget push "OnixLabs.Security.Cryptography/bin/Release/OnixLabs.Security.Cryptography.$VERSION.nupkg" --source "github"
80+
for pkg in "${PACKAGES[@]}"; do
81+
nupkg="\"$pkg/bin/Release/$pkg.$VERSION.nupkg\""
82+
# --skip-duplicate makes the script safe to re-run
83+
eval dotnet\ nuget\ push\ $nupkg\ --source\ \"github\"\ --api-key\ \"\$GITHUB_TOKEN\"\ --skip-duplicate
84+
done
5485

86+
# Push to NuGet.org
5587

5688
echo "Pushing packages to NuGet package registry"
57-
dotnet nuget push "OnixLabs.Core/bin/Release/OnixLabs.Core.$VERSION.nupkg" --source "nuget.org" --api-key "$NUGET_API_KEY"
58-
dotnet nuget push "OnixLabs.DependencyInjection/bin/Release/OnixLabs.DependencyInjection.$VERSION.nupkg" --source "nuget.org" --api-key "$NUGET_API_KEY"
59-
dotnet nuget push "OnixLabs.Numerics/bin/Release/OnixLabs.Numerics.$VERSION.nupkg" --source "nuget.org" --api-key "$NUGET_API_KEY"
60-
dotnet nuget push "OnixLabs.Security/bin/Release/OnixLabs.Security.$VERSION.nupkg" --source "nuget.org" --api-key "$NUGET_API_KEY"
61-
dotnet nuget push "OnixLabs.Security.Cryptography/bin/Release/OnixLabs.Security.Cryptography.$VERSION.nupkg" --source "nuget.org" --api-key "$NUGET_API_KEY"
89+
for pkg in "${PACKAGES[@]}"; do
90+
nupkg="\"$pkg/bin/Release/$pkg.$VERSION.nupkg\""
91+
eval dotnet\ nuget\ push\ $nupkg\ --source\ \"nuget.org\"\ --api-key\ \"\$NUGET_API_KEY\"\ --skip-duplicate
92+
done
6293

94+
# DONE
6395

6496
echo "Build and release process completed successfully!"

0 commit comments

Comments
 (0)