@@ -44,18 +44,56 @@ jobs:
4444 - name : Run tests
4545 run : dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal
4646
47+ - name : Get tag for current commit
48+ id : get_tag
49+ if : github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
50+ run : |
51+ TAG=$(git tag --points-at HEAD | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -n 1)
52+ echo "tag=$TAG" >> $GITHUB_OUTPUT
53+ echo "Found tag: $TAG"
54+
4755 - name : Pack NuGet package
48- if : startsWith(github.ref, 'refs/tags/')
56+ if : steps.get_tag.outputs.tag != ''
4957 run : dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts
5058
5159 - name : Publish to NuGet
52- if : startsWith(github.ref, 'refs/tags/')
60+ if : steps.get_tag.outputs.tag != ''
5361 run : dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
5462
63+ - name : Extract release notes from CHANGELOG.md
64+ if : steps.get_tag.outputs.tag != ''
65+ id : extract_notes
66+ run : |
67+ VERSION="${{ steps.get_tag.outputs.tag }}"
68+ echo "Extracting notes for version: $VERSION"
69+
70+ NOTES=$(awk -v ver="v$VERSION" '
71+ $0 ~ "^## "ver"$" {flag=1; next}
72+ flag && $0 ~ "^## " {flag=0}
73+ flag
74+ ' <(sed "s/\r$//" CHANGELOG.md) | awk '!/^Release Date:/')
75+ NOTES=$(echo "$NOTES" | sed '/./,$!d' | tac | sed '/./,$!d' | tac)
76+
77+ if [ -z "$NOTES" ]; then
78+ echo "Did not find notes with 'v' prefix, trying without."
79+ NOTES=$(awk -v ver="$VERSION" '
80+ $0 ~ "^## "ver"$" {flag=1; next}
81+ flag && $0 ~ "^## " {flag=0}
82+ flag
83+ ' <(sed "s/\r$//" CHANGELOG.md) | awk '!/^Release Date:/')
84+ NOTES=$(echo "$NOTES" | sed '/./,$!d' | tac | sed '/./,$!d' | tac)
85+ fi
86+
87+ # Set output
88+ echo "notes<<EOF" >> $GITHUB_OUTPUT
89+ echo "$NOTES" >> $GITHUB_OUTPUT
90+ echo "EOF" >> $GITHUB_OUTPUT
91+
5592 - name : Create GitHub Release
56- if : startsWith(github.ref, 'refs/tags/')
93+ if : steps.get_tag.outputs.tag != ''
5794 uses : softprops/action-gh-release@v1
5895 with :
59- generate_release_notes : true
96+ tag_name : ${{ steps.get_tag.outputs.tag }}
97+ body : ${{ steps.extract_notes.outputs.notes }}
6098 env :
6199 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments