1+ name : Create Release
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*.*.*'
7+ workflow_dispatch :
8+ inputs :
9+ version :
10+ description : ' Version number (e.g., 1.0.0)'
11+ required : true
12+ type : string
13+
14+ jobs :
15+ create-release :
16+ name : Create Release
17+ runs-on : ubuntu-latest
18+ permissions :
19+ contents : write
20+
21+ steps :
22+ - name : Checkout code
23+ uses : actions/checkout@v4
24+ with :
25+ fetch-depth : 0
26+
27+ - name : Set up Python
28+ uses : actions/setup-python@v5
29+ with :
30+ python-version : ' 3.11'
31+
32+ - name : Install dependencies
33+ run : |
34+ python -m pip install --upgrade pip
35+ pip install build wheel setuptools
36+
37+ - name : Determine version
38+ id : version
39+ run : |
40+ if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
41+ VERSION="${{ github.event.inputs.version }}"
42+ else
43+ VERSION=${GITHUB_REF#refs/tags/v}
44+ fi
45+ echo "version=$VERSION" >> $GITHUB_OUTPUT
46+ echo "Version: $VERSION"
47+
48+ - name : Build package
49+ run : |
50+ python -m build
51+
52+ - name : Generate changelog
53+ id : changelog
54+ run : |
55+ echo "# Changelog for v${{ steps.version.outputs.version }}" > CHANGELOG_RELEASE.md
56+ echo "" >> CHANGELOG_RELEASE.md
57+
58+ # Get commits since last tag
59+ LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
60+ if [ -z "$LAST_TAG" ]; then
61+ echo "## All Changes" >> CHANGELOG_RELEASE.md
62+ git log --pretty=format:"- %s (%h)" >> CHANGELOG_RELEASE.md
63+ else
64+ echo "## Changes since $LAST_TAG" >> CHANGELOG_RELEASE.md
65+ git log $LAST_TAG..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG_RELEASE.md
66+ fi
67+
68+ echo "" >> CHANGELOG_RELEASE.md
69+ echo "## Installation" >> CHANGELOG_RELEASE.md
70+ echo '```bash' >> CHANGELOG_RELEASE.md
71+ echo "pip install backtrader==${{ steps.version.outputs.version }}" >> CHANGELOG_RELEASE.md
72+ echo '```' >> CHANGELOG_RELEASE.md
73+
74+ - name : Create GitHub Release
75+ uses : softprops/action-gh-release@v1
76+ with :
77+ tag_name : v${{ steps.version.outputs.version }}
78+ name : Release v${{ steps.version.outputs.version }}
79+ body_path : CHANGELOG_RELEASE.md
80+ draft : false
81+ prerelease : false
82+ files : |
83+ dist/*.whl
84+ dist/*.tar.gz
85+ env :
86+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
87+
88+ - name : Upload release artifacts
89+ uses : actions/upload-artifact@v4
90+ with :
91+ name : release-artifacts-${{ steps.version.outputs.version }}
92+ path : dist/
93+ retention-days : 90
0 commit comments