Skip to content

Commit 4f37101

Browse files
committed
Added AWS & Azure rules, CI/CD and tests
1 parent 18a4b6b commit 4f37101

68 files changed

Lines changed: 5795 additions & 397 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: Main Branch Validation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
# =========================
9+
# QUICK VALIDATION
10+
# =========================
11+
validate:
12+
name: Validate Package
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -e ".[dev,aws,azure]"
26+
27+
- name: Verify imports
28+
run: |
29+
python -c "from cleancloud.cli import main; print('✅ CLI imports')"
30+
python -c "from cleancloud.models.finding import Finding; print('✅ Models import')"
31+
python -c "from cleancloud.providers.aws.session import create_aws_session; print('✅ AWS imports')"
32+
python -c "from cleancloud.providers.azure.session import create_azure_session; print('✅ Azure imports')"
33+
34+
- name: Run linting
35+
run: |
36+
pip install ruff black
37+
ruff check cleancloud/ || echo "⚠️ Linting warnings found"
38+
black --check cleancloud/ || echo "⚠️ Formatting issues found"
39+
40+
# =========================
41+
# INTEGRATION TESTS (REQUIRED - Must pass)
42+
# =========================
43+
integration-test-aws:
44+
name: Integration Test - AWS (Required)
45+
runs-on: ubuntu-latest
46+
needs: validate
47+
environment: cleancloud-test
48+
# NO continue-on-error - failures will block
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v5
55+
with:
56+
python-version: "3.11"
57+
58+
- name: Install CleanCloud
59+
run: |
60+
python -m pip install --upgrade pip
61+
pip install -e ".[dev,aws,azure]"
62+
63+
- name: Test AWS doctor (strict)
64+
env:
65+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
67+
AWS_DEFAULT_REGION: us-east-1
68+
run: |
69+
set -e # Exit on any error
70+
cleancloud doctor --provider aws --region us-east-1
71+
72+
- name: Test AWS scan (strict)
73+
env:
74+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
75+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
76+
AWS_DEFAULT_REGION: us-east-1
77+
run: |
78+
set -e # Exit on any error
79+
cleancloud scan --provider aws --region us-east-1 --output json --output-file test-results.json
80+
81+
- name: Upload test results
82+
if: always()
83+
uses: actions/upload-artifact@v4
84+
with:
85+
name: aws-integration-main
86+
path: test-results.json
87+
88+
integration-test-azure:
89+
name: Integration Test - Azure (Required)
90+
runs-on: ubuntu-latest
91+
needs: validate
92+
environment: cleancloud-test
93+
# NO continue-on-error - failures will block
94+
95+
steps:
96+
- uses: actions/checkout@v4
97+
98+
- name: Set up Python
99+
uses: actions/setup-python@v5
100+
with:
101+
python-version: "3.11"
102+
103+
- name: Install CleanCloud
104+
run: |
105+
python -m pip install --upgrade pip
106+
pip install -e ".[dev,aws,azure]"
107+
108+
- name: Test Azure doctor (strict)
109+
env:
110+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
111+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
112+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
113+
#AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
114+
run: |
115+
set -e # Exit on any error
116+
cleancloud doctor --provider azure
117+
118+
- name: Test Azure scan (strict)
119+
env:
120+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
121+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
122+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
123+
#AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
124+
run: |
125+
set -e # Exit on any error
126+
cleancloud scan --provider azure --output json --output-file test-results.json
127+
128+
- name: Upload test results
129+
if: always()
130+
uses: actions/upload-artifact@v4
131+
with:
132+
name: azure-integration-main
133+
path: test-results.json
134+
135+
# =========================
136+
# NOTIFY ON FAILURE
137+
# =========================
138+
notify-failure:
139+
name: Create Issue on Failure
140+
runs-on: ubuntu-latest
141+
needs: [validate, integration-test-aws, integration-test-azure]
142+
if: failure()
143+
144+
steps:
145+
- name: Create issue
146+
uses: actions/github-script@v7
147+
with:
148+
script: |
149+
const runUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
150+
151+
await github.rest.issues.create({
152+
owner: context.repo.owner,
153+
repo: context.repo.repo,
154+
title: '🚨 Main branch validation failed',
155+
body: `Main branch validation failed.\n\n**Workflow run:** ${runUrl}\n**Commit:** ${context.sha}\n\n⚠️ Main branch may not be production-ready.`,
156+
labels: ['bug', 'ci-failure', 'urgent']
157+
});

.github/workflows/pr-checks.yml

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
name: PR Checks
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
7+
jobs:
8+
# =========================
9+
# CODE QUALITY CHECKS (REQUIRED)
10+
# =========================
11+
lint:
12+
name: Lint & Format Check
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Set up Python
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: "3.11"
21+
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install ruff black
26+
27+
- name: Run Ruff
28+
run: ruff check cleancloud/
29+
30+
- name: Check formatting with Black
31+
run: black --check cleancloud/
32+
33+
# =========================
34+
# UNIT TESTS (REQUIRED)
35+
# =========================
36+
test:
37+
name: Test Python ${{ matrix.python-version }}
38+
runs-on: ubuntu-latest
39+
environment: cleancloud-test
40+
strategy:
41+
fail-fast: false
42+
matrix:
43+
python-version: ["3.10", "3.11", "3.12"]
44+
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- name: Set up Python ${{ matrix.python-version }}
49+
uses: actions/setup-python@v5
50+
with:
51+
python-version: ${{ matrix.python-version }}
52+
53+
- name: Install dependencies
54+
run: |
55+
python -m pip install --upgrade pip
56+
pip install -e ".[dev,aws,azure]"
57+
58+
- name: Run tests
59+
env:
60+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
61+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
62+
AWS_DEFAULT_REGION: us-east-1
63+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
64+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
65+
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
66+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
67+
run: pytest tests/ -v --cov=cleancloud --cov-report=xml
68+
69+
- name: Upload coverage
70+
if: matrix.python-version == '3.11'
71+
uses: codecov/codecov-action@v4
72+
with:
73+
file: ./coverage.xml
74+
fail_ci_if_error: false
75+
76+
# =========================
77+
# BUILD PACKAGE (REQUIRED)
78+
# =========================
79+
build:
80+
name: Build Distribution
81+
runs-on: ubuntu-latest
82+
needs: [lint, test]
83+
84+
steps:
85+
- uses: actions/checkout@v4
86+
87+
- name: Set up Python
88+
uses: actions/setup-python@v5
89+
with:
90+
python-version: "3.11"
91+
92+
- name: Install build tools
93+
run: |
94+
python -m pip install --upgrade pip
95+
pip install build twine
96+
97+
- name: Build package
98+
run: python -m build
99+
100+
- name: Check package
101+
run: twine check dist/*
102+
103+
- name: Upload distributions
104+
uses: actions/upload-artifact@v4
105+
with:
106+
name: distributions
107+
path: dist/
108+
109+
# =========================
110+
# INTEGRATION TESTS (OPTIONAL - Don't block PR)
111+
# =========================
112+
integration-test-aws:
113+
name: Integration Test - AWS (Optional)
114+
runs-on: ubuntu-latest
115+
continue-on-error: true # ✅ Informational only
116+
environment: cleancloud-it-test
117+
118+
steps:
119+
- uses: actions/checkout@v4
120+
121+
- name: Set up Python
122+
uses: actions/setup-python@v5
123+
with:
124+
python-version: "3.11"
125+
126+
- name: Install CleanCloud
127+
run: |
128+
python -m pip install --upgrade pip
129+
pip install -e ".[dev,aws,azure]"
130+
131+
- name: Test AWS doctor command
132+
env:
133+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
134+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
135+
AWS_DEFAULT_REGION: us-east-1
136+
run: |
137+
cleancloud doctor --provider aws --region us-east-1
138+
139+
- name: Test AWS scan
140+
env:
141+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
142+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
143+
AWS_DEFAULT_REGION: us-east-1
144+
run: |
145+
cleancloud scan --provider aws --region us-east-1 --output json --output-file test-results.json
146+
147+
- name: Upload test results
148+
if: always()
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: aws-integration-test-results
152+
path: test-results.json
153+
154+
integration-test-azure:
155+
name: Integration Test - Azure (Optional)
156+
runs-on: ubuntu-latest
157+
continue-on-error: true # ✅ Informational only
158+
environment: cleancloud-it-test
159+
160+
steps:
161+
- uses: actions/checkout@v4
162+
163+
- name: Set up Python
164+
uses: actions/setup-python@v5
165+
with:
166+
python-version: "3.11"
167+
168+
- name: Install CleanCloud
169+
run: |
170+
python -m pip install --upgrade pip
171+
pip install -e ".[dev,aws,azure]"
172+
173+
- name: Test Azure doctor command (with retry)
174+
uses: nick-fields/retry-action@v3
175+
with:
176+
timeout_minutes: 3
177+
max_attempts: 3
178+
retry_wait_seconds: 30
179+
command: cleancloud doctor --provider azure
180+
env:
181+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
182+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
183+
#AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
184+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
185+
186+
- name: Test Azure scan (with retry)
187+
uses: nick-fields/retry-action@v3
188+
with:
189+
timeout_minutes: 5
190+
max_attempts: 3
191+
retry_wait_seconds: 30
192+
command: cleancloud scan --provider azure --output json --output-file test-results.json
193+
env:
194+
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
195+
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
196+
#AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
197+
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
198+
199+
- name: Upload test results
200+
if: always()
201+
uses: actions/upload-artifact@v4
202+
with:
203+
name: azure-integration-test-results
204+
path: test-results.json

0 commit comments

Comments
 (0)