-
-
Notifications
You must be signed in to change notification settings - Fork 0
213 lines (181 loc) · 6.67 KB
/
auto-release.yml
File metadata and controls
213 lines (181 loc) · 6.67 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
name: Automatic Release
on:
push:
tags:
- 'v*' # Trigger bei Tags wie v1.2.3
permissions:
contents: write # Needed to create releases and upload assets
actions: read # Needed to read workflow artifacts
packages: write # Needed for package publishing
id-token: write # Needed for PyPI trusted publishing (optional)
jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
release_id: ${{ steps.create_release.outputs.id }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0 # Vollständige Git-Historie für CHANGELOG
- name: Get tag version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Extract changelog for this version
id: changelog
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
# Extrahiere Release-Notes aus CHANGELOG.md
if [ -f "CHANGELOG.md" ]; then
# Suche nach der Version im CHANGELOG
awk -v version="$VERSION" '
/^## \[/ {
if ($0 ~ "\\[" version "\\]") {
found = 1
next
}
if (found) exit
}
found && /^## \[/ { exit }
found && !/^## \[/ { print }
' CHANGELOG.md > release_notes.txt
# Falls keine spezifischen Release-Notes gefunden wurden, erstelle Standard-Text
if [ ! -s release_notes.txt ]; then
echo "## Version $VERSION" > release_notes.txt
echo "" >> release_notes.txt
echo "### Änderungen" >> release_notes.txt
echo "- Neue Version veröffentlicht" >> release_notes.txt
echo "" >> release_notes.txt
echo "### Installation" >> release_notes.txt
echo "\`\`\`bash" >> release_notes.txt
echo "# Via pip" >> release_notes.txt
echo "pip install bash-script-maker==$VERSION" >> release_notes.txt
echo "" >> release_notes.txt
echo "\`\`\`" >> release_notes.txt
fi
else
echo "Keine CHANGELOG.md gefunden. Erstelle Standard-Release-Notes." > release_notes.txt
fi
# Zeige die Release-Notes zur Überprüfung
echo "Release-Notes für Version $VERSION:"
cat release_notes.txt
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.get_version.outputs.TAG_NAME }}
name: Release ${{ steps.get_version.outputs.VERSION }}
body_path: release_notes.txt
draft: false
prerelease: ${{ contains(steps.get_version.outputs.VERSION, '-') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload-assets:
name: Build and Upload Release Assets
needs: create-release
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Get version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine wheel setuptools
- name: Build Python packages
run: |
python setup.py sdist bdist_wheel
- name: Create source archive
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
git archive --format=tar.gz --prefix=bash-script-maker-$VERSION/ HEAD > bash-script-maker-$VERSION-source.tar.gz
- name: Upload Python wheel
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ steps.get_version.outputs.VERSION }}
files: |
dist/*.whl
dist/*.tar.gz
bash-script-maker-${{ steps.get_version.outputs.VERSION }}-source.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-pypi:
name: Publish to PyPI
needs: [create-release, build-and-upload-assets]
runs-on: ubuntu-latest
if: ${{ !contains(github.ref_name, '-') }} # Nur für stable releases, nicht pre-releases
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build packages
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
update-changelog:
name: Update Changelog
needs: [create-release, build-and-upload-assets]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Get version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/v}
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
- name: Update CHANGELOG.md
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
DATE=$(date +%Y-%m-%d)
# Erstelle temporäre Datei mit aktualisiertem CHANGELOG
awk -v version="$VERSION" -v date="$DATE" '
/^## \[Unreleased\]/ {
print $0
print ""
print "### Added"
print ""
print "### Changed"
print ""
print "### Fixed"
print ""
print "## [" version "] - " date
next
}
{ print }
' CHANGELOG.md > CHANGELOG_temp.md
mv CHANGELOG_temp.md CHANGELOG.md
- name: Commit CHANGELOG update
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add CHANGELOG.md
git commit -m "docs: update CHANGELOG for release v${{ steps.get_version.outputs.VERSION }}" || exit 0
git push