Skip to content

Commit 805629e

Browse files
authored
Merge pull request #36 from bnbong/dev
[CICD, DOCS] add templates' dependency vulnerable checking workflow, add commands at Makefile
2 parents 4474cc6 + a0179c0 commit 805629e

8 files changed

Lines changed: 1108 additions & 37 deletions

File tree

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
name: Weekly Template Security Scan
2+
3+
on:
4+
schedule:
5+
- cron: "0 23 * * 0"
6+
workflow_dispatch:
7+
inputs:
8+
templates:
9+
description: "Specific templates to scan (comma-separated, leave empty for all)"
10+
required: false
11+
default: ""
12+
13+
permissions:
14+
contents: read
15+
issues: write
16+
17+
jobs:
18+
security-scan:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.12"
29+
30+
- name: Install pip-audit
31+
run: pip install pip-audit
32+
33+
- name: Run security scan on templates
34+
id: scan
35+
run: |
36+
TEMPLATE_DIR="src/fastapi_fastkit/fastapi_project_template"
37+
RESULTS_FILE="security_scan_results.json"
38+
SCAN_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
39+
40+
# Initialize results
41+
echo '{' > $RESULTS_FILE
42+
echo ' "scan_date": "'$SCAN_DATE'",' >> $RESULTS_FILE
43+
echo ' "templates": [' >> $RESULTS_FILE
44+
45+
TEMPLATES_INPUT="${{ github.event.inputs.templates }}"
46+
FIRST_TEMPLATE=true
47+
TOTAL_VULNERABILITIES=0
48+
AFFECTED_TEMPLATES=""
49+
50+
for template_dir in $TEMPLATE_DIR/fastapi-*/; do
51+
template_name=$(basename "$template_dir")
52+
53+
# Skip if specific templates are requested and this isn't one
54+
if [ -n "$TEMPLATES_INPUT" ]; then
55+
if ! echo "$TEMPLATES_INPUT" | grep -q "$template_name"; then
56+
continue
57+
fi
58+
fi
59+
60+
req_file="$template_dir/requirements.txt-tpl"
61+
if [ -f "$req_file" ]; then
62+
echo "🔍 Scanning $template_name..."
63+
64+
# Create temp requirements file
65+
temp_req=$(mktemp)
66+
cp "$req_file" "$temp_req"
67+
68+
# Run pip-audit and capture output
69+
audit_output=$(pip-audit -r "$temp_req" --format json 2>/dev/null || echo '[]')
70+
rm "$temp_req"
71+
72+
# Count vulnerabilities
73+
vuln_count=$(echo "$audit_output" | python3 -c "import sys, json; data = json.load(sys.stdin); print(len(data))" 2>/dev/null || echo "0")
74+
75+
if [ "$vuln_count" -gt 0 ]; then
76+
TOTAL_VULNERABILITIES=$((TOTAL_VULNERABILITIES + vuln_count))
77+
AFFECTED_TEMPLATES="$AFFECTED_TEMPLATES $template_name"
78+
echo "⚠️ Found $vuln_count vulnerabilities in $template_name"
79+
else
80+
echo "✅ No vulnerabilities in $template_name"
81+
fi
82+
83+
# Add to JSON
84+
if [ "$FIRST_TEMPLATE" = true ]; then
85+
FIRST_TEMPLATE=false
86+
else
87+
echo ' ,' >> $RESULTS_FILE
88+
fi
89+
90+
echo ' {' >> $RESULTS_FILE
91+
echo ' "name": "'$template_name'",' >> $RESULTS_FILE
92+
echo ' "vulnerability_count": '$vuln_count',' >> $RESULTS_FILE
93+
echo ' "vulnerabilities": '$audit_output >> $RESULTS_FILE
94+
echo ' }' >> $RESULTS_FILE
95+
fi
96+
done
97+
98+
echo ' ],' >> $RESULTS_FILE
99+
echo ' "total_vulnerabilities": '$TOTAL_VULNERABILITIES',' >> $RESULTS_FILE
100+
echo ' "affected_templates": "'$(echo $AFFECTED_TEMPLATES | xargs)'"' >> $RESULTS_FILE
101+
echo '}' >> $RESULTS_FILE
102+
103+
# Set outputs for later steps
104+
echo "total_vulnerabilities=$TOTAL_VULNERABILITIES" >> $GITHUB_OUTPUT
105+
echo "affected_templates=$AFFECTED_TEMPLATES" >> $GITHUB_OUTPUT
106+
107+
- name: Upload scan results
108+
uses: actions/upload-artifact@v4
109+
if: always()
110+
with:
111+
name: security-scan-results
112+
path: security_scan_results.json
113+
retention-days: 30
114+
115+
- name: Create Issue on Vulnerabilities
116+
if: steps.scan.outputs.total_vulnerabilities != '0'
117+
uses: actions/github-script@v7
118+
with:
119+
script: |
120+
const fs = require('fs');
121+
122+
let issueBody = `## 🔒 Template Dependency Security Scan Results\n\n`;
123+
issueBody += `**Scan Date:** ${new Date().toISOString()}\n`;
124+
issueBody += `**Total Vulnerabilities Found:** ${{ steps.scan.outputs.total_vulnerabilities }}\n\n`;
125+
126+
try {
127+
const results = JSON.parse(fs.readFileSync('security_scan_results.json', 'utf8'));
128+
129+
results.templates.forEach(template => {
130+
if (template.vulnerability_count > 0) {
131+
issueBody += `### ⚠️ ${template.name}\n\n`;
132+
issueBody += `Found **${template.vulnerability_count}** vulnerabilities:\n\n`;
133+
issueBody += `| Package | Installed | Fix Versions | Vulnerability ID |\n`;
134+
issueBody += `|---------|-----------|--------------|------------------|\n`;
135+
136+
template.vulnerabilities.forEach(vuln => {
137+
const fixVersions = vuln.fix_versions ? vuln.fix_versions.join(', ') : 'N/A';
138+
issueBody += `| ${vuln.name} | ${vuln.version} | ${fixVersions} | ${vuln.id} |\n`;
139+
});
140+
141+
issueBody += `\n`;
142+
}
143+
});
144+
145+
} catch (error) {
146+
issueBody += `\nError reading detailed results: ${error.message}\n`;
147+
}
148+
149+
issueBody += `\n---\n**Workflow:** [${context.workflow}](${context.payload.repository.html_url}/actions/runs/${context.runId})`;
150+
151+
// Determine severity label
152+
const totalVulns = parseInt('${{ steps.scan.outputs.total_vulnerabilities }}');
153+
let severityLabel = 'security: low';
154+
if (totalVulns >= 10) {
155+
severityLabel = 'security: critical';
156+
} else if (totalVulns >= 5) {
157+
severityLabel = 'security: high';
158+
} else if (totalVulns >= 2) {
159+
severityLabel = 'security: medium';
160+
}
161+
162+
await github.rest.issues.create({
163+
owner: context.repo.owner,
164+
repo: context.repo.repo,
165+
title: `🔒 Template Security Alert: ${totalVulns} vulnerabilities found - ${new Date().toISOString().split('T')[0]}`,
166+
body: issueBody,
167+
labels: ['security', severityLabel, 'automated', 'template']
168+
});
169+
170+
- name: Report Summary
171+
if: always()
172+
run: |
173+
echo "## 🔒 Security Scan Summary" >> $GITHUB_STEP_SUMMARY
174+
echo "" >> $GITHUB_STEP_SUMMARY
175+
176+
if [ "${{ steps.scan.outputs.total_vulnerabilities }}" = "0" ]; then
177+
echo "✅ **No vulnerabilities found in any template!**" >> $GITHUB_STEP_SUMMARY
178+
else
179+
echo "⚠️ **Found ${{ steps.scan.outputs.total_vulnerabilities }} vulnerabilities**" >> $GITHUB_STEP_SUMMARY
180+
echo "" >> $GITHUB_STEP_SUMMARY
181+
echo "Affected templates: ${{ steps.scan.outputs.affected_templates }}" >> $GITHUB_STEP_SUMMARY
182+
echo "" >> $GITHUB_STEP_SUMMARY
183+
echo "A GitHub Issue has been created with detailed information." >> $GITHUB_STEP_SUMMARY
184+
fi

CONTRIBUTING.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Key commands for contributors:
9999
- `make test` - Run all tests
100100
- `make test-verbose` - Run tests with verbose output
101101
- `make test-coverage` - Run tests with coverage report
102+
- `make coverage-report` - Generate detailed coverage report (supports FORMAT=html/xml/json/all)
102103

103104
#### Installation and Building
104105
- `make install-test` - Install package for testing (uninstall + reinstall)
@@ -109,6 +110,9 @@ Key commands for contributors:
109110
- `make build-docs` - Build documentation
110111
- `make serve-docs` - Serve documentation locally
111112

113+
#### Translation
114+
- `make translate` - Translate documentation (supports LANG, PROVIDER, MODEL parameters)
115+
112116
### Development Workflow
113117

114118
1. **Before making changes:**
@@ -170,6 +174,13 @@ Run tests using these commands:
170174
make test-coverage
171175
```
172176

177+
4. **Detailed coverage report with options:**
178+
```bash
179+
make coverage-report # Terminal output
180+
make coverage-report FORMAT=html # HTML report (opens in browser)
181+
make coverage-report FORMAT=all # All formats (term, html, xml, json)
182+
```
183+
173184
### Making PRs
174185

175186
Use these tags in PR title:
@@ -423,7 +434,21 @@ This migrates existing English docs to `docs/en/` and creates language directori
423434

424435
### Translating Documentation
425436

426-
#### Translate to Specific Language
437+
#### Using Make Commands (Recommended)
438+
439+
```bash
440+
# Translate all docs to all configured languages
441+
make translate
442+
443+
# Translate to specific language
444+
make translate LANG=ko
445+
446+
# Specify API provider and model
447+
make translate LANG=ko PROVIDER=github MODEL=gpt-4o-mini
448+
make translate LANG=ko PROVIDER=openai MODEL=gpt-4
449+
```
450+
451+
#### Using Script Directly
427452

428453
```bash
429454
# Translate all docs to Korean

Makefile

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help install install-dev install-test uninstall test test-verbose lint format format-check clean build build-docs serve-docs version-update all
1+
.PHONY: help install install-dev install-test uninstall test test-verbose lint format format-check clean build build-docs serve-docs version-update all translate coverage-report
22

33
# Default target
44
help: ## Show this help message
@@ -137,3 +137,21 @@ all: ## Run complete development workflow
137137
$(MAKE) dev-setup
138138
$(MAKE) dev-check
139139
$(MAKE) build
140+
141+
# Translation commands
142+
translate: ## Translate documentation - Usage: make translate LANG=ko PROVIDER=github MODEL=gpt-4o-mini
143+
@echo "Starting translation..."
144+
@CMD="python scripts/translate.py"; \
145+
if [ -n "$(LANG)" ]; then CMD="$$CMD --target-lang $(LANG)"; fi; \
146+
if [ -n "$(PROVIDER)" ]; then CMD="$$CMD --api-provider $(PROVIDER)"; fi; \
147+
if [ -n "$(MODEL)" ]; then CMD="$$CMD --model $(MODEL)"; fi; \
148+
echo "Running: $$CMD"; \
149+
$$CMD
150+
151+
# Coverage report commands
152+
coverage-report: ## Generate detailed coverage report - Usage: make coverage-report FORMAT=html
153+
@if [ -z "$(FORMAT)" ]; then \
154+
./scripts/coverage-report.sh; \
155+
else \
156+
./scripts/coverage-report.sh -f "$(FORMAT)"; \
157+
fi

docs/en/contributing/development-setup.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ The project Makefile provides convenient commands for common development tasks:
191191
| `make test-unit` | Run unit tests only |
192192
| `make test-integration` | Run integration tests only |
193193
| `make test-coverage` | Run tests with coverage report |
194+
| `make coverage-report` | Generate detailed coverage report (FORMAT=html/xml/json/all) |
194195
| `make test-watch` | Run tests in watch mode |
195196

196197
### Documentation Commands
@@ -201,6 +202,12 @@ The project Makefile provides convenient commands for common development tasks:
201202
| `make docs-build` | Build documentation |
202203
| `make docs-deploy` | Deploy documentation to GitHub Pages |
203204

205+
### Translation Commands
206+
207+
| Command | Description |
208+
|---------|-----------|
209+
| `make translate` | Translate documentation (LANG, PROVIDER, MODEL parameters) |
210+
204211
### Examples
205212

206213
<div class="termy">
@@ -231,6 +238,15 @@ src/cli.py 89 5 94%
231238
src/templates.py 67 3 96%
232239
--------------------------------------------
233240
TOTAL 201 10 95%
241+
242+
# Generate HTML coverage report
243+
$ make coverage-report FORMAT=html
244+
🌐 Opening HTML coverage report in browser...
245+
246+
# Translate documentation to Korean
247+
$ make translate LANG=ko PROVIDER=github MODEL=gpt-4o-mini
248+
Starting translation...
249+
Running: python scripts/translate.py --target-lang ko --api-provider github --model gpt-4o-mini
234250
```
235251

236252
</div>

docs/en/contributing/translation-guide.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,25 @@ gh auth login
6666

6767
## Usage
6868

69-
### Translate All Documentation
69+
### Using Make Commands (Recommended)
70+
71+
The easiest way to run translations:
72+
73+
```bash
74+
# Translate all docs to all languages
75+
make translate
76+
77+
# Translate to specific language
78+
make translate LANG=ko
79+
80+
# Specify API provider and model
81+
make translate LANG=ko PROVIDER=openai MODEL=gpt-4
82+
make translate LANG=ko PROVIDER=github MODEL=gpt-4o-mini
83+
```
84+
85+
### Using Script Directly
86+
87+
#### Translate All Documentation
7088

7189
Translate all documentation to all supported languages:
7290

docs/ko/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{!CHANGELOG.md!}

0 commit comments

Comments
 (0)