Skip to content

Commit 1def85d

Browse files
committed
ci: add coverage improvement workflow and enhance test validation
Add a GitHub Actions workflow to improve test coverage with scheduled and manual triggers. Update coverage tool to separate test generation logic and improve validation by regenerating tests on failure, switching to 'make ut' for unit test execution, and simplifying retry handling. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
1 parent 8e07a5f commit 1def85d

File tree

2 files changed

+25
-57
lines changed

2 files changed

+25
-57
lines changed

.github/workflows/coverage-improvement.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
---
22
name: Coverage Improvement
33

4-
'on':
4+
"on":
55
# Run weekly on Mondays at 00:00 UTC
66
schedule:
7-
- cron: '0 0 * * 1'
7+
- cron: "0 0 * * 1"
88
# Allow manual trigger
99
workflow_dispatch:
1010
inputs:
1111
git_user_name:
12-
description: 'Git user name for commits'
12+
description: "Git user name for commits"
1313
required: false
14-
default: 'github-actions[bot]'
14+
default: "github-actions[bot]"
1515
git_user_email:
16-
description: 'Git user email for commits'
16+
description: "Git user email for commits"
1717
required: false
18-
default: 'github-actions[bot]@users.noreply.github.com'
18+
default: "github-actions[bot]@users.noreply.github.com"
1919
pr_target_repo:
20-
description: 'Target repository for PR (owner/repo format)'
20+
description: "Target repository for PR (owner/repo format)"
2121
required: false
22-
default: ''
22+
default: ""
2323
create_pr:
24-
description: 'Whether to create a pull request'
24+
description: "Whether to create a pull request"
2525
required: false
26-
default: 'true'
26+
default: "true"
2727
type: boolean
2828

2929
permissions:
@@ -66,7 +66,7 @@ jobs:
6666
- name: Setup Go
6767
uses: actions/setup-go@v5
6868
with:
69-
go-version-file: 'go.work'
69+
go-version-file: "go.work"
7070
cache-dependency-path: "**/*.sum"
7171

7272
- name: Build coverage tool
@@ -115,6 +115,8 @@ jobs:
115115
fi
116116
117117
- name: Validate and apply tests
118+
env:
119+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118120
id: validate
119121
run: |
120122
contrib/nydus-coverage-tool/coverage-tool validate \

contrib/nydus-coverage-tool/cmd/coverage-tool/main.go

Lines changed: 12 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func runAnalyze(cmd *cobra.Command, args []string) error {
202202
return nil
203203
}
204204

205-
func runGenerate(cmd *cobra.Command, args []string) error {
205+
func generateTests() error {
206206
fmt.Println("================================================================================")
207207
fmt.Println("Generating Unit Tests")
208208
fmt.Println("================================================================================")
@@ -263,6 +263,10 @@ func runGenerate(cmd *cobra.Command, args []string) error {
263263
return nil
264264
}
265265

266+
func runGenerate(cmd *cobra.Command, args []string) error {
267+
return generateTests()
268+
}
269+
266270
func runValidate(cmd *cobra.Command, args []string) error {
267271
fmt.Println("================================================================================")
268272
fmt.Println("Validating Generated Tests")
@@ -301,38 +305,6 @@ func runValidate(cmd *cobra.Command, args []string) error {
301305
fmt.Printf("Validation Attempt %d/%d\n", attempt, maxRetries)
302306
fmt.Printf("================================================================================\n")
303307

304-
// Generate new tests for each attempt (except the first one which uses existing)
305-
if attempt > 1 {
306-
fmt.Println("\nRegenerating tests with different seed...")
307-
308-
// Read file content
309-
content, err := os.ReadFile(backupPath)
310-
if err != nil {
311-
lastErr = fmt.Errorf("failed to read original file: %w", err)
312-
continue
313-
}
314-
315-
// Generate new tests
316-
generatedTests, err := callGitHubModelsAPI(string(content), originalFilePath, analysis.Stats)
317-
if err != nil {
318-
lastErr = fmt.Errorf("failed to regenerate tests: %w", err)
319-
continue
320-
}
321-
322-
// Integrate tests into the file
323-
updatedContent := integrateTests(string(content), generatedTests)
324-
325-
// Save updated file
326-
testFilePath := filepath.Join(outputDir, "updated_file.rs")
327-
if err := os.WriteFile(testFilePath, []byte(updatedContent), 0644); err != nil {
328-
lastErr = fmt.Errorf("failed to write updated file: %w", err)
329-
continue
330-
}
331-
332-
// Update metadata
333-
metadata["generated_tests_path"] = testFilePath
334-
}
335-
336308
testFilePath := metadata["generated_tests_path"].(string)
337309

338310
// Copy generated file to original location
@@ -343,23 +315,17 @@ func runValidate(cmd *cobra.Command, args []string) error {
343315

344316
// Run cargo check
345317
fmt.Println("\nRunning cargo check...")
346-
if err := runCommand("cargo", "check", "--workspace"); err != nil {
347-
fmt.Println("❌ Compilation failed!")
348-
lastErr = err
349-
copyFile(backupPath, originalFilePath) // Restore backup
350-
continue
351-
}
352-
fmt.Println("✅ Compilation successful!")
353-
354-
// Run tests
355-
fmt.Println("\nRunning tests...")
356-
if err := runCommand("cargo", "test", "--workspace", "--", "--skip", "integration", "--nocapture"); err != nil {
357-
fmt.Println("❌ Tests failed!")
318+
if err := runCommand("make", "ut"); err != nil {
319+
fmt.Println("❌ UT failed!")
358320
lastErr = err
359321
copyFile(backupPath, originalFilePath) // Restore backup
322+
// Regenerate tests
323+
if err := generateTests(); err != nil {
324+
return fmt.Errorf("failed to regenerate tests: %w", err)
325+
}
360326
continue
361327
}
362-
fmt.Println("✅ All tests passed!")
328+
fmt.Println("✅ UT successful!")
363329

364330
success = true
365331
break

0 commit comments

Comments
 (0)