Skip to content

Commit 2a58732

Browse files
refactor: streamline badge generation process and improve error handling
1 parent d663e1e commit 2a58732

File tree

2 files changed

+111
-203
lines changed

2 files changed

+111
-203
lines changed

.github/workflows/test-action.yml

Lines changed: 5 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ on:
99
branches: [ main ]
1010
paths:
1111
- 'action.yml'
12-
- 'update_badges.py'
1312
- '.github/workflows/test-action.yml'
1413
push:
1514
branches: [ main ]
1615
paths:
1716
- 'action.yml'
18-
- 'update_badges.py'
1917
- '.github/workflows/test-action.yml'
20-
workflow_dispatch: # Allow manual trigger
21-
18+
19+
#Allow manual trigger
20+
workflow_dispatch: {}
21+
2222
jobs:
2323
# Test basic linting functionality
2424
test-basic-linting:
@@ -113,171 +113,9 @@ jobs:
113113
- name: Run Python Linting (With Requirements)
114114
uses: ./
115115
with:
116-
python-version: '3.11'
116+
python-version: '3.10'
117117
requirements-file: 'requirements.txt'
118118

119-
# Test badge generation
120-
test-badge-generation:
121-
name: Test Badge Generation
122-
runs-on: ubuntu-latest
123-
permissions:
124-
contents: read
125-
steps:
126-
- name: Checkout repository
127-
uses: actions/checkout@v5
128-
129-
- name: Create test Python file
130-
run: |
131-
mkdir -p test_project
132-
cat > test_project/sample.py << 'EOF'
133-
"""Sample Python file for testing."""
134-
135-
def hello_world():
136-
"""Print hello world."""
137-
print("Hello, World!")
138-
139-
if __name__ == "__main__":
140-
hello_world()
141-
EOF
142-
143-
- name: Run Python Linting (Badge Generation)
144-
uses: ./
145-
with:
146-
python-version: '3.11'
147-
generate-badges: 'true'
148-
badges-directory: '.github/test-badges'
149-
150-
- name: Verify badges were created
151-
run: |
152-
if [ ! -f .github/test-badges/pylint.svg ]; then
153-
echo "Error: pylint badge not created"
154-
exit 1
155-
fi
156-
if [ ! -f .github/test-badges/black.svg ]; then
157-
echo "Error: black badge not created"
158-
exit 1
159-
fi
160-
if [ ! -f .github/test-badges/mypy.svg ]; then
161-
echo "Error: mypy badge not created"
162-
exit 1
163-
fi
164-
echo "✓ All badges created successfully"
165-
166-
# Test README update functionality
167-
test-readme-update:
168-
name: Test README Update
169-
runs-on: ubuntu-latest
170-
permissions:
171-
contents: read
172-
steps:
173-
- name: Checkout repository
174-
uses: actions/checkout@v5
175-
176-
- name: Create test files
177-
run: |
178-
mkdir -p test_project
179-
cat > test_project/sample.py << 'EOF'
180-
"""Sample Python file for testing."""
181-
182-
def hello_world():
183-
"""Print hello world."""
184-
print("Hello, World!")
185-
186-
if __name__ == "__main__":
187-
hello_world()
188-
EOF
189-
190-
cat > TEST_README.md << 'EOF'
191-
# Test Project
192-
193-
This is a test README.
194-
EOF
195-
196-
- name: Run Python Linting (README Update)
197-
uses: ./
198-
with:
199-
python-version: '3.11'
200-
generate-badges: 'true'
201-
update-readme: 'true'
202-
readme-path: 'TEST_README.md'
203-
badges-directory: '.github/test-badges'
204-
badge-style: 'path'
205-
206-
- name: Verify README was updated
207-
run: |
208-
if ! grep -q "linting-badges-start" TEST_README.md; then
209-
echo "Error: README not updated with badge markers"
210-
exit 1
211-
fi
212-
if ! grep -q "pylint" TEST_README.md; then
213-
echo "Error: README missing pylint badge"
214-
exit 1
215-
fi
216-
echo "✓ README updated successfully"
217-
cat TEST_README.md
218-
219-
# Test update_badges.py script directly
220-
test-update-badges-script:
221-
name: Test update_badges.py Script
222-
runs-on: ubuntu-latest
223-
permissions:
224-
contents: read
225-
steps:
226-
- name: Checkout repository
227-
uses: actions/checkout@v5
228-
229-
- name: Setup Python
230-
uses: actions/setup-python@v6
231-
with:
232-
python-version: '3.11'
233-
234-
- name: Create test environment
235-
run: |
236-
mkdir -p test_badges
237-
cat > test_readme.md << 'EOF'
238-
# Test Project
239-
240-
Some content here.
241-
EOF
242-
243-
# Create dummy badge files
244-
echo '<svg></svg>' > test_badges/pylint.svg
245-
echo '<svg></svg>' > test_badges/black.svg
246-
echo '<svg></svg>' > test_badges/mypy.svg
247-
248-
- name: Test script with relative paths
249-
run: |
250-
python3 update_badges.py \
251-
--readme test_readme.md \
252-
--badges-dir test_badges
253-
254-
if ! grep -q "linting-badges-start" test_readme.md; then
255-
echo "Error: Script did not update README"
256-
exit 1
257-
fi
258-
echo "✓ Script test (relative paths) passed"
259-
260-
- name: Test script with GitHub URLs
261-
run: |
262-
cat > test_readme2.md << 'EOF'
263-
# Test Project
264-
265-
Some content here.
266-
EOF
267-
268-
python3 update_badges.py \
269-
--readme test_readme2.md \
270-
--badges-dir test_badges \
271-
--use-url \
272-
--github-repo thoughtparametersllc/python-linting
273-
274-
if ! grep -q "raw.githubusercontent.com" test_readme2.md; then
275-
echo "Error: Script did not use GitHub URLs"
276-
exit 1
277-
fi
278-
echo "✓ Script test (GitHub URLs) passed"
279-
cat test_readme2.md
280-
281119
# Test with different Python versions
282120
test-python-versions:
283121
name: Test Python ${{ matrix.python-version }}
@@ -320,9 +158,6 @@ jobs:
320158
- test-basic-linting
321159
- test-custom-options
322160
- test-requirements-file
323-
- test-badge-generation
324-
- test-readme-update
325-
- test-update-badges-script
326161
- test-python-versions
327162
steps:
328163
- name: All tests passed
@@ -333,7 +168,4 @@ jobs:
333168
echo " ✓ Basic linting functionality"
334169
echo " ✓ Custom linting options"
335170
echo " ✓ Requirements file handling"
336-
echo " ✓ Badge generation"
337-
echo " ✓ README updates"
338-
echo " ✓ update_badges.py script"
339171
echo " ✓ Multiple Python versions (3.9-3.12)"

0 commit comments

Comments
 (0)