Skip to content

Commit 2dd052d

Browse files
Merge pull request #2 from eapache-opslevel/tidra-standardize_static_analysis_workflow_across_repositories-6f5ed524
Standardize Static Analysis Workflow Across Repositories
2 parents 83dd6d3 + 371d324 commit 2dd052d

13 files changed

Lines changed: 2049 additions & 125 deletions
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Static Analysis
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
static-analysis:
13+
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main

.gitignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
build/
8+
develop-eggs/
9+
dist/
10+
downloads/
11+
eggs/
12+
.eggs/
13+
lib/
14+
lib64/
15+
parts/
16+
sdist/
17+
var/
18+
wheels/
19+
*.egg-info/
20+
.installed.cfg
21+
*.egg
22+
23+
# Virtual environments
24+
venv/
25+
ENV/
26+
env/
27+
28+
# IDE
29+
.vscode/
30+
.idea/
31+
*.swp
32+
*.swo
33+
*~
34+
35+
# Generated reports and logs
36+
tracking-log.json
37+
batch-report.json
38+
*.log
39+
40+
# OS
41+
.DS_Store
42+
Thumbs.db

INDEX.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Static Analysis Workflow Automation - File Index
2+
3+
## Core Scripts
4+
5+
### Main Automation Script
6+
- **`add-static-analysis-workflow.py`** - Primary script to add/update static analysis workflow in a single repository
7+
- Detects default branch automatically
8+
- Validates YAML syntax
9+
- Compares with existing files
10+
- Creates tracking logs
11+
- Usage: `python3 add-static-analysis-workflow.py [repo_path]`
12+
13+
### Batch Processing Script
14+
- **`batch-add-workflows.py`** - Process multiple repositories at once
15+
- Sequential or parallel execution
16+
- Consolidated reporting
17+
- Handles failures gracefully
18+
- Usage: `python3 batch-add-workflows.py --repos repo1 repo2` or `--repo-file repos.txt`
19+
20+
## Testing
21+
22+
### Unit Tests
23+
- **`test_workflow_implementation.py`** - Core functionality tests
24+
- Tests script execution
25+
- Verifies file creation
26+
- Checks idempotency
27+
- Validates tracking logs
28+
- Run: `python3 test_workflow_implementation.py`
29+
30+
### Integration Tests
31+
- **`integration_test.py`** - End-to-end testing
32+
- Creates temporary test repositories
33+
- Tests branch detection
34+
- Verifies batch processing
35+
- Tests YAML validation
36+
- Run: `python3 integration_test.py`
37+
38+
## Documentation
39+
40+
### Getting Started
41+
- **`README.md`** - Repository overview with quick start
42+
- **`QUICKSTART.md`** - 5-minute quick start guide
43+
- **`WORKFLOW_AUTOMATION.md`** - Complete reference documentation
44+
45+
### Configuration
46+
- **`requirements.txt`** - Python dependencies (PyYAML)
47+
- **`.gitignore`** - Git ignore patterns
48+
49+
### Examples
50+
- **`examples/repos-example.txt`** - Example repository list format
51+
- **`examples/usage-examples.sh`** - Common usage scenarios
52+
53+
## Generated Files
54+
55+
### Workflow File (in target repositories)
56+
- **`.github/workflows/static-analysis.yaml`** - The standardized workflow
57+
- Uses shared OpsLevel template
58+
- Configured with detected default branch
59+
- Triggers on push and pull_request
60+
61+
### Logs (in target repositories)
62+
- **`tracking-log.json`** - Operation history
63+
- Timestamps
64+
- Actions taken (created/updated/skipped)
65+
- Branch information
66+
- Success/failure status
67+
68+
### Reports (from batch operations)
69+
- **`batch-report.json`** - Consolidated batch processing report
70+
- Summary statistics
71+
- Individual repository results
72+
- Error details
73+
74+
## Workflow Template
75+
76+
The automation creates this standardized workflow:
77+
78+
```yaml
79+
name: Static Analysis
80+
81+
on:
82+
push:
83+
branches:
84+
- [detected-branch]
85+
pull_request:
86+
branches:
87+
- [detected-branch]
88+
89+
jobs:
90+
static-analysis:
91+
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main
92+
```
93+
94+
## Dependencies
95+
96+
- Python 3.7+
97+
- PyYAML 6.0+
98+
- Git
99+
100+
## Quick Reference
101+
102+
### Single Repository
103+
```bash
104+
python3 add-static-analysis-workflow.py /path/to/repo
105+
```
106+
107+
### Dry Run
108+
```bash
109+
python3 add-static-analysis-workflow.py --dry-run
110+
```
111+
112+
### Multiple Repositories
113+
```bash
114+
python3 batch-add-workflows.py --repo-file repos.txt
115+
```
116+
117+
### Parallel Processing
118+
```bash
119+
python3 batch-add-workflows.py --repo-file repos.txt --parallel --max-workers 8
120+
```
121+
122+
### Run Tests
123+
```bash
124+
python3 test_workflow_implementation.py
125+
python3 integration_test.py
126+
```
127+
128+
## Support
129+
130+
For detailed usage instructions, see:
131+
- [QUICKSTART.md](QUICKSTART.md) - Quick start guide
132+
- [WORKFLOW_AUTOMATION.md](WORKFLOW_AUTOMATION.md) - Full documentation

QUICKSTART.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Quick Start Guide
2+
3+
Get started with the Static Analysis Workflow Automation in 5 minutes.
4+
5+
## Prerequisites
6+
7+
```bash
8+
# Ensure Python 3.7+ is installed
9+
python3 --version
10+
11+
# Ensure Git is installed
12+
git --version
13+
```
14+
15+
## Installation
16+
17+
```bash
18+
# 1. Clone or navigate to this repository
19+
cd /path/to/this/repo
20+
21+
# 2. Install dependencies
22+
pip install -r requirements.txt
23+
```
24+
25+
## Quick Usage
26+
27+
### Option 1: Single Repository
28+
29+
```bash
30+
# Add workflow to the current repository
31+
python3 add-static-analysis-workflow.py
32+
33+
# Or specify a repository path
34+
python3 add-static-analysis-workflow.py /path/to/target/repo
35+
```
36+
37+
### Option 2: Multiple Repositories
38+
39+
```bash
40+
# Create a text file with repository paths (one per line)
41+
cat > repos.txt << EOF
42+
/path/to/repo1
43+
/path/to/repo2
44+
/path/to/repo3
45+
EOF
46+
47+
# Process all repositories
48+
python3 batch-add-workflows.py --repo-file repos.txt
49+
```
50+
51+
## Verify Results
52+
53+
### Check Individual Repository
54+
55+
```bash
56+
# View the generated workflow file
57+
cat /path/to/repo/.github/workflows/static-analysis.yaml
58+
59+
# View the tracking log
60+
cat /path/to/repo/tracking-log.json
61+
```
62+
63+
### Check Batch Results
64+
65+
```bash
66+
# View the batch report
67+
cat batch-report.json
68+
69+
# Or use jq for pretty output
70+
jq . batch-report.json
71+
```
72+
73+
## Common Scenarios
74+
75+
### Dry Run First (Recommended)
76+
77+
Before making changes, see what would happen:
78+
79+
```bash
80+
python3 add-static-analysis-workflow.py --dry-run
81+
```
82+
83+
### Process Many Repositories Quickly
84+
85+
Use parallel processing for better performance:
86+
87+
```bash
88+
python3 batch-add-workflows.py --repo-file repos.txt --parallel --max-workers 8
89+
```
90+
91+
### Re-run Safely
92+
93+
The scripts are idempotent - running them multiple times won't cause issues:
94+
95+
```bash
96+
# Running again on the same repo will skip if nothing changed
97+
python3 add-static-analysis-workflow.py /path/to/repo
98+
# Output: "Action: skipped - File already exists and matches template"
99+
```
100+
101+
## Workflow File Example
102+
103+
The generated `.github/workflows/static-analysis.yaml` will look like:
104+
105+
```yaml
106+
name: Static Analysis
107+
108+
on:
109+
push:
110+
branches:
111+
- main
112+
pull_request:
113+
branches:
114+
- main
115+
116+
jobs:
117+
static-analysis:
118+
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main
119+
```
120+
121+
The branch name (`main`) is automatically detected for each repository.
122+
123+
## What Gets Created
124+
125+
After running the script on a repository, you'll have:
126+
127+
```
128+
repository/
129+
├── .github/
130+
│ └── workflows/
131+
│ └── static-analysis.yaml ← The workflow file
132+
└── tracking-log.json ← Operation log
133+
```
134+
135+
## Next Steps
136+
137+
- Read [WORKFLOW_AUTOMATION.md](WORKFLOW_AUTOMATION.md) for detailed documentation
138+
- Run the test suite: `python3 test_workflow_implementation.py`
139+
- Check examples in the `examples/` directory
140+
141+
## Troubleshooting
142+
143+
### "No module named 'yaml'"
144+
145+
```bash
146+
pip install PyYAML
147+
```
148+
149+
### "Could not detect default branch"
150+
151+
The repository might not have a remote tracking branch set up. Check:
152+
153+
```bash
154+
cd /path/to/repo
155+
git remote -v
156+
git branch -a
157+
```
158+
159+
### Need Help?
160+
161+
Run with `-h` or `--help` for command options:
162+
163+
```bash
164+
python3 add-static-analysis-workflow.py --help
165+
python3 batch-add-workflows.py --help
166+
```

0 commit comments

Comments
 (0)