@@ -18,28 +18,71 @@ jobs:
1818 runs-on : ubuntu-latest
1919
2020 steps :
21+ # Checkout repository with full history
2122 - uses : actions/checkout@v3
2223 with :
2324 fetch-depth : 0
2425
26+ # Setup .NET SDK
2527 - name : Setup .NET
2628 uses : actions/setup-dotnet@v3
2729 with :
2830 dotnet-version : ' 9.0.x'
2931
30- # Setup
31- - name : Install GitVersion
32- uses : gittools/actions/gitversion/setup@v0.10.2
33- with :
34- preferLatestVersion : true
35-
36- # Fetch version
37- - name : Determine Version
38- id : gitversion
39- uses : gittools/actions/gitversion/execute@v0.10.2
32+ # Check which projects changed and calculate their new versions
33+ - name : Check Changes and Calculate Versions
34+ id : version_check
35+ run : |
36+ SHOULD_RELEASE="false"
37+ CHANGED_PROJECTS=""
38+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
39+
40+ # Check each project for changes and update versions
41+ for proj in $(find . -name "*.csproj"); do
42+ PROJECT_NAME=$(basename "$proj")
43+ PROJECT_DIR=$(dirname "$proj")
44+
45+ # Get current version from csproj
46+ CURRENT_VERSION=$(grep -oP '(?<=<Version>).*(?=</Version>)' "$proj" || echo "0.0.0")
47+
48+ # Split version into parts
49+ IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
50+ MAJOR="${VERSION_PARTS[0]}"
51+ MINOR="${VERSION_PARTS[1]}"
52+ PATCH="${VERSION_PARTS[2]}"
53+
54+ # Check if project has changes since last tag
55+ if [ -z "$LATEST_TAG" ] || ! git diff --quiet $LATEST_TAG HEAD -- "$PROJECT_DIR"; then
56+ # Calculate new version based on release type
57+ case "${{ github.event.inputs.release_type }}" in
58+ "major")
59+ NEW_VERSION="$((MAJOR + 1)).0.0"
60+ ;;
61+ "minor")
62+ NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
63+ ;;
64+ "patch")
65+ NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
66+ ;;
67+ esac
68+
69+ # Update version in csproj
70+ sed -i "s/<Version>.*<\/Version>/<Version>${NEW_VERSION}<\/Version>/g" "$proj"
71+
72+ CHANGED_PROJECTS="$CHANGED_PROJECTS$PROJECT_NAME -> $NEW_VERSION\n"
73+ SHOULD_RELEASE="true"
74+ fi
75+ done
76+
77+ # Set environment variables for next steps
78+ echo "CHANGED_PROJECTS<<EOF" >> $GITHUB_ENV
79+ echo -e "$CHANGED_PROJECTS" >> $GITHUB_ENV
80+ echo "EOF" >> $GITHUB_ENV
81+ echo "SHOULD_RELEASE=$SHOULD_RELEASE" >> $GITHUB_ENV
4082
41- # Gen release notes
83+ # Generate release notes with commits and changed projects
4284 - name : Generate Release Notes
85+ if : env.SHOULD_RELEASE == 'true'
4386 id : release_notes
4487 run : |
4588 PREVIOUS_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
@@ -51,47 +94,28 @@ jobs:
5194 echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
5295 echo "## What's Changed" >> $GITHUB_ENV
5396 echo "$COMMITS" >> $GITHUB_ENV
97+ echo -e "\n## Updated Projects" >> $GITHUB_ENV
98+ echo "${{ env.CHANGED_PROJECTS }}" >> $GITHUB_ENV
5499 echo "EOF" >> $GITHUB_ENV
55-
56- # Calc new version
57- - name : Calculate New Version
58- id : version
59- run : |
60- CURRENT_VERSION=${{ steps.gitversion.outputs.semVer }}
61- IFS='.' read -r -a VERSION_PARTS <<< "$CURRENT_VERSION"
62- MAJOR="${VERSION_PARTS[0]}"
63- MINOR="${VERSION_PARTS[1]}"
64- PATCH="${VERSION_PARTS[2]}"
65-
66- case "${{ github.event.inputs.release_type }}" in
67- "major")
68- NEW_VERSION="$((MAJOR + 1)).0.0"
69- ;;
70- "minor")
71- NEW_VERSION="${MAJOR}.$((MINOR + 1)).0"
72- ;;
73- "patch")
74- NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))"
75- ;;
76- esac
77- echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV
78-
79- # Update csproj
80- - name : Update Version
81- run : |
82- find . -name "*.csproj" -type f -exec sed -i "s/<Version>.*<\/Version>/<Version>${{ env.NEW_VERSION }}<\/Version>/g" {} \;
83100
101+ # Restore project dependencies
84102 - name : Restore dependencies
103+ if : env.SHOULD_RELEASE == 'true'
85104 run : dotnet restore
86105
106+ # Build solution
87107 - name : Build
108+ if : env.SHOULD_RELEASE == 'true'
88109 run : dotnet build --configuration Release --no-restore
89110
111+ # Create NuGet packages
90112 - name : Pack
113+ if : env.SHOULD_RELEASE == 'true'
91114 run : dotnet pack --configuration Release --no-build --output nupkgs
92115
93- # Create release
116+ # Create GitHub release
94117 - name : Create Release
118+ if : env.SHOULD_RELEASE == 'true'
95119 id : create_release
96120 uses : actions/create-release@v1
97121 env :
@@ -103,25 +127,28 @@ jobs:
103127 draft : false
104128 prerelease : false
105129
106- # Move .nupkg into dist
107- - name : Upload Release Asset
130+ # Upload NuGet packages as release assets
131+ - name : Upload Release Assets
132+ if : env.SHOULD_RELEASE == 'true'
108133 uses : softprops/action-gh-release@v1
109134 with :
110135 files : ./nupkgs/*.nupkg
111136 tag_name : v${{ env.NEW_VERSION }}
112137 env :
113138 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
114139
115- # Publish
140+ # Publish packages to NuGet.org
116141 - name : Push to NuGet
142+ if : env.SHOULD_RELEASE == 'true'
117143 run : dotnet nuget push "./nupkgs/*.nupkg" --source "https://api.nuget.org/v3/index.json" --api-key ${{secrets.NUGET_API_KEY}} --skip-duplicate
118144
119- # Commit
120- - name : Commit version update
145+ # Commit version updates and create tag
146+ - name : Commit version updates
147+ if : env.SHOULD_RELEASE == 'true'
121148 run : |
122149 git config --local user.email "action@github.com"
123150 git config --local user.name "GitHub Action"
124151 git add .
125- git commit -m "Bump version to ${{ env.NEW_VERSION }} "
152+ git commit -m "Update project versions "
126153 git tag -a "v${{ env.NEW_VERSION }}" -m "Release v${{ env.NEW_VERSION }}"
127- git push --follow-tags
154+ git push --follow-tags
0 commit comments