-
Notifications
You must be signed in to change notification settings - Fork 131
125 lines (103 loc) · 3.84 KB
/
auto-release.yml
File metadata and controls
125 lines (103 loc) · 3.84 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
# Steps to trigger the release:
# # 1. Switch to main branch
# git checkout main
# # 2. Ensure main is up to date
# git pull origin main
# # 3. Create tag
# git tag v1.0.0
# # 4. Push tag to remote
# git push origin v1.0.0
name: Auto Release
on:
push:
tags:
- 'v*.*.*'
- 'v*.*.*-*'
permissions:
contents: write
pull-requests: write
issues: write
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Get version from tag
id: version
run: |
echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
echo "VERSION_WITHOUT_V=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Generate changelog
id: changelog
run: |
# Get the previous tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
# Generate changelog between tags
if [ -z "$PREVIOUS_TAG" ]; then
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "## What's Changed" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "Initial release 🎉" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
else
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "## What's Changed" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
# Get commit messages
git log ${PREVIOUS_TAG}..HEAD --pretty=format:"* %s by @%an in %h" | while read line; do
echo "$line" >> $GITHUB_OUTPUT
done
echo "" >> $GITHUB_OUTPUT
echo "" >> $GITHUB_OUTPUT
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/${PREVIOUS_TAG}...${{ steps.version.outputs.VERSION }}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
fi
- name: Build distribution
run: |
python -m build
ls -la dist/
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.version.outputs.VERSION }}
release_name: Release ${{ steps.version.outputs.VERSION }}
body: |
# Release ${{ steps.version.outputs.VERSION }}
${{ steps.changelog.outputs.CHANGELOG }}
## Installation
You can install this version directly from the source:
```bash
pip install git+https://github.com/${{ github.repository }}@${{ steps.version.outputs.VERSION }}
```
Or download the source code and install locally:
```bash
tar -xzf <archive>.tar.gz
cd <directory>
pip install .
```
draft: false
prerelease: ${{ contains(steps.version.outputs.VERSION, '-') }}
- name: Post release summary
run: |
echo "### 🎉 Release ${{ steps.version.outputs.VERSION }} Created Successfully!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Release URL**: https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Assets**:" >> $GITHUB_STEP_SUMMARY
echo "- Source code (tar.gz)" >> $GITHUB_STEP_SUMMARY
echo "- Source code (zip)" >> $GITHUB_STEP_SUMMARY
ls -la dist/ | grep -E "\.(tar\.gz|whl)$" | awk '{print "- "$9}' >> $GITHUB_STEP_SUMMARY