-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (183 loc) · 5.95 KB
/
Copy pathmain.yml
File metadata and controls
222 lines (183 loc) · 5.95 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
name: CI/CD
on:
push:
branches: [ main, develop ]
tags:
- 'v*'
pull_request:
branches: [ main, develop ]
workflow_dispatch:
inputs:
test_pypi:
description: 'Publish to Test PyPI instead of PyPI'
required: false
type: boolean
default: false
jobs:
test:
name: Test on macOS
runs-on: macos-latest
strategy:
matrix:
python-version: ['3.12', '3.13']
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies
run: uv sync
- name: Run linting (if configured)
run: |
# Add linting commands here if you add ruff or similar
echo "Linting step placeholder"
continue-on-error: true
- name: Run tests
run: uv run pytest -v
- name: Run tests with coverage
run: uv run pytest --cov=screenshots_cleaner --cov-report=xml --cov-report=term
- name: Check coverage threshold
run: |
COVERAGE=$(uv run pytest --cov=screenshots_cleaner --cov-report=term | grep "TOTAL" | awk '{print $4}' | sed 's/%//')
echo "Coverage: ${COVERAGE}%"
if [ "${COVERAGE%.*}" -lt 90 ]; then
echo "::warning::Coverage is below 90% (${COVERAGE}%)"
exit 1
fi
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
continue-on-error: true
integration-test:
name: Integration Tests
runs-on: macos-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.12
- name: Install dependencies
run: uv sync
- name: Run integration tests
run: uv run pytest tests/integration_test.py -v
- name: Test CLI commands
run: |
# Create test directory with dummy screenshots
mkdir -p /tmp/test-screenshots
touch "/tmp/test-screenshots/Screen Shot 2024-01-01.png"
# Test preview command
uv run screenshot-cleaner preview --path=/tmp/test-screenshots --days=1
# Test clean with dry-run
uv run screenshot-cleaner clean --path=/tmp/test-screenshots --days=1 --dry-run
# Cleanup
rm -rf /tmp/test-screenshots
build:
name: Build Distribution
needs: [test, integration-test]
runs-on: ubuntu-latest
# Only build on tags or manual workflow dispatch
if: startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true
- name: Set up Python
run: uv python install 3.12
- name: Build package
run: uv build
- name: Store distribution packages
uses: actions/upload-artifact@v4
with:
name: python-package-distributions
path: dist/
publish-to-pypi:
name: Publish to PyPI
needs: build
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/screenshots-cleaner
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
publish-to-test-pypi:
name: Publish to Test PyPI
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.test_pypi
runs-on: ubuntu-latest
environment:
name: test-pypi
url: https://test.pypi.org/p/screenshot-cleaner
permissions:
id-token: write
steps:
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Publish to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
github-release:
name: Create GitHub Release
needs: publish-to-pypi
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download distributions
uses: actions/download-artifact@v4
with:
name: python-package-distributions
path: dist/
- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
- name: Extract changelog for version
id: changelog
run: |
VERSION=${{ steps.get_version.outputs.VERSION }}
# Extract the section for this version from CHANGELOG.md
CHANGELOG=$(sed -n "/## \[$VERSION\]/,/## \[/p" CHANGELOG.md | sed '$d')
if [ -z "$CHANGELOG" ]; then
CHANGELOG="Release $VERSION"
fi
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.changelog.outputs.CHANGELOG }}
files: dist/*
draft: false
prerelease: false