Skip to content

Release v0.1.2#4

Merged
c-vigo merged 5 commits intomainfrom
dev
Jan 28, 2026
Merged

Release v0.1.2#4
c-vigo merged 5 commits intomainfrom
dev

Conversation

@c-vigo
Copy link
Contributor

@c-vigo c-vigo commented Jan 28, 2026

Description

This PR adds support for TARGET_BRANCH environment variable to resolve branch selection conflicts with GitHub's built-in GITHUB_REF, improves branch normalization logic, fixes security vulnerabilities, and adds comprehensive test coverage.

Related Issue(s)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Test updates
  • Documentation update

Changes Made

  • Added TARGET_BRANCH environment variable support: New preferred environment variable to specify target branch, avoiding conflicts when workflow runs on a different branch than the commit target
  • Implemented branch normalization functions: Extracted normalizeBranch() and resolveBranch() as exported, testable functions that handle various Git reference formats (refs/heads/, refs/tags/, plain branch names)
  • Improved branch resolution priority: Explicit priority order: TARGET_BRANCH > GITHUB_REF (if different from context) > workflow context
  • Fixed security vulnerabilities: Added npm package overrides to force @actions/http-client@3.0.2 and undici@6.23.0 to resolve moderate severity vulnerability
  • Fixed Jest ESM module resolution: Added manual mock for @actions/github to resolve ESM module resolution issues in tests
  • Added comprehensive test suite: Created commit-runner.test.ts with 17 new test cases covering branch normalization and resolution logic
  • Updated documentation: Enhanced README with TARGET_BRANCH usage examples and explanation of branch resolution behavior
  • Updated CHANGELOG: Documented all changes in the Unreleased section

Testing

  • Tests pass locally (npm test)
  • Manual testing performed (describe below)

Manual Testing Details

  • Verified branch normalization handles various formats: refs/heads/main, refs/tags/v1.0.0, plain main
  • Confirmed TARGET_BRANCH takes precedence over GITHUB_REF when both are set
  • Verified fallback to workflow context when neither TARGET_BRANCH nor GITHUB_REF differ from context
  • All 26 unit tests pass (9 existing + 17 new)
  • ESLint passes with no warnings or errors
  • npm audit shows 0 vulnerabilities after fixes

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have updated the documentation accordingly (README.md, CONTRIBUTE.md, etc.)
  • I have updated the CHANGELOG.md in the [Unreleased] section
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Key Improvements

  1. Branch Resolution Fix: The original issue where GITHUB_REF: refs/heads/main was being ignored when the workflow ran on dev branch is now resolved. Users can use TARGET_BRANCH to explicitly set the commit target branch.

  2. Security: Fixed npm audit vulnerabilities by adding package overrides. This ensures all dependencies use secure versions without requiring major dependency updates.

  3. Testability: Refactored branch resolution logic into pure, testable functions with comprehensive test coverage (17 test cases covering edge cases).

  4. Backward Compatibility: All changes are backward compatible. Existing workflows using GITHUB_REF will continue to work, with improved behavior when it differs from the workflow context.

Files Changed

  • src/commit-runner.ts - Added exported normalizeBranch() and resolveBranch() functions, refactored main() to use them
  • src/__tests__/unit/commit-runner.test.ts - New test file with 17 test cases
  • src/__tests__/__mocks__/@actions/github.ts - Manual mock for ESM module resolution
  • src/__tests__/setup.ts - Simplified to use manual mock
  • package.json - Added npm overrides for security fixes
  • package-lock.json - Updated dependencies
  • README.md - Added TARGET_BRANCH documentation and usage examples
  • CHANGELOG.md - Documented all changes

Example Usage

- name: Commit and push changes via API
  uses: vig-os/commit-action@v0.1.2
  env:
    GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    TARGET_BRANCH: refs/heads/main  # Preferred: avoids conflicts
    COMMIT_MESSAGE: "chore: update files"
    FILE_PATHS: "docs"

- Bumped version to 0.1.1 in package.json and package-lock.json.
- Updated @actions/github and other dependencies to their latest versions.
- Added manual mock for @actions/github in tests.
- Updated commit-runner.ts to support TARGET_BRANCH environment variable for branch resolution.
- Added normalizeBranch (placeholder) and resolveBranch functions to handle various Git reference formats.
- Implemented logic to prioritize TARGET_BRANCH over GITHUB_REF and context reference.
- Introduced unit tests for new functions to ensure correct behavior across different scenarios.
@c-vigo c-vigo self-assigned this Jan 28, 2026
@c-vigo c-vigo merged commit ed561cf into main Jan 28, 2026
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.

1 participant