-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (114 loc) · 4.77 KB
/
release.yml
File metadata and controls
129 lines (114 loc) · 4.77 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
name: 🎫 Auto Release
on:
push:
tags:
- 'v*' # Trigger bei: v1.0.0, v1.2.3, etc.
workflow_dispatch:
inputs:
tag:
description: 'Tag, der released werden soll (z. B. v1.2.3)'
required: true
type: string
create_tag:
description: 'Neuen Tag erstellen, falls er noch nicht existiert'
required: false
type: boolean
default: false
ref:
description: 'Branch/Commit für den neuen Tag (nur falls oben aktiviert)'
required: false
type: string
default: main
# Verhindert, dass sich zwei Release-Läufe für denselben Tag überschneiden
concurrency:
group: release-${{ inputs.tag || github.ref_name }}
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
# Tag ermitteln — funktioniert sowohl bei Tag-Push als auch bei manueller Ausführung
- name: Tag ermitteln
id: tag
run: |
set -euo pipefail
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
TAG="${{ inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
if [[ ! "$TAG" =~ ^v ]]; then
echo "::error::Tag '$TAG' entspricht nicht dem erwarteten Muster 'v*'."
exit 1
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
# Checkout des Tags (falls vorhanden) bzw. des angegebenen Branches (für neue Tags).
# fetch-depth: 0 holt komplette History + alle Tags.
- name: Checkout
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref || github.ref }}
fetch-depth: 0
# Prüft, ob der Tag existiert. Falls nicht:
# - create_tag aktiviert → Tag wird aus 'ref' erstellt und gepusht
# - create_tag deaktiviert → Abbruch mit Hinweis
- name: Tag prüfen & ggf. erstellen
run: |
set -euo pipefail
TAG="${{ steps.tag.outputs.tag }}"
if git rev-parse -q --verify "refs/tags/$TAG" >/dev/null; then
echo "✅ Tag '$TAG' existiert bereits."
exit 0
fi
if [ "${{ inputs.create_tag }}" != "true" ]; then
echo "::error::Tag '$TAG' existiert nicht. Workflow erneut ausführen und die Option 'Neuen Tag erstellen' aktivieren — der Tag wird dann aus '${{ inputs.ref }}' erstellt."
exit 1
fi
echo "🏷️ Tag '$TAG' existiert nicht — wird aus '${{ inputs.ref }}' erstellt."
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$TAG" -m "Release $TAG"
git push origin "refs/tags/$TAG"
echo "✅ Tag '$TAG' erstellt und gepusht."
- name: Modified files & Commits ermitteln
run: |
set -euo pipefail
CURR_TAG="${{ steps.tag.outputs.tag }}"
PREV_TAG=$(git describe --tags --abbrev=0 "${CURR_TAG}^" 2>/dev/null || echo "")
REPO="${GITHUB_REPOSITORY}"
if [ -z "$PREV_TAG" ]; then
RANGE="$CURR_TAG"
printf '> ⚠️ First Release – no comparison with previous tag possible.\n\n' > release_body.md
else
RANGE="$PREV_TAG..$CURR_TAG"
printf '> 🔍 Comparison: [`%s` → `%s`](https://github.com/%s/compare/%s...%s)\n\n' \
"$PREV_TAG" "$CURR_TAG" "$REPO" "$PREV_TAG" "$CURR_TAG" > release_body.md
fi
# Commits
# Use --pretty=format:"...%n" so every line (including the last) ends
# with a newline. The previous `while read` loop silently dropped the
# most recent commit, because `read` returns non-zero on a final line
# without a trailing newline — the loop body was skipped for it.
echo "## 📝 Commits" >> release_body.md
git log "$RANGE" \
--pretty=format:"- [\`%h\`](https://github.com/$REPO/commit/%H) %s (%an)%n" \
>> release_body.md
# Modified files
printf '\n\n## 📂 Modified files\n' >> release_body.md
echo '```' >> release_body.md
git diff --name-status "$RANGE" \
| sed 's/^A\t/✅ NEW /;s/^M\t/✏️ CHANGED /;s/^D\t/🗑️ DELETED /' \
>> release_body.md
echo '```' >> release_body.md
# Statistics
STATS=$(git diff --shortstat "$RANGE" 2>/dev/null || echo "First Release")
printf '\n---\n📊 **%s**\n' "$STATS" >> release_body.md
- name: GitHub Release erstellen
uses: softprops/action-gh-release@v3
with:
tag_name: ${{ steps.tag.outputs.tag }}
body_path: release_body.md
generate_release_notes: true
token: ${{ secrets.GITHUB_TOKEN }}