|
| 1 | +# GitHub Actions Workflows |
| 2 | + |
| 3 | +This directory contains the CI/CD workflows for the SAP Cloud SDK for Python. |
| 4 | + |
| 5 | +## Workflow Structure |
| 6 | + |
| 7 | +The CI pipeline is split into three independent workflows for optimal performance and security: |
| 8 | + |
| 9 | +### 1. Code Quality Checks (`checks.yaml`) |
| 10 | + |
| 11 | +**Trigger**: `pull_request` (runs on all PRs) |
| 12 | +**Purpose**: Fast feedback on code style and type safety |
| 13 | +**Jobs**: |
| 14 | +- `lint` - Ruff linter checks |
| 15 | +- `format` - Ruff formatter checks |
| 16 | +- `typecheck` - ty type checker |
| 17 | + |
| 18 | +**Parallelization**: All jobs run in parallel (~1-2 min total) |
| 19 | + |
| 20 | +**Security**: |
| 21 | +- Uses `pull_request` trigger (read-only by default) |
| 22 | +- ✅ SAFE: Only runs static analysis tools (no code execution) |
| 23 | +- ❌ NO secrets or write permissions |
| 24 | + |
| 25 | +**Fork-friendly**: Contributors get immediate feedback on code quality checks. |
| 26 | + |
| 27 | +### 2. Tests & Coverage (`test.yaml`) |
| 28 | + |
| 29 | +**Trigger**: `pull_request` (runs on all PRs) |
| 30 | +**Purpose**: Run tests and report coverage |
| 31 | +**Jobs**: |
| 32 | +- `test` - Unit tests with coverage reporting |
| 33 | + |
| 34 | +**Permissions**: |
| 35 | +- `contents: read` - Read-only access |
| 36 | + |
| 37 | +**Security**: |
| 38 | +- Uses `pull_request` trigger (read-only) |
| 39 | +- Coverage visible in workflow summary |
| 40 | + |
| 41 | +### 3. Build & Package (`build.yaml`) |
| 42 | + |
| 43 | +**Trigger**: `pull_request` (requires approval for fork PRs) |
| 44 | +**Purpose**: Build and verify distribution packages |
| 45 | +**Jobs**: |
| 46 | +- `build` - Creates wheel and source distributions |
| 47 | + |
| 48 | +**Artifacts**: |
| 49 | +- Uploads built packages for 7 days |
| 50 | + |
| 51 | +## Workflow Execution Flow |
| 52 | + |
| 53 | +``` |
| 54 | +Fork PR opened |
| 55 | + ↓ |
| 56 | +┌─────────────────────────────────────────┐ |
| 57 | +│ checks.yaml (auto-runs) │ |
| 58 | +│ ├─ lint (parallel) │ |
| 59 | +│ ├─ format (parallel) │ |
| 60 | +│ └─ typecheck (parallel) │ |
| 61 | +└─────────────────────────────────────────┘ |
| 62 | + ↓ (1-2 min) |
| 63 | + ✓ Quick feedback to contributor |
| 64 | + |
| 65 | + ↓ (Runs in parallel) |
| 66 | + |
| 67 | +┌─────────────────────────────────────────┐ |
| 68 | +│ test.yaml (auto-runs) │ |
| 69 | +│ └─ test (with coverage) │ |
| 70 | +└─────────────────────────────────────────┘ |
| 71 | + ↓ (3-5 min) |
| 72 | + |
| 73 | + ↓ (Maintainer clicks "Approve and run") |
| 74 | + |
| 75 | +┌─────────────────────────────────────────┐ |
| 76 | +│ build.yaml (requires approval) │ |
| 77 | +│ └─ build (package creation) │ |
| 78 | +└─────────────────────────────────────────┘ |
| 79 | + ↓ (1-2 min) |
| 80 | + |
| 81 | + ✓ All checks passed, ready to merge |
| 82 | +``` |
| 83 | + |
| 84 | +## Benefits |
| 85 | + |
| 86 | +### For Contributors |
| 87 | +- **Immediate feedback** on code style and tests |
| 88 | +- **Faster iteration** - fix issues quickly |
| 89 | +- **Clear separation** of concerns in CI status |
| 90 | + |
| 91 | +### For Maintainers |
| 92 | +- **Parallel execution** - faster CI overall (~3-5 min vs ~8-10 min) |
| 93 | +- **Security** - limited permissions for all workflows |
| 94 | +- **Selective approval** - only approve build jobs |
| 95 | + |
| 96 | +## Security Considerations |
| 97 | + |
| 98 | +### Why Build Requires Approval |
| 99 | + |
| 100 | +The `build.yaml` workflow requires approval because it: |
| 101 | +- Creates distribution packages |
| 102 | +- May access secrets in the future (e.g., PyPI tokens) |
| 103 | + |
| 104 | +## Local Development |
| 105 | + |
| 106 | +Run checks locally before pushing: |
| 107 | + |
| 108 | +```bash |
| 109 | +# Lint |
| 110 | +uv run ruff check . |
| 111 | + |
| 112 | +# Format |
| 113 | +uv run ruff format . |
| 114 | + |
| 115 | +# Type check |
| 116 | +uv run ty check . |
| 117 | + |
| 118 | +# Tests |
| 119 | +uv run pytest -m "not integration" |
| 120 | + |
| 121 | +# Build |
| 122 | +uv build |
| 123 | +``` |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +### Fork PR workflows not running? |
| 128 | + |
| 129 | +1. **checks.yaml/test.yaml not running**: Check if Actions are enabled in repository settings |
| 130 | +2. **build.yaml not running**: Requires manual approval for fork PRs - look for "Approve and run" button |
| 131 | + |
| 132 | +### All workflows require approval? |
| 133 | + |
| 134 | +This means fork PR workflows are disabled in repository settings: |
| 135 | +1. Go to Settings → Actions → General |
| 136 | +2. Enable "Fork pull request workflows from outside collaborators" |
| 137 | +3. Select "Require approval for first-time contributors" |
| 138 | + |
| 139 | +## References |
| 140 | + |
| 141 | +- [GitHub Actions: Events that trigger workflows](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows) |
| 142 | +- [Keeping your GitHub Actions secure](https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions) |
| 143 | +- [Using pull_request_target safely](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) |
0 commit comments