-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (68 loc) · 2.82 KB
/
nuget.yml
File metadata and controls
80 lines (68 loc) · 2.82 KB
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
name: Publish .NET Package to NuGet
on:
push:
branches:
- main
workflow_dispatch:
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '9.0'
- name: Get the version from the .csproj file
id: get_version
run: |
VERSION=$(cat SimpleViewModel/SimpleViewModel.csproj | grep -oPm1 "(?<=<Version>)[^<]+")
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Get the latest published version from NuGet
id: get_latest_version
run: |
LATEST_VERSION=$(curl -s "https://api.nuget.org/v3-flatcontainer/simpleviewmodel/index.json" | jq -r '.versions[-1]')
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
- name: Compare versions
id: version_check
run: |
if [ "$VERSION" != "$LATEST_VERSION" ]; then
echo "New version detected: $VERSION"
echo "run_publish=true" >> $GITHUB_ENV
else
echo "No new version detected"
echo "run_publish=false" >> $GITHUB_ENV
fi
- name: Restore dependencies
run: dotnet restore
- name: Build the project and source generator
run: |
dotnet build SimpleViewModel/SimpleViewModel.csproj --configuration Release --no-restore
dotnet build ViewModelGenerator/ViewModelGenerator.csproj --configuration Release --no-restore
- name: Pack the NuGet package
run: |
dotnet pack SimpleViewModel/SimpleViewModel.csproj --configuration Release --no-build --output ./nupkg
mkdir -p ./nupkg/analyzers/dotnet/cs/
if [ -f ViewModelGenerator/bin/Release/netstandard2.0/ViewModelGenerator.dll ]; then
echo "Source Generator DLL found, copying..."
cp ViewModelGenerator/bin/Release/netstandard2.0/ViewModelGenerator.dll ./nupkg/analyzers/dotnet/cs/
else
echo "Source Generator DLL not found! Exiting."
exit 1
fi
ls ./nupkg/analyzers/dotnet/cs/
- name: Unzip the NuGet package for inspection
run: |
mkdir -p ./package-inspection
unzip ./nupkg/*.nupkg -d ./package-inspection/
ls -R ./package-inspection
if [ -f ./package-inspection/analyzers/dotnet/cs/ViewModelGenerator.dll ]; then
echo "Source Generator DLL is correctly packed!"
else
echo "Source Generator DLL is missing from the package!" && exit 1
fi
- name: Publish to NuGet
if: env.run_publish == 'true'
run: dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
continue-on-error: true