-
-
Notifications
You must be signed in to change notification settings - Fork 0
346 lines (287 loc) · 11.6 KB
/
auto-release-on-push.yml
File metadata and controls
346 lines (287 loc) · 11.6 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
name: Auto Release on Push
on:
push:
branches: [ main ]
paths-ignore:
- 'README.md'
- 'docs/**'
- '*.md'
permissions:
contents: write # Needed to create releases and push tags
actions: read # Needed to read workflow artifacts
packages: write # Needed for package publishing
id-token: write # Needed for PyPI trusted publishing (optional)
jobs:
check-for-release:
name: Check for Release Triggers
runs-on: ubuntu-latest
outputs:
should_release: ${{ steps.check.outputs.should_release }}
release_type: ${{ steps.check.outputs.release_type }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Check commit message for release triggers
id: check
run: |
COMMIT_MSG="${{ github.event.head_commit.message }}"
echo "Commit message: $COMMIT_MSG"
# Aktuelle Version lesen
CURRENT_VERSION=$(cat VERSION 2>/dev/null || echo "0.0.0")
echo "Current version: $CURRENT_VERSION"
# Letzten Git-Tag abrufen
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
LAST_TAG_VERSION=${LAST_TAG#v}
echo "Last tag version: $LAST_TAG_VERSION"
# Höchste Version verwenden
if [[ "$LAST_TAG_VERSION" > "$CURRENT_VERSION" ]]; then
CURRENT_VERSION="$LAST_TAG_VERSION"
echo "Using tag version as base: $CURRENT_VERSION"
fi
# Release-Typ bestimmen basierend auf Commit-Message
SHOULD_RELEASE="false"
RELEASE_TYPE=""
NEW_VERSION=""
# Behandle Merge-Commits speziell
if [[ "$COMMIT_MSG" =~ ^Merge[[:space:]]pull[[:space:]]request ]]; then
echo "Merge commit detected, analyzing PR content..."
# Für Merge-Commits: Minor release (neue Features zusammengeführt)
SHOULD_RELEASE="true"
RELEASE_TYPE="minor"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2+1".0"}')
elif [[ "$COMMIT_MSG" =~ ^(feat|feature)(\(.+\))?!: ]] || [[ "$COMMIT_MSG" =~ BREAKING[[:space:]]CHANGE ]]; then
# Major release (breaking change)
SHOULD_RELEASE="true"
RELEASE_TYPE="major"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1+1".0.0"}')
elif [[ "$COMMIT_MSG" =~ ^(feat|feature)(\(.+\))?: ]]; then
# Minor release (new feature)
SHOULD_RELEASE="true"
RELEASE_TYPE="minor"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2+1".0"}')
elif [[ "$COMMIT_MSG" =~ ^(fix|bugfix)(\(.+\))?: ]]; then
# Patch release (bug fix)
SHOULD_RELEASE="true"
RELEASE_TYPE="patch"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2"."$3+1}')
elif [[ "$COMMIT_MSG" =~ \[release\] ]]; then
# Manueller Release-Trigger
SHOULD_RELEASE="true"
RELEASE_TYPE="patch"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2"."$3+1}')
elif [[ "$COMMIT_MSG" =~ \[major\] ]]; then
SHOULD_RELEASE="true"
RELEASE_TYPE="major"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1+1".0.0"}')
elif [[ "$COMMIT_MSG" =~ \[minor\] ]]; then
SHOULD_RELEASE="true"
RELEASE_TYPE="minor"
NEW_VERSION=$(echo $CURRENT_VERSION | awk -F. '{print $1"."$2+1".0"}')
fi
# Überprüfen ob der berechnete Tag bereits existiert
if [[ "$SHOULD_RELEASE" == "true" ]] && git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then
echo "Tag v$NEW_VERSION already exists, skipping release"
SHOULD_RELEASE="false"
fi
echo "should_release=$SHOULD_RELEASE" >> $GITHUB_OUTPUT
echo "release_type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Should release: $SHOULD_RELEASE"
echo "Release type: $RELEASE_TYPE"
echo "New version: $NEW_VERSION"
create-release:
name: Create Automatic Release
needs: check-for-release
runs-on: ubuntu-latest
if: needs.check-for-release.outputs.should_release == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Update version files
run: |
NEW_VERSION="${{ needs.check-for-release.outputs.version }}"
# VERSION-Datei aktualisieren
echo "$NEW_VERSION" > VERSION
# __version__.py aktualisieren
cat > __version__.py << EOF
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Version information for Bash-Script-Maker
"""
__version__ = "$NEW_VERSION"
__version_info__ = ($(echo $NEW_VERSION | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1, \2, \3/'))
EOF
# pyproject.toml aktualisieren
sed -i "s/^version = .*/version = \"$NEW_VERSION\"/" pyproject.toml
- name: Generate release notes
id: release_notes
run: |
NEW_VERSION="${{ needs.check-for-release.outputs.version }}"
RELEASE_TYPE="${{ needs.check-for-release.outputs.release_type }}"
COMMIT_MSG="${{ github.event.head_commit.message }}"
# Basis Release-Notes erstellen
cat > release_notes.txt << EOF
## Version $NEW_VERSION
**Release-Typ:** $RELEASE_TYPE
### Änderungen
$COMMIT_MSG
### Installation
\`\`\`bash
# Via pip
pip install bash-script-maker==$NEW_VERSION
# Aus Quellcode
git clone https://github.com/securebitsorg/bash-script-maker.git
cd bash-script-maker
git checkout v$NEW_VERSION
./install.sh
\`\`\`
### Artefakte
- Python Wheel (.whl)
- Source Distribution (.tar.gz)
- Flatpak Bundle (.flatpak)
- Vollständiger Quellcode
EOF
echo "Release-Notes erstellt für Version $NEW_VERSION"
- name: Commit version changes
run: |
NEW_VERSION="${{ needs.check-for-release.outputs.version }}"
git add VERSION __version__.py pyproject.toml
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
- name: Create and push tag
run: |
NEW_VERSION="${{ needs.check-for-release.outputs.version }}"
# Überprüfen ob Tag bereits existiert
if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then
echo "Tag v$NEW_VERSION already exists, skipping tag creation"
exit 0
fi
git tag -a "v$NEW_VERSION" -m "Automatic release v$NEW_VERSION"
git push origin main
git push origin "v$NEW_VERSION"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check-for-release.outputs.version }}
name: Release ${{ needs.check-for-release.outputs.version }}
body_path: release_notes.txt
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-and-upload:
name: Build and Upload Assets
needs: [check-for-release, create-release]
runs-on: ubuntu-latest
if: needs.check-for-release.outputs.should_release == 'true'
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: v${{ needs.check-for-release.outputs.version }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install twine wheel setuptools
- name: Build Python packages
run: |
python setup.py sdist bdist_wheel
- name: Create source archive
run: |
VERSION=${{ needs.check-for-release.outputs.version }}
git archive --format=tar.gz --prefix=bash-script-maker-$VERSION/ HEAD > bash-script-maker-$VERSION-source.tar.gz
- name: Upload to release
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.check-for-release.outputs.version }}
files: |
dist/*.whl
dist/*.tar.gz
bash-script-maker-${{ needs.check-for-release.outputs.version }}-source.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-pypi:
name: Publish to PyPI
needs: [check-for-release, build-and-upload]
runs-on: ubuntu-latest
if: needs.check-for-release.outputs.should_release == 'true' && !contains(needs.check-for-release.outputs.version, '-')
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: v${{ needs.check-for-release.outputs.version }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install build dependencies
run: |
python -m pip install --upgrade pip
pip install twine wheel setuptools
- name: Build packages
run: python setup.py sdist bdist_wheel
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
publish-github-packages:
name: Publish to GitHub Packages
needs: [check-for-release, build-and-upload]
runs-on: ubuntu-latest
if: needs.check-for-release.outputs.should_release == 'true'
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: v${{ needs.check-for-release.outputs.version }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository_owner }}/bash-script-maker
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}},value=v${{ needs.check-for-release.outputs.version }}
type=semver,pattern={{major}}.{{minor}},value=v${{ needs.check-for-release.outputs.version }}
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max