|
1 | 1 | #!/usr/bin/env bash |
2 | | - |
3 | 2 | set -euo pipefail |
| 3 | + |
4 | 4 | export USE_FULL_NUMERIC_PROVIDER=true |
5 | 5 |
|
| 6 | +# Safeguards |
6 | 7 |
|
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 |
9 | 13 |
|
| 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 |
10 | 24 |
|
11 | 25 | echo "Checking out main branch" |
12 | 26 | git checkout main |
13 | 27 |
|
14 | | - |
15 | 28 | echo "Obtaining release version" |
16 | 29 | VERSION=$(grep "<Version>" Directory.Build.props | sed -E 's/.*<Version>(.*)<\/Version>.*/\1/') |
17 | 30 |
|
|
22 | 35 |
|
23 | 36 | echo "Detected release version: $VERSION" |
24 | 37 |
|
25 | | - |
26 | 38 | echo "Checking out release branch" |
27 | 39 | git checkout release |
28 | 40 |
|
29 | | - |
30 | 41 | 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" |
33 | 43 |
|
34 | 44 | echo "Pushing release branch to origin" |
35 | 45 | git push origin release |
36 | 46 |
|
| 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 |
37 | 62 |
|
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" |
41 | 66 |
|
| 67 | +# Publish Helpers |
42 | 68 |
|
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 | +) |
46 | 76 |
|
| 77 | +# Push to GitHub Packages |
47 | 78 |
|
48 | 79 | 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 |
54 | 85 |
|
| 86 | +# Push to NuGet.org |
55 | 87 |
|
56 | 88 | 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 |
62 | 93 |
|
| 94 | +# DONE |
63 | 95 |
|
64 | 96 | echo "Build and release process completed successfully!" |
0 commit comments