Skip to content

Implement Automated Changelog System for CI/CD Integration #1640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 21, 2025

Conversation

ksylvan
Copy link
Collaborator

@ksylvan ksylvan commented Jul 21, 2025

Implement Automated Changelog System for CI/CD Integration

Summary

This pull request implements a comprehensive automated changelog system for CI/CD integration, adding new functionality to pre-process pull requests during development and aggregate changelog entries during release workflows.

Related Issues

Closes #1630

Files Changed

New Files Added

  • cmd/generate_changelog/incoming/1640.txt - Example incoming changelog entry for PR Implement Automated Changelog System for CI/CD Integration #1640
  • cmd/generate_changelog/internal/changelog/generator_test.go - Test coverage for changelog generation functionality
  • cmd/generate_changelog/internal/changelog/processing.go - Core processing logic for PR handling and release aggregation
  • cmd/generate_changelog/internal/changelog/processing_test.go - Comprehensive test suite for processing functionality
  • docs/Automated-ChangeLog.md - Technical specification and implementation details
  • docs/Automated-Changelog-Usage.md - Developer guide and usage documentation

Modified Files

  • .github/workflows/update-version-and-create-tag.yml - Updated CI/CD workflow to integrate changelog processing
  • .gitignore - Added .claude/ directory exclusion
  • .vscode/settings.json - Added new spell check words for project terminology
  • cmd/generate_changelog/internal/config/config.go - Extended configuration with new fields for PR processing
  • cmd/generate_changelog/internal/git/walker.go - Added git operations for staging, committing, and pushing changes
  • cmd/generate_changelog/internal/github/client.go - Enhanced GitHub API client with validation methods and PR details
  • cmd/generate_changelog/internal/github/types.go - Added PRDetails struct for comprehensive PR information
  • cmd/generate_changelog/main.go - Added new command-line flags and processing modes

Code Changes

Core Processing Logic (processing.go)

func (g *Generator) ProcessIncomingPR(prNumber int) error
func (g *Generator) CreateNewChangelogEntry(version string) error
func (g *Generator) getDirectCommitsSinceLastRelease(processedPRs map[int]bool, processedCommitSHAs map[string]bool) (string, error)

GitHub API Enhancements (client.go)

func (c *Client) GetPRValidationDetails(prNumber int) (*PRDetails, error)
func (c *Client) GetPRWithCommits(prNumber int) (*PR, error)
func (c *Client) buildPRWithCommits(ctx context.Context, ghPR *github.PullRequest) (*PR, error)

Git Operations (walker.go)

func (w *Walker) IsWorkingDirectoryClean() (bool, error)
func (w *Walker) AddFile(filename string) error
func (w *Walker) CommitChanges(message string) (plumbing.Hash, error)
func (w *Walker) PushToRemote() error

CI/CD Workflow Integration

- name: Generate Changelog Entry
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  run: |
    go run ./cmd/generate_changelog --process-prs ${{ env.new_tag }}

Reason for Changes

This implementation addresses the need for automated changelog generation in CI/CD pipelines while maintaining developer control over content quality. The system eliminates manual CHANGELOG.md editing, reduces merge conflicts, and ensures consistent formatting across releases.

Key motivations:

  • Developer Experience: Pre-process PR entries during development with AI-enhanced summaries
  • CI/CD Integration: Automatically aggregate entries during release workflows
  • Consistency: Standardized formatting and comprehensive coverage of all changes
  • Performance: Leverages existing caching and optimization infrastructure

Impact of Changes

Positive Impacts

  • Automated Workflow: Developers can generate changelog entries with --incoming-pr flag
  • Release Integration: CI/CD automatically processes incoming files with --process-prs
  • Reduced Conflicts: No multiple PRs editing CHANGELOG.md simultaneously
  • Enhanced Quality: AI-powered summaries provide professional, consistent formatting
  • Backward Compatibility: Existing changelog generation remains unchanged

Potential Risks

  • Git State Dependencies: Tool requires clean working directory for processing
  • GitHub API Rate Limits: Increased API usage for PR validation and commit fetching
  • File System Operations: Auto-commit and push functionality requires proper authentication
  • Validation Complexity: Multiple validation layers could introduce failure points

Test Plan

The implementation includes comprehensive test coverage:

Unit Tests

  • generator_test.go: Version detection, directory creation, changelog insertion
  • processing_test.go: File aggregation, error handling, validation logic
  • Tests cover edge cases like permission errors, malformed files, and git state validation

Integration Testing

  • PR validation workflow with GitHub API
  • Git operations including staging, committing, and pushing
  • End-to-end processing from incoming files to CHANGELOG.md updates

Manual Testing

  • Test with actual PR numbers for validation
  • Verify CI/CD integration in GitHub Actions workflow
  • Validate file cleanup and git staging operations

Additional Notes

Configuration Extensions

New configuration fields support the automated workflow:

  • IncomingPR: PR number for pre-processing
  • ProcessPRsVersion: Version string for release aggregation
  • IncomingDir: Directory path for incoming PR files
  • Push: Enable automatic git push after commits

Error Handling

Robust error handling covers:

  • PR state validation (open, mergeable)
  • Git working directory cleanliness
  • File system permissions and disk space
  • Network failures with GitHub API
  • Authentication issues for git operations

Developer Workflow

  1. Create PR and ensure it's mergeable
  2. Run generate_changelog --incoming-pr XXXX --ai-summarize
  3. Review generated incoming/XXXX.txt file
  4. Commit is auto-created; use --push for automatic remote push
  5. PR includes pre-processed changelog entry for review

The system maintains full backward compatibility while providing opt-in automation features that significantly improve the development and release process.

ksylvan added 3 commits July 20, 2025 17:47
## CHANGES

- Add incoming PR preprocessing with validation
- Implement release aggregation for incoming files
- Create git operations for staging changes
- Add comprehensive test coverage for processing
- Extend GitHub client with validation methods
- Support version detection from nix files
- Include documentation for automated workflow
- Add command flags for PR processing
- Add SilenceUsage to prevent help output on errors
- Add GetStatusDetails method to show which files are dirty
- Include direct commits in ProcessIncomingPRs for complete AI summaries
## CHANGES

- Add .claude/ directory to gitignore exclusions
- Update comment clarity for SilenceUsage flag
- Remove redundant error handling in main function
- Simplify command execution without explicit error checking
@ksylvan ksylvan marked this pull request as draft July 21, 2025 02:08
ksylvan added 3 commits July 20, 2025 20:33
## CHANGES

- Change `NoPush` config field to `Push` boolean
- Update CLI flag from `--no-push` to `--push`
- Add GitHub token authentication for push operations
- Import `os` and HTTP transport packages
- Reverse push logic to require explicit enable
- Update documentation for new push behavior
- Add automatic GitHub repository detection for auth
## CHANGES

- Extract PR numbers from processed changelog files
- Pass processed PRs map to direct commits function
- Filter out commits already included via PR files
- Reduce extra newlines in changelog version insertion
- Add strconv import for PR number parsing
- Prevent duplicate entries between PRs and direct commits
- Improve changelog formatting consistency
@ksylvan ksylvan force-pushed the 0720-changelog-during-ci-cd branch from fd4d068 to 9f242bc Compare July 21, 2025 05:50
…processing

## CHANGES

- Pass version parameter to changelog generation workflow
- Update ProcessIncomingPRs method to accept version string
- Add commit SHA tracking to prevent duplicate entries
- Modify process-prs flag to require version parameter
- Improve changelog formatting with proper spacing
- Update configuration to use ProcessPRsVersion string field
- Enhance direct commit filtering with SHA exclusion
- Update documentation to reflect version parameter requirement
@ksylvan ksylvan force-pushed the 0720-changelog-during-ci-cd branch from 9f242bc to 91c1aca Compare July 21, 2025 14:36
ksylvan and others added 4 commits July 21, 2025 08:25
…arity

## CHANGES

- Rename ProcessIncomingPRs method to CreateNewChangelogEntry
- Update method comment to reflect new name
- Update main.go to call renamed method
- Reduce newline spacing in content formatting
@ksylvan ksylvan force-pushed the 0720-changelog-during-ci-cd branch from 429a915 to cab6df8 Compare July 21, 2025 17:02
@ksylvan ksylvan marked this pull request as ready for review July 21, 2025 17:59
@ksylvan ksylvan requested a review from Copilot July 21, 2025 17:59
Copilot

This comment was marked as resolved.

@ksylvan ksylvan merged commit 07ee7f8 into danielmiessler:main Jul 21, 2025
1 check passed
@ksylvan ksylvan deleted the 0720-changelog-during-ci-cd branch July 21, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request]: CHANGELOG entries automatically added during CI/CD
1 participant