-
-
Notifications
You must be signed in to change notification settings - Fork 36
234 lines (194 loc) · 7.15 KB
/
release.yml
File metadata and controls
234 lines (194 loc) · 7.15 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: release
on:
push:
branches: [main]
jobs:
build:
name: build
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v6
- name: setup .net
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: cache nuget packages
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: restore dependencies
run: dotnet restore
- name: build
run: dotnet build --no-restore --configuration Release
test:
name: test
runs-on: ubuntu-latest
steps:
- name: checkout code
uses: actions/checkout@v6
- name: setup .net
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: cache nuget packages
uses: actions/cache@v5
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: restore dependencies
run: dotnet restore
- name: build
run: dotnet build --no-restore --configuration Release
- name: run tests
run: dotnet test --no-build --configuration Release
release:
name: release
needs: [build, test]
runs-on: windows-latest
permissions:
contents: write
steps:
- name: checkout code
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: setup .net
uses: actions/setup-dotnet@v5
with:
dotnet-version: '10.0.x'
- name: calculate version and generate changelog
id: version
shell: bash
run: |
# Get the latest 5.x.x tag, or default to 5.0.0
LAST_TAG=$(git tag -l '5.*.*' --sort=-v:refname | head -n1)
if [ -z "$LAST_TAG" ]; then
LAST_TAG="5.0.0"
COMPARE_REF="$(git rev-list --max-parents=0 HEAD)"
else
COMPARE_REF="$LAST_TAG"
fi
echo "Last tag: $LAST_TAG"
echo "Comparing from: $COMPARE_REF"
# Parse version components
MAJOR=$(echo "$LAST_TAG" | cut -d. -f1)
MINOR=$(echo "$LAST_TAG" | cut -d. -f2)
PATCH=$(echo "$LAST_TAG" | cut -d. -f3)
# Track the highest semver change and collect commits by type
HIGHEST_CHANGE="none"
MAJOR_COMMITS=""
MINOR_COMMITS=""
PATCH_COMMITS=""
# Get commits since last tag
while IFS= read -r line; do
if [ -z "$line" ]; then
continue
fi
COMMIT_HASH=$(echo "$line" | cut -d' ' -f1)
COMMIT_MSG=$(echo "$line" | cut -d' ' -f2-)
COMMIT_SHORT="${COMMIT_HASH:0:7}"
# Get commit body and look for semver tag
COMMIT_BODY=$(git log -1 --format="%b" "$COMMIT_HASH")
SEMVER_TAG=$(echo "$COMMIT_BODY" | grep -E 'semver:\s*\w+' | sed -E 's/.*semver:\s*(\w+).*/\1/' | head -n1 || true)
case "$SEMVER_TAG" in
major)
if [ "$HIGHEST_CHANGE" != "major" ]; then
HIGHEST_CHANGE="major"
fi
MAJOR_COMMITS="${MAJOR_COMMITS}- ${COMMIT_MSG}\n"
;;
minor)
if [ "$HIGHEST_CHANGE" != "major" ]; then
HIGHEST_CHANGE="minor"
fi
MINOR_COMMITS="${MINOR_COMMITS}- ${COMMIT_MSG}\n"
;;
patch)
if [ "$HIGHEST_CHANGE" = "none" ]; then
HIGHEST_CHANGE="patch"
fi
PATCH_COMMITS="${PATCH_COMMITS}- ${COMMIT_MSG}\n"
;;
esac
done < <(git log "${COMPARE_REF}..HEAD" --format="%H %s" --reverse)
# If no releasable changes, skip
if [ "$HIGHEST_CHANGE" = "none" ]; then
echo "No releasable changes found (no semver: major/minor/patch tags)"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
# Calculate new version
case "$HIGHEST_CHANGE" in
major)
MINOR=$((MINOR + 1))
PATCH=0
;;
minor|patch)
PATCH=$((PATCH + 1))
;;
esac
NEW_VERSION="${MAJOR}.${MINOR}.${PATCH}"
echo "New version: $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "should_release=true" >> $GITHUB_OUTPUT
# Generate changelog
CHANGELOG="## What's new in ${NEW_VERSION}\n\n"
if [ -n "$MAJOR_COMMITS" ]; then
CHANGELOG="${CHANGELOG}### Breaking changes\n${MAJOR_COMMITS}\n"
fi
if [ -n "$MINOR_COMMITS" ]; then
CHANGELOG="${CHANGELOG}### New features\n${MINOR_COMMITS}\n"
fi
if [ -n "$PATCH_COMMITS" ]; then
CHANGELOG="${CHANGELOG}### Fixes\n${PATCH_COMMITS}\n"
fi
# Write changelog to file for later use
echo -e "$CHANGELOG" > changelog.md
# Also output for GitHub Actions
{
echo 'changelog<<EOF'
echo -e "$CHANGELOG"
echo 'EOF'
} >> $GITHUB_OUTPUT
- name: build release
if: steps.version.outputs.should_release == 'true'
run: |
dotnet restore
dotnet build --no-restore --configuration Release /p:Version=${{ steps.version.outputs.version }}
- name: pack nuget
if: steps.version.outputs.should_release == 'true'
run: |
dotnet pack EliteAPI/EliteAPI.csproj --no-build --configuration Release /p:Version=${{ steps.version.outputs.version }} --output ./nupkg
- name: zip net48 release
if: steps.version.outputs.should_release == 'true'
shell: pwsh
run: |
Compress-Archive -Path "EliteVA/bin/Release/net48/*" -DestinationPath "EliteVA-${{ steps.version.outputs.version }}.zip"
- name: create git tag
if: steps.version.outputs.should_release == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}"
git push origin "${{ steps.version.outputs.version }}"
- name: create github release
if: steps.version.outputs.should_release == 'true'
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.version.outputs.version }}
name: v${{ steps.version.outputs.version }}
body_path: changelog.md
draft: false
prerelease: false
files: |
EliteVA-${{ steps.version.outputs.version }}.zip
# - name: publish to nuget
# if: steps.version.outputs.should_release == 'true'
# run: |
# dotnet nuget push ./nupkg/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate