Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/static-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Static Analysis

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
static-analysis:
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Python
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
ENV/
env/

# IDE
.vscode/
.idea/
*.swp
*.swo
*~

# Generated reports and logs
tracking-log.json
batch-report.json
*.log

# OS
.DS_Store
Thumbs.db
132 changes: 132 additions & 0 deletions INDEX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# Static Analysis Workflow Automation - File Index

## Core Scripts

### Main Automation Script
- **`add-static-analysis-workflow.py`** - Primary script to add/update static analysis workflow in a single repository
- Detects default branch automatically
- Validates YAML syntax
- Compares with existing files
- Creates tracking logs
- Usage: `python3 add-static-analysis-workflow.py [repo_path]`

### Batch Processing Script
- **`batch-add-workflows.py`** - Process multiple repositories at once
- Sequential or parallel execution
- Consolidated reporting
- Handles failures gracefully
- Usage: `python3 batch-add-workflows.py --repos repo1 repo2` or `--repo-file repos.txt`

## Testing

### Unit Tests
- **`test_workflow_implementation.py`** - Core functionality tests
- Tests script execution
- Verifies file creation
- Checks idempotency
- Validates tracking logs
- Run: `python3 test_workflow_implementation.py`

### Integration Tests
- **`integration_test.py`** - End-to-end testing
- Creates temporary test repositories
- Tests branch detection
- Verifies batch processing
- Tests YAML validation
- Run: `python3 integration_test.py`

## Documentation

### Getting Started
- **`README.md`** - Repository overview with quick start
- **`QUICKSTART.md`** - 5-minute quick start guide
- **`WORKFLOW_AUTOMATION.md`** - Complete reference documentation

### Configuration
- **`requirements.txt`** - Python dependencies (PyYAML)
- **`.gitignore`** - Git ignore patterns

### Examples
- **`examples/repos-example.txt`** - Example repository list format
- **`examples/usage-examples.sh`** - Common usage scenarios

## Generated Files

### Workflow File (in target repositories)
- **`.github/workflows/static-analysis.yaml`** - The standardized workflow
- Uses shared OpsLevel template
- Configured with detected default branch
- Triggers on push and pull_request

### Logs (in target repositories)
- **`tracking-log.json`** - Operation history
- Timestamps
- Actions taken (created/updated/skipped)
- Branch information
- Success/failure status

### Reports (from batch operations)
- **`batch-report.json`** - Consolidated batch processing report
- Summary statistics
- Individual repository results
- Error details

## Workflow Template

The automation creates this standardized workflow:

```yaml
name: Static Analysis

on:
push:
branches:
- [detected-branch]
pull_request:
branches:
- [detected-branch]

jobs:
static-analysis:
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main
```

## Dependencies

- Python 3.7+
- PyYAML 6.0+
- Git

## Quick Reference

### Single Repository
```bash
python3 add-static-analysis-workflow.py /path/to/repo
```

### Dry Run
```bash
python3 add-static-analysis-workflow.py --dry-run
```

### Multiple Repositories
```bash
python3 batch-add-workflows.py --repo-file repos.txt
```

### Parallel Processing
```bash
python3 batch-add-workflows.py --repo-file repos.txt --parallel --max-workers 8
```

### Run Tests
```bash
python3 test_workflow_implementation.py
python3 integration_test.py
```

## Support

For detailed usage instructions, see:
- [QUICKSTART.md](QUICKSTART.md) - Quick start guide
- [WORKFLOW_AUTOMATION.md](WORKFLOW_AUTOMATION.md) - Full documentation
166 changes: 166 additions & 0 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Quick Start Guide

Get started with the Static Analysis Workflow Automation in 5 minutes.

## Prerequisites

```bash
# Ensure Python 3.7+ is installed
python3 --version

# Ensure Git is installed
git --version
```

## Installation

```bash
# 1. Clone or navigate to this repository
cd /path/to/this/repo

# 2. Install dependencies
pip install -r requirements.txt
```

## Quick Usage

### Option 1: Single Repository

```bash
# Add workflow to the current repository
python3 add-static-analysis-workflow.py

# Or specify a repository path
python3 add-static-analysis-workflow.py /path/to/target/repo
```

### Option 2: Multiple Repositories

```bash
# Create a text file with repository paths (one per line)
cat > repos.txt << EOF
/path/to/repo1
/path/to/repo2
/path/to/repo3
EOF

# Process all repositories
python3 batch-add-workflows.py --repo-file repos.txt
```

## Verify Results

### Check Individual Repository

```bash
# View the generated workflow file
cat /path/to/repo/.github/workflows/static-analysis.yaml

# View the tracking log
cat /path/to/repo/tracking-log.json
```

### Check Batch Results

```bash
# View the batch report
cat batch-report.json

# Or use jq for pretty output
jq . batch-report.json
```

## Common Scenarios

### Dry Run First (Recommended)

Before making changes, see what would happen:

```bash
python3 add-static-analysis-workflow.py --dry-run
```

### Process Many Repositories Quickly

Use parallel processing for better performance:

```bash
python3 batch-add-workflows.py --repo-file repos.txt --parallel --max-workers 8
```

### Re-run Safely

The scripts are idempotent - running them multiple times won't cause issues:

```bash
# Running again on the same repo will skip if nothing changed
python3 add-static-analysis-workflow.py /path/to/repo
# Output: "Action: skipped - File already exists and matches template"
```

## Workflow File Example

The generated `.github/workflows/static-analysis.yaml` will look like:

```yaml
name: Static Analysis

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
static-analysis:
uses: opslevel/.github/.github/workflows/static-analysis.yaml@main
```

The branch name (`main`) is automatically detected for each repository.

## What Gets Created

After running the script on a repository, you'll have:

```
repository/
├── .github/
│ └── workflows/
│ └── static-analysis.yaml ← The workflow file
└── tracking-log.json ← Operation log
```

## Next Steps

- Read [WORKFLOW_AUTOMATION.md](WORKFLOW_AUTOMATION.md) for detailed documentation
- Run the test suite: `python3 test_workflow_implementation.py`
- Check examples in the `examples/` directory

## Troubleshooting

### "No module named 'yaml'"

```bash
pip install PyYAML
```

### "Could not detect default branch"

The repository might not have a remote tracking branch set up. Check:

```bash
cd /path/to/repo
git remote -v
git branch -a
```

### Need Help?

Run with `-h` or `--help` for command options:

```bash
python3 add-static-analysis-workflow.py --help
python3 batch-add-workflows.py --help
```
Loading