-
Notifications
You must be signed in to change notification settings - Fork 12
85 lines (66 loc) · 2.89 KB
/
dotnet.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Build and Publish NuGet Package
on:
push:
branches:
- release/*
jobs:
build-and-push:
runs-on: ubuntu-latest
outputs:
package_version: ${{ steps.pack.outputs.package_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: '8.0'
- name: Get latest NuGet package version
run: |
nuget_response=$(curl -s "https://api.nuget.org/v3-flatcontainer/DotnetGeminiSDK/index.json")
echo "NuGet API Response:"
echo "$nuget_response"
latest_version=$(echo "$nuget_response" | python -c "import sys, json; data = json.load(sys.stdin); versions = data.get('versions', []); versions = [v for v in versions if v is not None]; print(max(versions, key=lambda s: list(map(int, s.split('.')))) if versions else '')")
echo "Latest version after parsing:"
echo "$latest_version"
if [ -z "$latest_version" ]; then
echo "Error: Unable to determine the latest version from the NuGet API response."
exit 1
fi
IFS='.' read -r -a version_parts <<< "$latest_version"
echo "Version parts array: ${version_parts[@]}"
if [ "${#version_parts[@]}" -lt 3 ]; then
echo "Error: Insufficient version parts."
exit 1
fi
set -x
((version_parts[2]++))
set -x
echo "Incremented version parts array: ${version_parts[@]}"
new_version="${version_parts[0]}.${version_parts[1]}.${version_parts[2]}"
echo "Latest version: $latest_version"
echo "New version: $new_version"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: Show environment variable
run: |
echo "NEW_VERSION: $NEW_VERSION"
- name: Install nuget CLI
run: |
sudo curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
alias nuget="mono /usr/local/bin/nuget.exe"
- name: Update Nuspec file
run: |
nuspec_path="nuget/dotnet-gemini.nuspec"
sed -i "s/<version>.*<\/version>/<version>${NEW_VERSION}<\/version>/" "$nuspec_path"
cat "$nuspec_path"
- name: Pack NuGet package
id: pack
run: |
nuspec_path="nuget/dotnet-gemini.nuspec"
dotnet pack src/DotnetGeminiSDK/DotnetGeminiSDK.csproj --configuration Release --output nupkg -p:PackageVersion=$NEW_VERSION
echo "::set-output name=package_version::$NEW_VERSION"
echo "Packaged NuGet package version: $NEW_VERSION"
- name: Push NuGet Package
run: nuget push **/*.nupkg -Source https://api.nuget.org/v3/index.json -ApiKey ${{ secrets.NUGET_API_KEY }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}