Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for
TARGET_BRANCHenvironment variable to resolve branch selection conflicts with GitHub's built-inGITHUB_REF, improves branch normalization logic, fixes security vulnerabilities, and adds comprehensive test coverage.Related Issue(s)
Type of Change
Changes Made
TARGET_BRANCHenvironment variable support: New preferred environment variable to specify target branch, avoiding conflicts when workflow runs on a different branch than the commit targetnormalizeBranch()andresolveBranch()as exported, testable functions that handle various Git reference formats (refs/heads/,refs/tags/, plain branch names)TARGET_BRANCH>GITHUB_REF(if different from context) > workflow context@actions/http-client@3.0.2andundici@6.23.0to resolve moderate severity vulnerability@actions/githubto resolve ESM module resolution issues in testscommit-runner.test.tswith 17 new test cases covering branch normalization and resolution logicTARGET_BRANCHusage examples and explanation of branch resolution behaviorTesting
npm test)Manual Testing Details
refs/heads/main,refs/tags/v1.0.0, plainmainTARGET_BRANCHtakes precedence overGITHUB_REFwhen both are setTARGET_BRANCHnorGITHUB_REFdiffer from contextChecklist
[Unreleased]sectionAdditional Notes
Key Improvements
Branch Resolution Fix: The original issue where
GITHUB_REF: refs/heads/mainwas being ignored when the workflow ran ondevbranch is now resolved. Users can useTARGET_BRANCHto explicitly set the commit target branch.Security: Fixed npm audit vulnerabilities by adding package overrides. This ensures all dependencies use secure versions without requiring major dependency updates.
Testability: Refactored branch resolution logic into pure, testable functions with comprehensive test coverage (17 test cases covering edge cases).
Backward Compatibility: All changes are backward compatible. Existing workflows using
GITHUB_REFwill continue to work, with improved behavior when it differs from the workflow context.Files Changed
src/commit-runner.ts- Added exportednormalizeBranch()andresolveBranch()functions, refactored main() to use themsrc/__tests__/unit/commit-runner.test.ts- New test file with 17 test casessrc/__tests__/__mocks__/@actions/github.ts- Manual mock for ESM module resolutionsrc/__tests__/setup.ts- Simplified to use manual mockpackage.json- Added npm overrides for security fixespackage-lock.json- Updated dependenciesREADME.md- AddedTARGET_BRANCHdocumentation and usage examplesCHANGELOG.md- Documented all changesExample Usage