-
Notifications
You must be signed in to change notification settings - Fork 0
99 lines (75 loc) · 3.27 KB
/
build.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
name: Build & Release
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
environment:
name: nuget.org
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Update Patch Versions
run: |
echo "Starting the patch version update process..."
# Find all .csproj files
csprojFiles=$(find . -name '*.csproj')
echo "Found .csproj files: $csprojFiles"
for csprojFile in $csprojFiles; do
echo "Processing file: $csprojFile"
# Check for PackageId, otherwise use project name
packageName=$(grep -oPm1 "(?<=<PackageId>)[^<]+" $csprojFile || echo $(basename $csprojFile .csproj))
echo "Package name determined: $packageName"
# Extract or initialize the version
version=$(grep -oPm1 "(?<=<Version>)[^<]+" $csprojFile)
if [ -z "$version" ]; then
echo "No version found in $csprojFile, initializing to default 1.0.0"
version="1.0.0"
sed -i "/<\/PropertyGroup>/i \ \ <Version>$version<\/Version>" $csprojFile
fi
echo "Version: $version"
majorMinor=$(echo $version | cut -d'.' -f1,2)
echo "Major and minor version: $majorMinor"
# Fetch latest patch version from NuGet
echo "Fetching latest patch version for $packageName from NuGet..."
nugetListOutput=$(nuget list $packageName -PreRelease)
echo "NuGet list output for $packageName: $nugetListOutput"
filteredList=$(echo "$nugetListOutput" | grep "$majorMinor\.")
echo "Filtered list for version $majorMinor: $filteredList"
sortedList=$(echo "$filteredList" | sort -V)
echo "Sorted list of versions: $sortedList"
latestVersion=$(echo "$sortedList" | tail -n1)
echo "Latest version found: $latestVersion"
latestPatch=$(echo "$latestVersion" | grep -oP "\b\d+\.\d+\.\K\d+" | head -n1)
echo "Latest patch version extracted: $latestPatch"
if [ -z "$latestPatch" ]; then
latestPatch=0
echo "No patch versions found on NuGet for $majorMinor, defaulting to 0"
fi
echo "Latest patch version from NuGet: $latestPatch"
if [ -z "$latestPatch" ]; then
latestPatch=0
echo "No patch versions found on NuGet, defaulting to 0"
fi
# Update .csproj with new patch version
newPatch=$((latestPatch + 1))
newVersion="$majorMinor.$newPatch"
echo "Updating to new version: $newVersion"
sed -i "s/<Version>$version<\/Version>/<Version>$newVersion<\/Version>/" $csprojFile
done
echo "Patch version update process completed."
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: Pack
run: dotnet pack --configuration Release --no-build --output nupkgs
- name: Publish
run: dotnet nuget push "nupkgs/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{ secrets.NUGET_API_KEY }}
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}