Skip to content

Commit 7a58d64

Browse files
authored
Merge pull request #2 from WP-Code-Check/development
Development to Main
2 parents df0c12a + 52d9b35 commit 7a58d64

5 files changed

Lines changed: 261 additions & 141 deletions

File tree

.github/workflows/README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# GitHub Actions Workflows
2+
3+
## ⚠️ IMPORTANT: Single Workflow Policy
4+
5+
**This repository uses a SINGLE consolidated workflow file: `ci.yml`**
6+
7+
### DO NOT Create Additional Workflow Files
8+
9+
**Do NOT create:**
10+
- Separate workflows for Slack notifications
11+
- Separate workflows for performance audits
12+
- Separate workflows for different branches
13+
- Duplicate workflows with slight variations
14+
15+
**Instead:**
16+
- Edit `ci.yml` to add new functionality
17+
- Use conditional logic for different behaviors
18+
- Use job dependencies for complex workflows
19+
- Use reusable workflows only for external consumption
20+
21+
## Why Single Workflow?
22+
23+
**Problem we had (Dec 2025):**
24+
- 3 separate workflows running simultaneously
25+
- Each PR/push triggered 3+ workflow runs
26+
- Wasted CI resources and created confusion
27+
- Duplicate Slack notifications
28+
- Harder to maintain consistency
29+
30+
**Solution:**
31+
- Consolidated into single `ci.yml` workflow
32+
- Conditional Slack notifications based on event type
33+
- All CI logic in one place
34+
- Easier to maintain and debug
35+
36+
## Current Workflow Structure
37+
38+
### `ci.yml` - Consolidated CI Workflow
39+
40+
**Triggers:**
41+
- `push` to main/development branches
42+
- `pull_request` to main/development branches
43+
- `workflow_dispatch` for manual runs
44+
45+
**Jobs:**
46+
47+
1. **performance-checks**
48+
- Runs performance audit in JSON mode
49+
- Conditional Slack notifications:
50+
- Push to main/development: Always notify
51+
- Pull requests: Only notify on failures
52+
- Uploads audit results as artifacts
53+
- Handles missing SLACK_WEBHOOK_URL gracefully
54+
55+
2. **validate-test-fixtures**
56+
- Runs automated fixture validation tests
57+
- Tests antipattern detection
58+
- Validates clean code passes checks
59+
60+
### `wp-performance.yml` - Reusable Workflow
61+
62+
**Purpose:** External consumption only (workflow_call)
63+
- Used by other repositories to run performance checks
64+
- NOT triggered by events in this repository
65+
- This is OK to keep as it's not causing duplicate runs
66+
67+
## How to Modify CI Behavior
68+
69+
### Adding a New Check
70+
71+
```yaml
72+
# Add to ci.yml under the appropriate job
73+
- name: Your new check
74+
run: |
75+
echo "Running new check..."
76+
./your-script.sh
77+
```
78+
79+
### Changing Slack Notification Logic
80+
81+
```yaml
82+
# Edit the conditional in ci.yml
83+
- name: Post to Slack
84+
if: your-condition-here
85+
env:
86+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
87+
run: |
88+
./dist/bin/post-to-slack.sh audit-results.json
89+
```
90+
91+
### Adding a New Job
92+
93+
```yaml
94+
# Add to ci.yml at the jobs level
95+
jobs:
96+
your-new-job:
97+
name: Your New Job
98+
runs-on: ubuntu-latest
99+
steps:
100+
- name: Checkout
101+
uses: actions/checkout@v4
102+
# ... your steps
103+
```
104+
105+
## Checklist Before Creating a New Workflow
106+
107+
- [ ] Can this be added to `ci.yml` instead?
108+
- [ ] Is this for external consumption (workflow_call)?
109+
- [ ] Have I checked if similar functionality already exists?
110+
- [ ] Will this cause duplicate runs with existing workflows?
111+
- [ ] Have I documented why a separate workflow is necessary?
112+
113+
## Questions?
114+
115+
If you're unsure whether to create a new workflow or modify `ci.yml`, ask yourself:
116+
117+
1. **Does this need to run on the same triggers?** → Add to `ci.yml`
118+
2. **Is this a variation of existing checks?** → Add conditional logic to `ci.yml`
119+
3. **Is this for other repos to consume?** → Create reusable workflow with `workflow_call`
120+
4. **Is this completely unrelated to CI?** → Maybe OK, but document why
121+
122+
## History
123+
124+
- **2025-12-31**: Consolidated 3 workflows into 1
125+
- Removed: `performance-audit-slack.yml`
126+
- Removed: `performance-audit-slack-on-failure.yml`
127+
- Enhanced: `ci.yml` with all functionality
128+
- Created: This README to prevent future duplication
129+
130+
---
131+
132+
**Remember: One workflow to rule them all! 💍**
133+

.github/workflows/ci.yml

Lines changed: 99 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1+
# ============================================================================
12
# CI Workflow for WP Code Check by Hypercart
2-
# Validates changes to the toolkit repository
3+
# ============================================================================
4+
#
5+
# ⚠️ WARNING: This is the ONLY workflow file that should exist in this repo!
6+
#
7+
# This consolidated workflow handles ALL CI needs:
8+
# - Performance checks and audits
9+
# - Test fixture validation
10+
# - Slack notifications (conditional based on event type)
11+
# - Artifact uploads
12+
#
13+
# DO NOT create additional workflow files for:
14+
# - Slack notifications (already integrated here)
15+
# - Performance audits (already integrated here)
16+
# - Additional CI checks (add them to this file instead)
17+
#
18+
# If you need to modify CI behavior, edit THIS file only.
19+
# Multiple workflows cause duplicate runs and waste CI resources.
20+
#
21+
# History: Consolidated from 3 separate workflows on 2025-12-31
22+
# - Removed: performance-audit-slack.yml
23+
# - Removed: performance-audit-slack-on-failure.yml
24+
# - Kept: ci.yml (this file) with all functionality merged
25+
#
26+
# ============================================================================
327
name: CI
428

529
on:
30+
push:
31+
branches:
32+
- main
33+
- development
634
pull_request:
735
branches:
836
- main
937
- development
38+
workflow_dispatch: # Allow manual triggers
1039

11-
# Prevent duplicate runs: use branch name as concurrency key so both push and
12-
# pull_request events for the same branch share the same group and get deduplicated.
13-
# github.head_ref is set for pull_request (source branch), github.ref for push.
40+
# Prevent duplicate runs: use branch name as concurrency key
1441
concurrency:
1542
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
1643
cancel-in-progress: true
@@ -24,27 +51,86 @@ jobs:
2451
- name: Checkout code
2552
uses: actions/checkout@v4
2653

54+
- name: Install jq (for JSON processing and Slack)
55+
run: sudo apt-get update && sudo apt-get install -y jq
56+
2757
- name: Make scripts executable
2858
run: |
2959
chmod +x ./dist/bin/check-performance.sh
3060
chmod +x ./dist/tests/run-fixture-tests.sh
61+
chmod +x ./dist/bin/post-to-slack.sh
3162
32-
- name: Run performance checks
63+
- name: Run performance audit
64+
id: audit
3365
run: |
34-
echo "Running performance checks on toolkit repository..."
35-
./dist/bin/check-performance.sh --paths "." --no-log || EXIT_CODE=$?
36-
if [ "${EXIT_CODE:-0}" -ne 0 ]; then
37-
echo "::warning::Performance checks found issues (exit code: $EXIT_CODE)"
38-
echo "This is informational - the toolkit itself may have intentional patterns for testing"
66+
echo "Running performance audit on toolkit repository..."
67+
68+
# Run in JSON mode for Slack integration
69+
./dist/bin/check-performance.sh \
70+
--paths "." \
71+
--format json \
72+
--strict \
73+
> audit-results.json && EXIT_CODE=0 || EXIT_CODE=$?
74+
75+
echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT
76+
77+
# Show summary in workflow logs
78+
if [ -f audit-results.json ]; then
79+
echo "## Performance Audit Summary"
80+
jq -r '.summary // "No summary available"' audit-results.json || echo "Could not parse summary"
3981
fi
82+
83+
# Don't fail the step yet - we want to send Slack notification first
4084
exit 0
85+
continue-on-error: true
86+
87+
- name: Post results to Slack (on push to main/development)
88+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/development')
89+
env:
90+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
91+
run: |
92+
if [ -n "$SLACK_WEBHOOK_URL" ]; then
93+
echo "📤 Posting results to Slack..."
94+
./dist/bin/post-to-slack.sh audit-results.json --format detailed || {
95+
echo "::warning::Failed to post to Slack"
96+
}
97+
else
98+
echo "ℹ️ SLACK_WEBHOOK_URL not configured, skipping Slack notification"
99+
fi
100+
101+
- name: Post failure to Slack (on PR failures only)
102+
if: github.event_name == 'pull_request' && steps.audit.outputs.exit_code != '0'
103+
env:
104+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
105+
run: |
106+
if [ -n "$SLACK_WEBHOOK_URL" ]; then
107+
echo "📤 Posting failure to Slack..."
108+
./dist/bin/post-to-slack.sh audit-results.json --format detailed || {
109+
echo "::warning::Failed to post to Slack"
110+
}
111+
else
112+
echo "ℹ️ SLACK_WEBHOOK_URL not configured, skipping Slack notification"
113+
fi
114+
115+
- name: Upload audit results
116+
if: always()
117+
uses: actions/upload-artifact@v4
118+
with:
119+
name: performance-audit-results-${{ github.run_number }}
120+
path: audit-results.json
121+
retention-days: 30
41122

42123
- name: Display check info
43124
if: always()
44125
run: |
45-
echo "✅ Performance checks completed"
46-
echo "Note: Logs are disabled in CI (--no-log flag)"
47-
echo "The 'dist/tests/' directory is excluded by default"
126+
EXIT_CODE="${{ steps.audit.outputs.exit_code }}"
127+
if [ "${EXIT_CODE:-0}" -ne 0 ]; then
128+
echo "::warning::Performance audit found issues (exit code: $EXIT_CODE)"
129+
echo "Note: The toolkit itself may have intentional patterns for testing"
130+
echo "This is informational for the toolkit repository"
131+
else
132+
echo "✅ Performance checks completed successfully"
133+
fi
48134
49135
validate-test-fixtures:
50136
name: Validate Test Fixtures

.github/workflows/performance-audit-slack-on-failure.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)