-
Notifications
You must be signed in to change notification settings - Fork 1
203 lines (175 loc) · 5.87 KB
/
auto-release.yml
File metadata and controls
203 lines (175 loc) · 5.87 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
name: Auto Release
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
permissions:
contents: write
packages: write
pull-requests: write
issues: write
jobs:
analyze-changes:
runs-on: ubuntu-latest
outputs:
should-release: ${{ steps.changes.outputs.should-release }}
release-type: ${{ steps.changes.outputs.release-type }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Analyze commit messages
id: changes
run: |
# Get commits since last tag
LAST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ -z "$LAST_TAG" ]; then
echo "should-release=true" >> $GITHUB_OUTPUT
echo "release-type=minor" >> $GITHUB_OUTPUT
echo "First release - suggesting minor version"
exit 0
fi
# Check commit messages for conventional commits
COMMITS=$(git log --oneline ${LAST_TAG}..HEAD --pretty=format:"%s")
HAS_BREAKING=false
HAS_FEAT=false
HAS_FIX=false
while IFS= read -r commit; do
if [[ $commit =~ ^feat(\(.+\))?!:|^[^:]+!:|BREAKING[[:space:]]CHANGE ]]; then
HAS_BREAKING=true
elif [[ $commit =~ ^feat(\(.+\))?: ]]; then
HAS_FEAT=true
elif [[ $commit =~ ^fix(\(.+\))?: ]]; then
HAS_FIX=true
fi
done <<< "$COMMITS"
# Determine release type
if [ "$HAS_BREAKING" = true ]; then
RELEASE_TYPE="major"
elif [ "$HAS_FEAT" = true ]; then
RELEASE_TYPE="minor"
elif [ "$HAS_FIX" = true ]; then
RELEASE_TYPE="patch"
else
RELEASE_TYPE="none"
fi
# Only release if there are significant changes
if [ "$RELEASE_TYPE" != "none" ]; then
echo "should-release=true" >> $GITHUB_OUTPUT
echo "release-type=$RELEASE_TYPE" >> $GITHUB_OUTPUT
echo "Suggesting $RELEASE_TYPE release"
else
echo "should-release=false" >> $GITHUB_OUTPUT
echo "release-type=none" >> $GITHUB_OUTPUT
echo "No significant changes - skipping release"
fi
auto-release:
runs-on: ubuntu-latest
needs: analyze-changes
if: needs.analyze-changes.outputs.should-release == 'true' && github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "latest"
enable-cache: true
- name: Set up Python
run: uv python install 3.11
- name: Install dependencies
run: uv sync --dev
- name: Run tests
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
POSTGRES_SERVER: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: test_db
S3_ACCESS_KEY_ID: test_key
S3_ACCESS_KEY: test_secret
S3_BUCKET: test-bucket
REDIS_HOST: localhost
REDIS_PORT: 6379
ENVIRONMENT: testing
DEBUG: false
LOG_LEVEL: WARNING
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
run: |
uv run pytest src/tests/ -v --tb=short
- name: Configure git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump version and create release
run: |
chmod +x scripts/bump-version.sh
RELEASE_TYPE="${{ needs.analyze-changes.outputs.release-type }}"
./scripts/bump-version.sh $RELEASE_TYPE "Auto-release: $RELEASE_TYPE version bump"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
pr-preview:
runs-on: ubuntu-latest
needs: analyze-changes
if: github.event_name == 'pull_request'
steps:
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const { should-release, release-type } = ${{ toJson(needs.analyze-changes.outputs) }};
let message;
if (should-release === 'true') {
message = `🎯 **Release Preview**
This PR will trigger a **${release-type}** release when merged to main.
### What this means:
- Version will be bumped (${release-type})
- GitHub release will be created
- Python package will be built
- Changelog will be updated
### Release Type Explanation:
- **major**: Breaking changes (x.0.0)
- **minor**: New features (0.x.0)
- **patch**: Bug fixes (0.0.x)`;
} else {
message = `📋 **Release Preview**
This PR will **not** trigger an automatic release.
No significant changes detected based on commit messages.
To trigger a release, use conventional commit messages:
- \`feat:\` for new features (minor release)
- \`fix:\` for bug fixes (patch release)
- \`feat!:\` or \`BREAKING CHANGE:\` for breaking changes (major release)`;
}
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: message
});