Skip to content

Commit 3019feb

Browse files
authored
Refactor SwiftLint workflow for accessibility checks
Updated the SwiftLint workflow to include accessibility checks and removed unused jobs related to accessibility audits.
1 parent bfb4d57 commit 3019feb

File tree

1 file changed

+6
-126
lines changed

1 file changed

+6
-126
lines changed

.github/workflows/swiftlint.yml

Lines changed: 6 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
name: Accessibility Checks
1+
name: SwiftLint a11y Checks
22
on:
33
pull_request:
4-
types: [opened, synchronize, reopened]
4+
push:
5+
branches: [main, develop]
56

67
jobs:
7-
swiftlint:
8-
name: SwiftLint A11y Rules
8+
lint:
99
runs-on: macos-latest
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v4
13-
with:
14-
fetch-depth: 0 # Fetch full history for comparison
1513

1614
- name: Cache SwiftLint
1715
uses: actions/cache@v3
@@ -22,123 +20,5 @@ jobs:
2220
- name: Install SwiftLint
2321
run: brew install swiftlint
2422

25-
- name: Get changed Swift files
26-
id: changed-files
27-
uses: tj-actions/changed-files@v41
28-
with:
29-
files: |
30-
**/*.swift
31-
32-
- name: Run SwiftLint on changed files
33-
if: steps.changed-files.outputs.any_changed == 'true'
34-
run: |
35-
echo "Running SwiftLint on changed files..."
36-
echo "${{ steps.changed-files.outputs.all_changed_files }}" | xargs swiftlint lint --strict --reporter github-actions-logging
37-
38-
- name: No files to check
39-
if: steps.changed-files.outputs.any_changed != 'true'
40-
run: echo "No Swift files changed in this PR"
41-
42-
accessibility-audit:
43-
name: Custom A11y Pattern Check
44-
runs-on: ubuntu-latest
45-
steps:
46-
- name: Checkout
47-
uses: actions/checkout@v4
48-
with:
49-
fetch-depth: 0
50-
51-
- name: Get changed Swift files
52-
id: changed-files
53-
uses: tj-actions/changed-files@v41
54-
with:
55-
files: |
56-
**/*.swift
57-
58-
- name: Check for accessibility issues
59-
if: steps.changed-files.outputs.any_changed == 'true'
60-
run: |
61-
echo "Checking accessibility patterns in changed files..."
62-
63-
EXIT_CODE=0
64-
65-
# Check each changed Swift file
66-
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
67-
echo "Checking: $file"
68-
69-
# Check for Images without labels (excluding known valid patterns)
70-
if grep -n "Image(" "$file" | grep -v "accessibilityLabel" | grep -v "accessibilityHidden" | grep -v "combine" | grep -v "swiftlint:disable"; then
71-
echo "::error file=$file::Found Image without accessibility label"
72-
EXIT_CODE=1
73-
fi
74-
75-
# Check for Buttons without text or labels
76-
if grep -n "Button {" "$file" | grep -v "accessibilityLabel" | grep -v '"' | grep -v "Text(" | grep -v "swiftlint:disable"; then
77-
echo "::warning file=$file::Found Button that may be missing accessibility label"
78-
fi
79-
80-
# Check for empty Text views
81-
if grep -n 'Text("")' "$file"; then
82-
echo "::error file=$file::Found empty Text() view - bad for accessibility"
83-
EXIT_CODE=1
84-
fi
85-
86-
# Check for tap gestures without labels
87-
if grep -n "onTapGesture" "$file" | grep -v "accessibilityLabel" | grep -v "accessibilityAction" | grep -v "swiftlint:disable"; then
88-
echo "::warning file=$file::Found onTapGesture without accessibility label or action"
89-
fi
90-
91-
# Check for generic labels
92-
if grep -n 'accessibilityLabel("Button")\|accessibilityLabel("Image")\|accessibilityLabel("Icon")' "$file"; then
93-
echo "::warning file=$file::Found generic accessibility label - be more descriptive"
94-
fi
95-
done
96-
97-
if [ $EXIT_CODE -ne 0 ]; then
98-
echo "❌ Accessibility issues found!"
99-
exit $EXIT_CODE
100-
else
101-
echo "✅ No accessibility issues found"
102-
fi
103-
104-
accessibility-report:
105-
name: Generate A11y Report
106-
runs-on: ubuntu-latest
107-
if: always()
108-
needs: [swiftlint, accessibility-audit]
109-
steps:
110-
- name: Checkout
111-
uses: actions/checkout@v4
112-
113-
- name: Generate Accessibility Summary
114-
run: |
115-
echo "# Accessibility Check Summary 🔍" >> $GITHUB_STEP_SUMMARY
116-
echo "" >> $GITHUB_STEP_SUMMARY
117-
echo "## Checks Performed:" >> $GITHUB_STEP_SUMMARY
118-
echo "- ✅ SwiftLint accessibility rules" >> $GITHUB_STEP_SUMMARY
119-
echo "- ✅ Image accessibility labels" >> $GITHUB_STEP_SUMMARY
120-
echo "- ✅ Button accessibility labels" >> $GITHUB_STEP_SUMMARY
121-
echo "- ✅ Empty text views" >> $GITHUB_STEP_SUMMARY
122-
echo "- ✅ Tap gesture accessibility" >> $GITHUB_STEP_SUMMARY
123-
echo "- ✅ Generic label detection" >> $GITHUB_STEP_SUMMARY
124-
echo "" >> $GITHUB_STEP_SUMMARY
125-
echo "## Resources:" >> $GITHUB_STEP_SUMMARY
126-
echo "- [Apple Accessibility Guidelines](https://developer.apple.com/accessibility/)" >> $GITHUB_STEP_SUMMARY
127-
echo "- [SwiftUI Accessibility](https://developer.apple.com/documentation/swiftui/view-accessibility)" >> $GITHUB_STEP_SUMMARY
128-
129-
block-merge:
130-
name: Block Merge on Failures
131-
runs-on: ubuntu-latest
132-
needs: [swiftlint, accessibility-audit]
133-
if: failure()
134-
steps:
135-
- name: Comment on PR
136-
uses: actions/github-script@v7
137-
with:
138-
script: |
139-
github.rest.issues.createComment({
140-
issue_number: context.issue.number,
141-
owner: context.repo.owner,
142-
repo: context.repo.repo,
143-
body: '❌ **Accessibility checks failed**\n\nPlease review the accessibility issues found in the checks above before merging.\n\n**Common fixes:**\n- Add `.accessibilityLabel("description")` to images\n- Add `.accessibilityHidden(true)` for decorative images\n- Ensure buttons have descriptive labels\n- Use `.accessibilityElement(children: .combine)` for complex views\n\n**Need to suppress a warning?**\n```swift\n// swiftlint:disable:next a11y_swiftui_image_missing_label\nImage(systemName: "icon")\n```'
144-
})
23+
- name: Run SwiftLint
24+
run: swiftlint --strict --reporter github-actions-logging

0 commit comments

Comments
 (0)