-
Notifications
You must be signed in to change notification settings - Fork 1
135 lines (112 loc) · 4.42 KB
/
tag-draft-release.yml
File metadata and controls
135 lines (112 loc) · 4.42 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
name: Tag and Create Draft Release
on:
workflow_dispatch:
permissions:
contents: write
jobs:
tag-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Nerdbank GitVersioning needs the full history to calculate the version number
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
global-json-file: "global.json"
- name: Restore tools
run: dotnet tool restore
- name: Get version from nbgv
id: get_version
run: echo "version=$(nbgv get-version -v SemVer2)" >> $GITHUB_OUTPUT
# ✅ Only tag & push if build/tests succeeded
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --configuration Release --no-build --verbosity normal
- name: Pack NuGet
run: dotnet pack --configuration Release --no-build -o ./artifacts
# Everything builds, now tag and draft the release
- name: Tag git version
run: |
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git tag v${{ steps.get_version.outputs.version }}
git push origin v${{ steps.get_version.outputs.version }}
- name: Determine previous tag by semantic version
id: prev_tag
run: |
current_tag="v${{ steps.get_version.outputs.version }}"
echo "Current tag: $current_tag"
# Get all tags sorted by semver
all_tags=$(git tag --sort=v:refname | grep '^v')
echo "All tags (semver sorted):"
echo "$all_tags"
# Find the previous tag by walking the sorted list
previous_tag=""
for tag in $all_tags; do
if [ "$tag" = "$current_tag" ]; then
break
fi
previous_tag=$tag
done
echo "Previous tag: $previous_tag"
echo "tag=$previous_tag" >> $GITHUB_OUTPUT
- name: Generate release notes
run: |
current_tag="v${{ steps.get_version.outputs.version }}"
prev_tag="${{ steps.prev_tag.outputs.tag }}"
echo "Generating release notes for range: ${prev_tag}..${current_tag}"
RANGE_ARG=""
if [ -n "$prev_tag" ]; then
RANGE_ARG="${prev_tag}..${current_tag}"
else
RANGE_ARG="$current_tag" # first tag ever, just include that commit
fi
echo "## 🚀 Release ${current_tag}" > notes.md
echo "" >> notes.md
# Grab all commits in the range
all_commits=$(git log $RANGE_ARG --pretty=format:"%s")
# Helper function for adding sections
add_section() {
local title=$1
local pattern=$2
local matches=$(echo "$all_commits" | grep -E "$pattern" || true)
if [ -n "$matches" ]; then
echo "### $title" >> notes.md
echo "$matches" | sed 's/^/- /' >> notes.md
echo "" >> notes.md
fi
}
# Add categorized sections
add_section "✨ Features & Improvements" "✨|⚡️|♻️"
add_section "🐛 Bug Fixes" "🐛|🚑"
add_section "⚠️ Breaking Changes" "💥|🔥"
add_section "📝 Documentation" "📝"
add_section "🛠 Maintenance" "🧰|🔧|♿"
# Find commits that didn't match any of the above
known_pattern="✨|⚡️|♻️|🐛|🚑|💥|🔥|📝|🧰|🔧|♿"
other_commits=$(echo "$all_commits" | grep -Ev "$known_pattern" || true)
if [ -n "$other_commits" ]; then
echo "### 🔄 Other Changes" >> notes.md
echo "$other_commits" | sed 's/^/- /' >> notes.md
echo "" >> notes.md
fi
echo "Generated release notes:"
cat notes.md
- name: Create draft GitHub release with attached NuGet package
uses: softprops/action-gh-release@v1
with:
draft: true
tag_name: v${{ steps.get_version.outputs.version }}
name: v${{ steps.get_version.outputs.version }}
body_path: notes.md
files: |
./artifacts/*.nupkg
./artifacts/*.snupkg
fail_on_unmatched_files: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}