1- name : ' Upload last-master versions to MyGet'
1+ name : ' Upload to MyGet and NuGet'
2+
3+ run-name : ${{ github.event_name == 'push' && 'Upload to MyGet' || 'Upload to NuGet' }}
24
35on :
46 push :
57 branches :
68 - master
9+ release :
10+ types : [published]
711
812jobs :
9- main :
13+ publish :
1014 runs-on : ubuntu-latest
15+ permissions :
16+ contents : read
1117 steps :
1218 - name : Setup .NET 10
1319 uses : actions/setup-dotnet@v5
@@ -17,41 +23,72 @@ jobs:
1723
1824 - uses : actions/checkout@v6
1925
20- - name : ' Pack AngouriMath'
26+ - name : ' Determine version and target'
27+ id : version
2128 run : |
22- cd Sources
23-
24- # versioning
25- commithash=$(git rev-parse --short HEAD)
26- currtime=$(date +%s)
27- echo "commit hash is $commithash"
28- echo "time is $currtime"
29- name=10.0.0-master-$currtime-$commithash
30- echo "name is $name"
31-
32- # AngouriMath
33- cd AngouriMath
29+ if [[ "${{ github.event_name }}" == "push" ]]; then
30+ # MyGet versioning
31+ commithash=$(git rev-parse --short HEAD)
32+ currtime=$(date +%s)
33+ echo "commit hash is $commithash"
34+ echo "time is $currtime"
35+ version=10.0.0-master-$currtime-$commithash
36+ echo "version is $version"
37+ echo "version=$version" >> $GITHUB_OUTPUT
38+ echo "apikey=${{ secrets.MYGET_KEY }}" >> $GITHUB_OUTPUT
39+ echo "source=myget" >> $GITHUB_OUTPUT
40+ echo "target=MyGet" >> $GITHUB_OUTPUT
41+ else
42+ # NuGet versioning from release tag
43+ tagname="${{ github.event.release.tag_name }}"
44+
45+ # Validate tag name exists
46+ if [[ -z "$tagname" ]]; then
47+ echo "Error: Release tag name is empty"
48+ exit 1
49+ fi
50+
51+ # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0)
52+ version="${tagname#v}"
53+ echo "Release tag is $tagname"
54+ echo "Package version is $version"
55+
56+ # Validate version format (SemVer 2.0.0: X.Y.Z[-prerelease][+build])
57+ if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ ]]; then
58+ echo "Error: Invalid version format '$version'."
59+ echo "Expected semantic version (e.g., 1.0.0, 1.0.0-beta.1, 1.0.0+build.123)"
60+ exit 1
61+ fi
62+
63+ echo "version=$version" >> $GITHUB_OUTPUT
64+ echo "apikey=${{ secrets.NUGET_KEY }}" >> $GITHUB_OUTPUT
65+ echo "source=nuget.org" >> $GITHUB_OUTPUT
66+ echo "target=NuGet" >> $GITHUB_OUTPUT
67+ fi
68+
69+ - name : ' Pack and publish AngouriMath'
70+ run : |
71+ cd Sources/AngouriMath
3472 dotnet restore AngouriMath.csproj
3573 dotnet build AngouriMath.csproj -c release
36- dotnet pack AngouriMath.csproj -c release -p:PackageVersion=$name
74+ dotnet pack AngouriMath.csproj -c release -p:PackageVersion=${{ steps.version.outputs.version }}
3775 cd bin/release
38- dotnet nuget push AngouriMath.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget"
39- cd ../../..
76+ dotnet nuget push AngouriMath.${{ steps.version.outputs.version }}.nupkg --api-key ${{ steps.version.outputs.apikey }} --source "${{ steps.version.outputs.source }}"
4077
41- # AngouriMath.FSharp
42- cd Wrappers/AngouriMath.FSharp
78+ - name : ' Pack and publish AngouriMath.FSharp'
79+ run : |
80+ cd Sources/Wrappers/AngouriMath.FSharp
4381 dotnet restore
4482 dotnet build -c Release
45- dotnet pack -c Release -p:PackageVersion=$name
83+ dotnet pack -c Release -p:PackageVersion=${{ steps.version.outputs.version }}
4684 cd bin/Release
47- dotnet nuget push AngouriMath.FSharp.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget"
48- cd ../../../..
85+ dotnet nuget push AngouriMath.FSharp.${{ steps.version.outputs.version }}.nupkg --api-key ${{ steps.version.outputs.apikey }} --source "${{ steps.version.outputs.source }}"
4986
50- # AngouriMath.Interactive
51- cd Wrappers/AngouriMath.Interactive
87+ - name : ' Pack and publish AngouriMath.Interactive'
88+ run : |
89+ cd Sources/Wrappers/AngouriMath.Interactive
5290 dotnet restore
5391 dotnet build -c Release
54- dotnet pack -c Release -p:PackageVersion=$name
92+ dotnet pack -c Release -p:PackageVersion=${{ steps.version.outputs.version }}
5593 cd bin/Release
56- dotnet nuget push AngouriMath.Interactive.$name.nupkg --api-key ${{ secrets.MYGET_KEY }} --source "myget"
57- cd ../../../..
94+ dotnet nuget push AngouriMath.Interactive.${{ steps.version.outputs.version }}.nupkg --api-key ${{ steps.version.outputs.apikey }} --source "${{ steps.version.outputs.source }}"
0 commit comments