Skip to content

Commit f15e4c5

Browse files
committed
Update publish/release workflow
- Switch to trusted publishing on tag push - Add changelog gen based on changelog commits - Add pre-releases - Push to GitHub releases - Automate package version injection via git-tags This makes the version-info in .csproj files irrelevant Removes the need for github-actions to push automated commits Changelog(misc)
1 parent cc38c26 commit f15e4c5

File tree

5 files changed

+545
-111
lines changed

5 files changed

+545
-111
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
# Usage: generate-changelog.sh <output_file> [tag_or_range]
5+
# If tag_or_range is empty, generates from latest tag to HEAD
6+
7+
OUTPUT_FILE="$1"
8+
TAG_OR_RANGE="${2:-}"
9+
10+
mkdir -p "$(dirname "$OUTPUT_FILE")"
11+
12+
if [[ -z "$TAG_OR_RANGE" ]]; then
13+
LATEST_TAG=$(git describe --tags --abbrev=0 --match "v*.*.*" 2>/dev/null || echo "")
14+
if [[ -z "$LATEST_TAG" ]]; then
15+
LOG_RANGE=""
16+
CONTEXT_MSG="All unreleased changes:"
17+
VERSION_TITLE="Development Version"
18+
else
19+
LOG_RANGE="$LATEST_TAG..HEAD"
20+
CONTEXT_MSG="Changes since $LATEST_TAG:"
21+
VERSION_TITLE="Development Version"
22+
fi
23+
else
24+
VERSION="$TAG_OR_RANGE"
25+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 --match "v*.*.*" "$TAG_OR_RANGE^" 2>/dev/null || echo "")
26+
if [[ -z "$PREVIOUS_TAG" ]]; then
27+
LOG_RANGE="$TAG_OR_RANGE"
28+
CONTEXT_MSG="All changes in this release:"
29+
else
30+
LOG_RANGE="$PREVIOUS_TAG..$TAG_OR_RANGE"
31+
CONTEXT_MSG="Changes since $PREVIOUS_TAG:"
32+
fi
33+
VERSION_TITLE="Version ${VERSION#v}"
34+
fi
35+
36+
mapfile -t COMMITS < <(git log --pretty=format:'%H' $LOG_RANGE)
37+
FEATURES=""
38+
FIXES=""
39+
MISC=""
40+
41+
for commit_hash in "${COMMITS[@]}"; do
42+
commit_msg=$(git log -1 --pretty=format:'%s' "$commit_hash")
43+
commit_body=$(git log -1 --pretty=format:'%b' "$commit_hash")
44+
45+
changelog_type=""
46+
47+
if echo "$commit_msg" | grep -iqE 'changelog[(: ]'; then
48+
if echo "$commit_msg" | grep -iqE 'changelog\((feature|feat)\)'; then
49+
changelog_type="feature"
50+
elif echo "$commit_msg" | grep -iqE 'changelog\((fix)\)'; then
51+
changelog_type="fix"
52+
elif echo "$commit_msg" | grep -iqE 'changelog\((misc)\)'; then
53+
changelog_type="misc"
54+
fi
55+
fi
56+
57+
if [ -z "$changelog_type" ]; then
58+
if echo "$commit_body" | grep -iqE 'changelog[(: ]'; then
59+
if echo "$commit_body" | grep -iqE 'changelog\((feature|feat)\)'; then
60+
changelog_type="feature"
61+
elif echo "$commit_body" | grep -iqE 'changelog\((fix)\)'; then
62+
changelog_type="fix"
63+
elif echo "$commit_body" | grep -iqE 'changelog\((misc)\)'; then
64+
changelog_type="misc"
65+
fi
66+
fi
67+
fi
68+
69+
if [ -z "$changelog_type" ]; then
70+
if echo "$commit_msg" | grep -iqE '^(feat|feature)(\(.*\))?:'; then
71+
changelog_type="feature"
72+
commit_msg=$(echo "$commit_msg" | sed -E 's/^(feat|feature)(\(.*\))?:[[:space:]]*//')
73+
elif echo "$commit_msg" | grep -iqE '^fix(\(.*\))?:'; then
74+
changelog_type="fix"
75+
commit_msg=$(echo "$commit_msg" | sed -E 's/^fix(\(.*\))?:[[:space:]]*//')
76+
elif echo "$commit_msg" | grep -iqE '^(chore|docs|style|refactor|perf|test)(\(.*\))?:'; then
77+
changelog_type="misc"
78+
commit_msg=$(echo "$commit_msg" | sed -E 's/^(chore|docs|style|refactor|perf|test)(\(.*\))?:[[:space:]]*//')
79+
fi
80+
fi
81+
82+
if [ -n "$changelog_type" ]; then
83+
body_content=$(echo "$commit_body" | awk 'BEGIN{IGNORECASE=1} !/changelog[(: ]/ && NF')
84+
entry="- $commit_msg"
85+
if [ -n "$body_content" ]; then
86+
entry=$(printf "%s\n%s" "$entry" "$(echo "$body_content" | sed 's/^/ /')")
87+
fi
88+
if [ "$changelog_type" = "feature" ]; then
89+
FEATURES=$(printf "%s\n%s" "$FEATURES" "$entry")
90+
elif [ "$changelog_type" = "fix" ]; then
91+
FIXES=$(printf "%s\n%s" "$FIXES" "$entry")
92+
else
93+
MISC=$(printf "%s\n%s" "$MISC" "$entry")
94+
fi
95+
fi
96+
done
97+
98+
{
99+
echo "# Changelog for $VERSION_TITLE"
100+
echo ""
101+
if [[ -z "$TAG_OR_RANGE" ]]; then
102+
echo "This page shows unreleased changes in the development version."
103+
else
104+
echo "Release Date: $(date +'%Y-%m-%d')"
105+
fi
106+
echo ""
107+
echo "$CONTEXT_MSG"
108+
echo ""
109+
110+
if [[ -n "$FEATURES" ]]; then
111+
echo "## ✨ New Features"
112+
echo ""
113+
echo "$FEATURES"
114+
echo ""
115+
fi
116+
117+
if [[ -n "$FIXES" ]]; then
118+
echo "## 🐛 Fixes"
119+
echo ""
120+
echo "$FIXES"
121+
echo ""
122+
fi
123+
124+
if [[ -n "$MISC" ]]; then
125+
echo "## 🔧 Miscellaneous"
126+
echo ""
127+
echo "$MISC"
128+
echo ""
129+
fi
130+
131+
if [[ -z "$FEATURES" && -z "$FIXES" && -z "$MISC" ]]; then
132+
if [[ -z "$TAG_OR_RANGE" ]]; then
133+
echo "No changes yet."
134+
else
135+
echo "No changes."
136+
fi
137+
fi
138+
} > "$OUTPUT_FILE"
139+
140+
echo "Changelog generated: $OUTPUT_FILE"
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Generate Changelog
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
mode:
7+
required: true
8+
type: string
9+
description: 'Mode of operation: "release" or "snapshot"'
10+
tag_name:
11+
required: false
12+
type: string
13+
description: "Current tag name (required for release mode)"
14+
outputs:
15+
changelog:
16+
description: "Generated changelog"
17+
value: ${{ jobs.generate.outputs.changelog }}
18+
19+
jobs:
20+
generate:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
changelog: ${{ steps.generate_changelog.outputs.changelog }}
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v4
27+
with:
28+
fetch-depth: 0
29+
30+
- name: Generate Changelog
31+
id: generate_changelog
32+
shell: bash
33+
run: |
34+
chmod +x .github/scripts/generate-changelog.sh
35+
OUTFILE=changelog_output.md
36+
if [[ "${{ inputs.mode }}" == "release" ]]; then
37+
.github/scripts/generate-changelog.sh "$OUTFILE" "${{ inputs.tag_name }}"
38+
else
39+
.github/scripts/generate-changelog.sh "$OUTFILE"
40+
fi
41+
echo "changelog<<CHANGELOG_EOF" >> $GITHUB_OUTPUT
42+
cat "$OUTFILE" >> $GITHUB_OUTPUT
43+
echo "CHANGELOG_EOF" >> $GITHUB_OUTPUT

.github/workflows/publish-nuget.yml

Lines changed: 0 additions & 111 deletions
This file was deleted.

0 commit comments

Comments
 (0)