Skip to content

Commit 1ee5e56

Browse files
authored
Update publish.yml
1 parent bdb3cf2 commit 1ee5e56

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,37 @@ jobs:
2121
- name: Restore dependencies
2222
run: dotnet restore
2323

24+
- name: Get the version from the .csproj file
25+
id: get_version
26+
run: |
27+
VERSION=$(grep -oPm1 "(?<=<Version>)[^<]+" src/SetSharp/SetSharp.csproj)
28+
echo "VERSION=$VERSION" >> $GITHUB_ENV
29+
30+
- name: Get the latest published version from NuGet
31+
id: get_latest_version
32+
run: |
33+
PACKAGE_ID="SetSharp"
34+
LATEST_VERSION=$(curl -s https://api.nuget.org/v3-flatcontainer/${PACKAGE_ID,,}/index.json | jq -r '.versions | last')
35+
echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV
36+
37+
- name: Compare versions
38+
id: version_check
39+
run: |
40+
if [ "$VERSION" != "$LATEST_VERSION" ]; then
41+
echo "New version detected: $VERSION"
42+
echo "run_publish=true" >> $GITHUB_ENV
43+
else
44+
echo "No new version detected"
45+
echo "run_publish=false" >> $GITHUB_ENV
46+
2447
- name: Build
48+
if: env.run_publish == 'true'
2549
run: dotnet build --configuration Release --no-restore
2650

2751
- name: Pack
52+
if: env.run_publish == 'true'
2853
run: dotnet pack src/SetSharp/SetSharp.csproj --configuration Release --no-build
2954

3055
- name: Publish to NuGet
56+
if: env.run_publish == 'true'
3157
run: dotnet nuget push "src/SetSharp/bin/Release/*.nupkg" --api-key ${{ secrets.NUGET_API_KEY }} --source "https://api.nuget.org/v3/index.json"

0 commit comments

Comments
 (0)