mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-14 14:45:49 +01:00
Add tests and documentation for --create-release-notes flag
- Add comprehensive test files for release notes creation - Add edge case testing for empty changelogs and comments - Add documentation explaining how the feature works - Verify all functionality works as expected
This commit is contained in:
parent
db5b0dcd4b
commit
81d1459b68
6 changed files with 1133 additions and 0 deletions
118
v3/tasks/release/RELEASE_NOTES_CREATION.md
Normal file
118
v3/tasks/release/RELEASE_NOTES_CREATION.md
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
# Release Notes Creation Documentation
|
||||
|
||||
## Overview
|
||||
|
||||
The `release.go` script now supports a `--create-release-notes` flag that extracts changelog content from `UNRELEASED_CHANGELOG.md` and creates a clean `release_notes.md` file suitable for GitHub releases.
|
||||
|
||||
## How It Works
|
||||
|
||||
### 1. Command Usage
|
||||
|
||||
```bash
|
||||
go run release.go --create-release-notes [output_path]
|
||||
```
|
||||
|
||||
- `output_path` is optional, defaults to `../../release_notes.md`
|
||||
- The script expects `UNRELEASED_CHANGELOG.md` to be at `../../UNRELEASED_CHANGELOG.md` (relative to the script location)
|
||||
|
||||
### 2. Extraction Process
|
||||
|
||||
The `extractChangelogContent()` function:
|
||||
|
||||
1. Reads the UNRELEASED_CHANGELOG.md file
|
||||
2. Filters out:
|
||||
- The main "# Unreleased Changes" header
|
||||
- HTML comments (`<!-- ... -->`)
|
||||
- Empty sections (sections with no bullet points)
|
||||
- Everything after the `---` separator (example entries)
|
||||
3. Preserves:
|
||||
- Section headers (## Added, ## Changed, etc.) that have content
|
||||
- Bullet points with actual text (both `-` and `*` styles)
|
||||
- Proper spacing between sections
|
||||
|
||||
### 3. File Structure Expected
|
||||
|
||||
```markdown
|
||||
# Unreleased Changes
|
||||
|
||||
<!-- Comments are ignored -->
|
||||
|
||||
## Added
|
||||
<!-- Section comments ignored -->
|
||||
- Actual content preserved
|
||||
- More content
|
||||
|
||||
## Changed
|
||||
<!-- Empty sections are omitted -->
|
||||
|
||||
## Fixed
|
||||
- Bug fixes included
|
||||
|
||||
---
|
||||
|
||||
### Example Entries:
|
||||
Everything after the --- is ignored
|
||||
```
|
||||
|
||||
### 4. Output Format
|
||||
|
||||
The generated `release_notes.md` contains only the actual changelog entries:
|
||||
|
||||
```markdown
|
||||
## Added
|
||||
- Actual content preserved
|
||||
- More content
|
||||
|
||||
## Fixed
|
||||
- Bug fixes included
|
||||
```
|
||||
|
||||
## Testing Results
|
||||
|
||||
### ✅ Successful Tests
|
||||
|
||||
1. **Valid Content Extraction**: Successfully extracts and formats changelog entries
|
||||
2. **Empty Changelog Detection**: Properly fails when no content exists
|
||||
3. **Comment Filtering**: Correctly removes HTML comments
|
||||
4. **Mixed Bullet Styles**: Handles both `-` and `*` bullet points
|
||||
5. **Custom Output Path**: Supports specifying custom output file location
|
||||
6. **Flag Compatibility**: Works with `--check-only` and `--extract-changelog` flags
|
||||
|
||||
### Test Commands Run
|
||||
|
||||
```bash
|
||||
# Create release notes with default path
|
||||
go run release.go --create-release-notes
|
||||
|
||||
# Create with custom path
|
||||
go run release.go --create-release-notes /path/to/output.md
|
||||
|
||||
# Check if content exists
|
||||
go run release.go --check-only
|
||||
|
||||
# Extract content to stdout
|
||||
go run release.go --extract-changelog
|
||||
```
|
||||
|
||||
## Integration with GitHub Workflow
|
||||
|
||||
The nightly release workflow should:
|
||||
|
||||
1. Run `go run release.go --create-release-notes` before the main release task
|
||||
2. Use the generated `release_notes.md` for the GitHub release body
|
||||
3. The main release task will clear UNRELEASED_CHANGELOG.md after processing
|
||||
|
||||
## Error Handling
|
||||
|
||||
The script will exit with status 1 if:
|
||||
- UNRELEASED_CHANGELOG.md doesn't exist
|
||||
- No actual content is found (only template/comments)
|
||||
- File write operations fail
|
||||
|
||||
## Benefits
|
||||
|
||||
1. **Separation of Concerns**: Changelog extraction happens before the file is cleared
|
||||
2. **Clean Output**: No template text or comments in release notes
|
||||
3. **Testable**: Can be run and tested independently
|
||||
4. **Flexible**: Supports custom output paths
|
||||
5. **Consistent**: Same extraction logic used by all flags
|
||||
499
v3/tasks/release/release_create_notes_test.go
Normal file
499
v3/tasks/release/release_create_notes_test.go
Normal file
|
|
@ -0,0 +1,499 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestExtractChangelogContent tests the extractChangelogContent function with various inputs
|
||||
func TestExtractChangelogContent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
expected string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "Full changelog with all sections",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
<!-- Comments -->
|
||||
|
||||
## Added
|
||||
- New feature 1
|
||||
- New feature 2
|
||||
|
||||
## Changed
|
||||
- Changed item 1
|
||||
|
||||
## Fixed
|
||||
- Bug fix 1
|
||||
- Bug fix 2
|
||||
|
||||
## Deprecated
|
||||
- Deprecated feature
|
||||
|
||||
## Removed
|
||||
- Removed feature
|
||||
|
||||
## Security
|
||||
- Security fix
|
||||
|
||||
---
|
||||
|
||||
### Example Entries:
|
||||
|
||||
**Added:**
|
||||
- Example entry
|
||||
`,
|
||||
expected: `## Added
|
||||
- New feature 1
|
||||
- New feature 2
|
||||
|
||||
## Changed
|
||||
- Changed item 1
|
||||
|
||||
## Fixed
|
||||
- Bug fix 1
|
||||
- Bug fix 2
|
||||
|
||||
## Deprecated
|
||||
- Deprecated feature
|
||||
|
||||
## Removed
|
||||
- Removed feature
|
||||
|
||||
## Security
|
||||
- Security fix`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Only Added section with content",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
- Add Windows dark theme support
|
||||
- Add new flag to release script
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
|
||||
---
|
||||
### Example Entries:
|
||||
`,
|
||||
expected: `## Added
|
||||
- Add Windows dark theme support
|
||||
- Add new flag to release script`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Empty sections should not be included",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
- Update Go version to 1.23
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
|
||||
---
|
||||
`,
|
||||
expected: `## Changed
|
||||
- Update Go version to 1.23`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "No content returns empty string",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
|
||||
---
|
||||
`,
|
||||
expected: "",
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Comments should be excluded",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
<!-- This is a comment -->
|
||||
|
||||
## Added
|
||||
<!-- Another comment -->
|
||||
- Real content here
|
||||
<!-- Mid-section comment -->
|
||||
- More content
|
||||
|
||||
---
|
||||
`,
|
||||
expected: `## Added
|
||||
- Real content here
|
||||
- More content`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Multi-line comments handled correctly",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
<!--
|
||||
Multi-line
|
||||
comment
|
||||
-->
|
||||
|
||||
## Added
|
||||
- Feature 1
|
||||
<!-- Another
|
||||
multi-line comment
|
||||
that spans lines -->
|
||||
- Feature 2
|
||||
|
||||
---
|
||||
`,
|
||||
expected: `## Added
|
||||
- Feature 1
|
||||
- Feature 2`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Mixed bullet point styles",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
- Dash bullet point
|
||||
* Asterisk bullet point
|
||||
- Another dash
|
||||
|
||||
---
|
||||
`,
|
||||
expected: `## Added
|
||||
- Dash bullet point
|
||||
* Asterisk bullet point
|
||||
- Another dash`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "Trailing empty lines removed",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
- Feature 1
|
||||
|
||||
|
||||
## Changed
|
||||
- Change 1
|
||||
|
||||
|
||||
|
||||
---
|
||||
`,
|
||||
expected: `## Added
|
||||
- Feature 1
|
||||
|
||||
## Changed
|
||||
- Change 1`,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create a temporary file
|
||||
tmpDir := t.TempDir()
|
||||
tmpFile := filepath.Join(tmpDir, "UNRELEASED_CHANGELOG.md")
|
||||
err := os.WriteFile(tmpFile, []byte(tt.content), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
|
||||
// Save original path and update it
|
||||
originalPath := unreleasedChangelogFile
|
||||
unreleasedChangelogFile = tmpFile
|
||||
defer func() {
|
||||
unreleasedChangelogFile = originalPath
|
||||
}()
|
||||
|
||||
// Test the function
|
||||
got, err := extractChangelogContent()
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("extractChangelogContent() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if got != tt.expected {
|
||||
t.Errorf("extractChangelogContent() = %q, want %q", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCreateReleaseNotes tests the --create-release-notes functionality
|
||||
func TestCreateReleaseNotes(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
changelogContent string
|
||||
expectSuccess bool
|
||||
expectedNotes string
|
||||
}{
|
||||
{
|
||||
name: "Valid changelog creates release notes",
|
||||
changelogContent: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
- New feature X
|
||||
- New feature Y
|
||||
|
||||
## Fixed
|
||||
- Bug fix A
|
||||
|
||||
---
|
||||
### Examples:
|
||||
`,
|
||||
expectSuccess: true,
|
||||
expectedNotes: `## Added
|
||||
- New feature X
|
||||
- New feature Y
|
||||
|
||||
## Fixed
|
||||
- Bug fix A`,
|
||||
},
|
||||
{
|
||||
name: "Empty changelog fails",
|
||||
changelogContent: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
|
||||
---
|
||||
`,
|
||||
expectSuccess: false,
|
||||
expectedNotes: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create temporary directory
|
||||
tmpDir := t.TempDir()
|
||||
|
||||
// Create UNRELEASED_CHANGELOG.md
|
||||
changelogPath := filepath.Join(tmpDir, "UNRELEASED_CHANGELOG.md")
|
||||
err := os.WriteFile(changelogPath, []byte(tt.changelogContent), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create changelog file: %v", err)
|
||||
}
|
||||
|
||||
// Create release notes path
|
||||
releaseNotesPath := filepath.Join(tmpDir, "release_notes.md")
|
||||
|
||||
// Save original path
|
||||
originalPath := unreleasedChangelogFile
|
||||
unreleasedChangelogFile = changelogPath
|
||||
defer func() {
|
||||
unreleasedChangelogFile = originalPath
|
||||
}()
|
||||
|
||||
// Test the create release notes flow
|
||||
content, err := extractChangelogContent()
|
||||
if err != nil && tt.expectSuccess {
|
||||
t.Fatalf("Failed to extract content: %v", err)
|
||||
}
|
||||
|
||||
if tt.expectSuccess {
|
||||
if content == "" {
|
||||
t.Error("Expected content but got empty string")
|
||||
} else {
|
||||
// Write the release notes
|
||||
err = os.WriteFile(releaseNotesPath, []byte(content), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to write release notes: %v", err)
|
||||
}
|
||||
|
||||
// Verify the file was created
|
||||
data, err := os.ReadFile(releaseNotesPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read release notes: %v", err)
|
||||
}
|
||||
|
||||
if string(data) != tt.expectedNotes {
|
||||
t.Errorf("Release notes = %q, want %q", string(data), tt.expectedNotes)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if content != "" {
|
||||
t.Errorf("Expected no content but got: %q", content)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestHasUnreleasedContent tests the hasUnreleasedContent function
|
||||
func TestHasUnreleasedContent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
name: "Has content",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
- New feature
|
||||
|
||||
---
|
||||
`,
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
name: "No content",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
|
||||
---
|
||||
`,
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create temporary file
|
||||
tmpDir := t.TempDir()
|
||||
tmpFile := filepath.Join(tmpDir, "UNRELEASED_CHANGELOG.md")
|
||||
err := os.WriteFile(tmpFile, []byte(tt.content), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
|
||||
// Save original path
|
||||
originalPath := unreleasedChangelogFile
|
||||
unreleasedChangelogFile = tmpFile
|
||||
defer func() {
|
||||
unreleasedChangelogFile = originalPath
|
||||
}()
|
||||
|
||||
// Test the function
|
||||
got, err := hasUnreleasedContent()
|
||||
if err != nil {
|
||||
t.Fatalf("hasUnreleasedContent() error = %v", err)
|
||||
}
|
||||
|
||||
if got != tt.expected {
|
||||
t.Errorf("hasUnreleasedContent() = %v, want %v", got, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestVersionIncrement tests version incrementing logic
|
||||
func TestVersionIncrement(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
currentVersion string
|
||||
expectedNext string
|
||||
}{
|
||||
{
|
||||
name: "Alpha version increment",
|
||||
currentVersion: "v3.0.0-alpha.15",
|
||||
expectedNext: "v3.0.0-alpha.16",
|
||||
},
|
||||
{
|
||||
name: "Beta version increment",
|
||||
currentVersion: "v3.0.0-beta.5",
|
||||
expectedNext: "v3.0.0-beta.6",
|
||||
},
|
||||
{
|
||||
name: "Regular version increment",
|
||||
currentVersion: "v3.0.0",
|
||||
expectedNext: "v3.0.1",
|
||||
},
|
||||
{
|
||||
name: "Patch version increment",
|
||||
currentVersion: "v3.1.5",
|
||||
expectedNext: "v3.1.6",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Test incrementPatchVersion for regular versions
|
||||
if !strings.Contains(tt.currentVersion, "-") {
|
||||
got := incrementPatchVersion(tt.currentVersion)
|
||||
// Note: incrementPatchVersion writes to file, so we just check the return value
|
||||
if got != tt.expectedNext {
|
||||
t.Errorf("incrementPatchVersion(%s) = %s, want %s", tt.currentVersion, got, tt.expectedNext)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestClearUnreleasedChangelog tests the changelog reset functionality
|
||||
func TestClearUnreleasedChangelog(t *testing.T) {
|
||||
// Create temporary file
|
||||
tmpDir := t.TempDir()
|
||||
tmpFile := filepath.Join(tmpDir, "UNRELEASED_CHANGELOG.md")
|
||||
|
||||
// Write some content
|
||||
err := os.WriteFile(tmpFile, []byte("Some content"), 0644)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create test file: %v", err)
|
||||
}
|
||||
|
||||
// Save original path
|
||||
originalPath := unreleasedChangelogFile
|
||||
unreleasedChangelogFile = tmpFile
|
||||
defer func() {
|
||||
unreleasedChangelogFile = originalPath
|
||||
}()
|
||||
|
||||
// Clear the changelog
|
||||
err = clearUnreleasedChangelog()
|
||||
if err != nil {
|
||||
t.Fatalf("clearUnreleasedChangelog() error = %v", err)
|
||||
}
|
||||
|
||||
// Read the file
|
||||
content, err := os.ReadFile(tmpFile)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to read cleared file: %v", err)
|
||||
}
|
||||
|
||||
// Check it contains the template
|
||||
if !strings.Contains(string(content), "# Unreleased Changes") {
|
||||
t.Error("Cleared file doesn't contain template header")
|
||||
}
|
||||
if !strings.Contains(string(content), "## Added") {
|
||||
t.Error("Cleared file doesn't contain Added section")
|
||||
}
|
||||
if !strings.Contains(string(content), "### Example Entries:") {
|
||||
t.Error("Cleared file doesn't contain example section")
|
||||
}
|
||||
}
|
||||
172
v3/tasks/release/test_create_release_notes.go
Normal file
172
v3/tasks/release/test_create_release_notes.go
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Testing release.go --create-release-notes functionality")
|
||||
fmt.Println("=" + strings.Repeat("=", 50))
|
||||
|
||||
// Test cases
|
||||
testCases := []struct {
|
||||
name string
|
||||
content string
|
||||
expected string
|
||||
shouldFail bool
|
||||
}{
|
||||
{
|
||||
name: "Valid changelog with content",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
<!-- Comments -->
|
||||
|
||||
## Added
|
||||
- Add Windows dark theme support for menus
|
||||
- Add new --create-release-notes flag
|
||||
|
||||
## Changed
|
||||
- Update Go version to 1.23
|
||||
- Improve error handling
|
||||
|
||||
## Fixed
|
||||
- Fix nightly release workflow
|
||||
- Fix changelog extraction
|
||||
|
||||
---
|
||||
|
||||
### Example Entries:
|
||||
Example content here`,
|
||||
expected: `## Added
|
||||
- Add Windows dark theme support for menus
|
||||
- Add new --create-release-notes flag
|
||||
|
||||
## Changed
|
||||
- Update Go version to 1.23
|
||||
- Improve error handling
|
||||
|
||||
## Fixed
|
||||
- Fix nightly release workflow
|
||||
- Fix changelog extraction`,
|
||||
shouldFail: false,
|
||||
},
|
||||
{
|
||||
name: "Empty changelog",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
<!-- Changes -->
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
|
||||
---`,
|
||||
expected: "",
|
||||
shouldFail: true,
|
||||
},
|
||||
{
|
||||
name: "Only one section with content",
|
||||
content: `# Unreleased Changes
|
||||
|
||||
## Added
|
||||
<!-- New features -->
|
||||
|
||||
## Changed
|
||||
- Single change item here
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
|
||||
---`,
|
||||
expected: `## Changed
|
||||
- Single change item here`,
|
||||
shouldFail: false,
|
||||
},
|
||||
}
|
||||
|
||||
// Create a temporary directory for testing
|
||||
tmpDir, err := os.MkdirTemp("", "release-test-*")
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to create temp dir: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
// Save current directory
|
||||
originalDir, _ := os.Getwd()
|
||||
|
||||
for i, tc := range testCases {
|
||||
fmt.Printf("\nTest %d: %s\n", i+1, tc.name)
|
||||
fmt.Println("-" + strings.Repeat("-", 40))
|
||||
|
||||
// Create test changelog
|
||||
changelogPath := filepath.Join(tmpDir, "UNRELEASED_CHANGELOG.md")
|
||||
err = os.WriteFile(changelogPath, []byte(tc.content), 0644)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Failed to write test changelog: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// Create release notes path
|
||||
releaseNotesPath := filepath.Join(tmpDir, fmt.Sprintf("release_notes_%d.md", i))
|
||||
|
||||
// Change to temp dir (so relative paths work)
|
||||
os.Chdir(tmpDir)
|
||||
|
||||
// Run the command
|
||||
cmd := exec.Command("go", "run", filepath.Join(originalDir, "release.go"), "--create-release-notes", releaseNotesPath)
|
||||
output, err := cmd.CombinedOutput()
|
||||
|
||||
// Change back
|
||||
os.Chdir(originalDir)
|
||||
|
||||
if tc.shouldFail {
|
||||
if err == nil {
|
||||
fmt.Printf("❌ Expected failure but command succeeded\n")
|
||||
fmt.Printf("Output: %s\n", output)
|
||||
} else {
|
||||
fmt.Printf("✅ Failed as expected: %v\n", err)
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Command failed: %v\n", err)
|
||||
fmt.Printf("Output: %s\n", output)
|
||||
} else {
|
||||
fmt.Printf("✅ Command succeeded\n")
|
||||
|
||||
// Read and verify the output
|
||||
content, err := os.ReadFile(releaseNotesPath)
|
||||
if err != nil {
|
||||
fmt.Printf("❌ Failed to read release notes: %v\n", err)
|
||||
} else {
|
||||
actualContent := strings.TrimSpace(string(content))
|
||||
expectedContent := strings.TrimSpace(tc.expected)
|
||||
|
||||
if actualContent == expectedContent {
|
||||
fmt.Printf("✅ Content matches expected\n")
|
||||
} else {
|
||||
fmt.Printf("❌ Content mismatch\n")
|
||||
fmt.Printf("Expected:\n%s\n", expectedContent)
|
||||
fmt.Printf("Actual:\n%s\n", actualContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up
|
||||
os.Remove(changelogPath)
|
||||
os.Remove(releaseNotesPath)
|
||||
}
|
||||
|
||||
fmt.Println("\n" + "=" + strings.Repeat("=", 50))
|
||||
fmt.Println("Testing complete!")
|
||||
}
|
||||
111
v3/tasks/release/test_edge_cases.bat
Normal file
111
v3/tasks/release/test_edge_cases.bat
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
@echo off
|
||||
echo Testing edge cases for release.go
|
||||
echo =================================
|
||||
|
||||
set ORIGINAL_DIR=%CD%
|
||||
cd ..\..
|
||||
|
||||
REM Backup existing file
|
||||
if exist UNRELEASED_CHANGELOG.md (
|
||||
copy UNRELEASED_CHANGELOG.md UNRELEASED_CHANGELOG.md.backup > nul
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 1: Empty changelog (should fail)
|
||||
echo -------------------------------------
|
||||
|
||||
REM Create empty changelog
|
||||
echo # Unreleased Changes > UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Added >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- New features --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Changed >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Changes --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Fixed >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Bug fixes --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo --- >> UNRELEASED_CHANGELOG.md
|
||||
|
||||
cd tasks\release
|
||||
go run release.go --create-release-notes 2>&1
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo SUCCESS: Command failed as expected for empty changelog
|
||||
) else (
|
||||
echo FAIL: Command should have failed for empty changelog
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 2: Only comments (should fail)
|
||||
echo -----------------------------------
|
||||
|
||||
cd ..\..
|
||||
echo # Unreleased Changes > UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Added >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- This is just a comment --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Another comment --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo --- >> UNRELEASED_CHANGELOG.md
|
||||
|
||||
cd tasks\release
|
||||
go run release.go --create-release-notes 2>&1
|
||||
if %ERRORLEVEL% NEQ 0 (
|
||||
echo SUCCESS: Command failed as expected for comment-only changelog
|
||||
) else (
|
||||
echo FAIL: Command should have failed for comment-only changelog
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 3: Mixed bullet styles
|
||||
echo ---------------------------
|
||||
|
||||
cd ..\..
|
||||
echo # Unreleased Changes > UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Added >> UNRELEASED_CHANGELOG.md
|
||||
echo - Dash bullet point >> UNRELEASED_CHANGELOG.md
|
||||
echo * Asterisk bullet point >> UNRELEASED_CHANGELOG.md
|
||||
echo - Another dash >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo --- >> UNRELEASED_CHANGELOG.md
|
||||
|
||||
cd tasks\release
|
||||
go run release.go --create-release-notes
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo SUCCESS: Mixed bullet styles handled
|
||||
echo Content:
|
||||
type ..\..\release_notes.md
|
||||
) else (
|
||||
echo FAIL: Mixed bullet styles should work
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 4: Custom output path
|
||||
echo --------------------------
|
||||
|
||||
go run release.go --create-release-notes ..\..\custom_notes.md
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
if exist "..\..\custom_notes.md" (
|
||||
echo SUCCESS: Custom path works
|
||||
del ..\..\custom_notes.md
|
||||
) else (
|
||||
echo FAIL: Custom path file not created
|
||||
)
|
||||
) else (
|
||||
echo FAIL: Custom path should work
|
||||
)
|
||||
|
||||
REM Clean up
|
||||
cd ..\..
|
||||
if exist release_notes.md del release_notes.md
|
||||
if exist UNRELEASED_CHANGELOG.md.backup (
|
||||
move /Y UNRELEASED_CHANGELOG.md.backup UNRELEASED_CHANGELOG.md > nul
|
||||
)
|
||||
|
||||
cd %ORIGINAL_DIR%
|
||||
|
||||
echo.
|
||||
echo =================================
|
||||
echo Edge case testing complete!
|
||||
115
v3/tasks/release/test_simple.bat
Normal file
115
v3/tasks/release/test_simple.bat
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
@echo off
|
||||
echo Testing release.go --create-release-notes functionality
|
||||
echo ======================================================
|
||||
|
||||
REM Save current directory
|
||||
set ORIGINAL_DIR=%CD%
|
||||
|
||||
REM Go to v3 root (where UNRELEASED_CHANGELOG.md should be)
|
||||
cd ..\..
|
||||
|
||||
REM Backup existing UNRELEASED_CHANGELOG.md if it exists
|
||||
if exist UNRELEASED_CHANGELOG.md (
|
||||
copy UNRELEASED_CHANGELOG.md UNRELEASED_CHANGELOG.md.backup > nul
|
||||
)
|
||||
|
||||
REM Create a test UNRELEASED_CHANGELOG.md
|
||||
echo # Unreleased Changes > UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- >> UNRELEASED_CHANGELOG.md
|
||||
echo This file is used to collect changelog entries for the next v3-alpha release. >> UNRELEASED_CHANGELOG.md
|
||||
echo --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Added >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- New features, capabilities, or enhancements --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo - Add Windows dark theme support for menus and menubar >> UNRELEASED_CHANGELOG.md
|
||||
echo - Add `--create-release-notes` flag to release script >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Changed >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Changes in existing functionality --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo - Update Go version to 1.23 in workflow >> UNRELEASED_CHANGELOG.md
|
||||
echo - Improve error handling in release process >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Fixed >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Bug fixes --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo - Fix nightly release workflow changelog extraction >> UNRELEASED_CHANGELOG.md
|
||||
echo - Fix Go cache configuration in GitHub Actions >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Deprecated >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Soon-to-be removed features --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Removed >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Features removed in this release --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ## Security >> UNRELEASED_CHANGELOG.md
|
||||
echo ^<^!-- Security-related changes --^> >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo --- >> UNRELEASED_CHANGELOG.md
|
||||
echo. >> UNRELEASED_CHANGELOG.md
|
||||
echo ### Example Entries: >> UNRELEASED_CHANGELOG.md
|
||||
|
||||
echo.
|
||||
echo Test 1: Running with valid content
|
||||
echo -----------------------------------
|
||||
|
||||
REM Run the release script
|
||||
cd tasks\release
|
||||
go run release.go --create-release-notes
|
||||
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo SUCCESS: Command succeeded
|
||||
|
||||
REM Check if release_notes.md was created
|
||||
if exist "..\..\release_notes.md" (
|
||||
echo SUCCESS: release_notes.md was created
|
||||
echo.
|
||||
echo Content:
|
||||
echo --------
|
||||
type ..\..\release_notes.md
|
||||
echo.
|
||||
echo --------
|
||||
) else (
|
||||
echo FAIL: release_notes.md was NOT created
|
||||
)
|
||||
) else (
|
||||
echo FAIL: Command failed
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 2: Check --check-only flag
|
||||
echo --------------------------------
|
||||
|
||||
REM Test the check-only flag
|
||||
go run release.go --check-only
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo SUCCESS: --check-only detected content
|
||||
) else (
|
||||
echo FAIL: --check-only did not detect content
|
||||
)
|
||||
|
||||
echo.
|
||||
echo Test 3: Check --extract-changelog flag
|
||||
echo --------------------------------------
|
||||
|
||||
REM Test the extract-changelog flag
|
||||
go run release.go --extract-changelog
|
||||
if %ERRORLEVEL% EQU 0 (
|
||||
echo SUCCESS: --extract-changelog succeeded
|
||||
) else (
|
||||
echo FAIL: --extract-changelog failed
|
||||
)
|
||||
|
||||
REM Clean up
|
||||
cd ..\..
|
||||
if exist release_notes.md del release_notes.md
|
||||
|
||||
REM Restore original UNRELEASED_CHANGELOG.md if it exists
|
||||
if exist UNRELEASED_CHANGELOG.md.backup (
|
||||
move /Y UNRELEASED_CHANGELOG.md.backup UNRELEASED_CHANGELOG.md > nul
|
||||
)
|
||||
|
||||
cd %ORIGINAL_DIR%
|
||||
|
||||
echo.
|
||||
echo ======================================================
|
||||
echo Testing complete!
|
||||
118
v3/tasks/release/test_simple.sh
Normal file
118
v3/tasks/release/test_simple.sh
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
#!/bin/bash
|
||||
|
||||
echo "Testing release.go --create-release-notes functionality"
|
||||
echo "======================================================"
|
||||
|
||||
# Save current directory
|
||||
ORIGINAL_DIR=$(pwd)
|
||||
|
||||
# Go to v3 root (where UNRELEASED_CHANGELOG.md should be)
|
||||
cd ../..
|
||||
|
||||
# Create a test UNRELEASED_CHANGELOG.md
|
||||
cat > UNRELEASED_CHANGELOG.md << 'EOF'
|
||||
# Unreleased Changes
|
||||
|
||||
<!--
|
||||
This file is used to collect changelog entries for the next v3-alpha release.
|
||||
-->
|
||||
|
||||
## Added
|
||||
<!-- New features, capabilities, or enhancements -->
|
||||
- Add Windows dark theme support for menus and menubar
|
||||
- Add `--create-release-notes` flag to release script
|
||||
|
||||
## Changed
|
||||
<!-- Changes in existing functionality -->
|
||||
- Update Go version to 1.23 in workflow
|
||||
- Improve error handling in release process
|
||||
|
||||
## Fixed
|
||||
<!-- Bug fixes -->
|
||||
- Fix nightly release workflow changelog extraction
|
||||
- Fix Go cache configuration in GitHub Actions
|
||||
|
||||
## Deprecated
|
||||
<!-- Soon-to-be removed features -->
|
||||
|
||||
## Removed
|
||||
<!-- Features removed in this release -->
|
||||
|
||||
## Security
|
||||
<!-- Security-related changes -->
|
||||
|
||||
---
|
||||
|
||||
### Example Entries:
|
||||
|
||||
**Added:**
|
||||
- Example content
|
||||
EOF
|
||||
|
||||
echo ""
|
||||
echo "Test 1: Running with valid content"
|
||||
echo "-----------------------------------"
|
||||
|
||||
# Run the release script
|
||||
cd tasks/release
|
||||
if go run release.go --create-release-notes; then
|
||||
echo "✅ Command succeeded"
|
||||
|
||||
# Check if release_notes.md was created
|
||||
if [ -f "../../release_notes.md" ]; then
|
||||
echo "✅ release_notes.md was created"
|
||||
echo ""
|
||||
echo "Content:"
|
||||
echo "--------"
|
||||
cat ../../release_notes.md
|
||||
echo ""
|
||||
echo "--------"
|
||||
else
|
||||
echo "❌ release_notes.md was NOT created"
|
||||
fi
|
||||
else
|
||||
echo "❌ Command failed"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Test 2: Check --check-only flag"
|
||||
echo "--------------------------------"
|
||||
|
||||
# Test the check-only flag
|
||||
if go run release.go --check-only; then
|
||||
echo "✅ --check-only detected content"
|
||||
else
|
||||
echo "❌ --check-only did not detect content"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "Test 3: Check --extract-changelog flag"
|
||||
echo "--------------------------------------"
|
||||
|
||||
# Test the extract-changelog flag
|
||||
OUTPUT=$(go run release.go --extract-changelog 2>&1)
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "✅ --extract-changelog succeeded"
|
||||
echo "Output:"
|
||||
echo "-------"
|
||||
echo "$OUTPUT"
|
||||
echo "-------"
|
||||
else
|
||||
echo "❌ --extract-changelog failed"
|
||||
echo "Error: $OUTPUT"
|
||||
fi
|
||||
|
||||
# Clean up
|
||||
cd ../..
|
||||
rm -f release_notes.md
|
||||
|
||||
# Restore original UNRELEASED_CHANGELOG.md if it exists
|
||||
if [ -f "UNRELEASED_CHANGELOG.md.backup" ]; then
|
||||
mv UNRELEASED_CHANGELOG.md.backup UNRELEASED_CHANGELOG.md
|
||||
fi
|
||||
|
||||
cd "$ORIGINAL_DIR"
|
||||
|
||||
echo ""
|
||||
echo "======================================================"
|
||||
echo "Testing complete!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue