-
Notifications
You must be signed in to change notification settings - Fork 2
115 lines (100 loc) · 3.51 KB
/
Copy pathcreate-release.yml
File metadata and controls
115 lines (100 loc) · 3.51 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
name: Create Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version number (e.g., 1.0.2)'
required: true
type: string
release_type:
description: 'Type of release'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
prerelease:
description: 'Mark as pre-release'
required: false
default: false
type: boolean
jobs:
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate version format
run: |
if [[ ! "${{ inputs.version }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "❌ Invalid version format. Use semantic versioning (e.g., 1.0.2)"
exit 1
fi
echo "✅ Version format is valid: ${{ inputs.version }}"
- name: Check if tag exists
run: |
if git rev-parse "v${{ inputs.version }}" >/dev/null 2>&1; then
echo "❌ Tag v${{ inputs.version }} already exists"
exit 1
fi
echo "✅ Tag v${{ inputs.version }} is available"
- name: Update version files
run: |
# Update pyproject.toml
sed -i "s/version = \".*\"/version = \"${{ inputs.version }}\"/" pyproject.toml
# Update __init__.py
sed -i "s/__version__ = \".*\"/__version__ = \"${{ inputs.version }}\"/" dtop/__init__.py
echo "Updated version to ${{ inputs.version }}"
- name: Generate changelog entry
id: changelog
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -n "$LAST_TAG" ]; then
COMMITS=$(git log ${LAST_TAG}..HEAD --oneline --no-merges)
else
COMMITS=$(git log --oneline --no-merges -n 10)
fi
# Create changelog
CHANGELOG="## What's Changed\n\n"
if [ -n "$COMMITS" ]; then
while read -r line; do
if [ -n "$line" ]; then
CHANGELOG="${CHANGELOG}- ${line}\n"
fi
done <<< "$COMMITS"
else
CHANGELOG="${CHANGELOG}- Version bump to ${{ inputs.version }}\n"
fi
CHANGELOG="${CHANGELOG}\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${LAST_TAG}...v${{ inputs.version }}"
# Save to file for multiline output
echo -e "$CHANGELOG" > changelog.md
echo "Generated changelog for release"
- name: Commit version changes
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml dtop/__init__.py
git commit -m "Bump version to ${{ inputs.version }}"
git push
- name: Create and push tag
run: |
git tag -a "v${{ inputs.version }}" -m "Release v${{ inputs.version }}"
git push origin "v${{ inputs.version }}"
- name: Create GitHub Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ inputs.version }}
release_name: dtop v${{ inputs.version }}
body_path: changelog.md
draft: false
prerelease: ${{ inputs.prerelease }}