A powerful GitHub Action that extracts and processes information from commit messages using customizable patterns and commands.
- Flexible Pattern Matching: Extract information using regex patterns or custom commands
- Multiple Output Formats: Support for text, JSON, and CSV outputs
- Customizable Depth: Control the number of commits to analyze
- Fast & Lightweight: Built with Python 3.14-slim for optimal performance
- Fail-Safe Options: Optional validation with
fail_on_empty - Pretty Formatting: Clean, formatted commit message output
- Debug Mode: Verbose output for troubleshooting
- Timeout Control: Prevent long-running operations
- Easy Integration: Simple YAML configuration in your workflows
- name: Extract Environment from Commits
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'env:(\\w+)'"
pretty: true
key_variable: 'DEPLOY_ENV'| Input | Description | Required | Default |
|---|---|---|---|
commit_limit |
Number of commits to retrieve | Yes | N/A |
extract_command |
Command to extract info (e.g., grep pattern) | No | N/A |
pretty |
Use pretty format for Git logs | No | false |
key_variable |
Name of the output variable | No | ENVIRONMENT |
fail_on_empty |
Fail if no information is extracted | No | false |
output_format |
Output format: text, json, or csv |
No | text |
debug |
Enable debug mode for verbose output | No | false |
timeout |
Timeout in seconds for git/extract commands | No | 30 |
| Output | Description |
|---|---|
key_variable |
The name of the variable used |
value_variable |
The extracted value(s) from commits |
- name: Extract Environment
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'env:(\\w+)'"
pretty: true
key_variable: 'DEPLOY_ENV'- name: Extract Feature Tags
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'feature:(\\w+)'"
key_variable: 'FEATURE_TAG'- name: Extract Version
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'v[0-9]+\\.[0-9]+\\.[0-9]+'"
key_variable: 'VERSION'- name: Extract Critical Changes
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'critical:(\\w+)'"
key_variable: 'CRITICAL_CHANGES'
fail_on_empty: true # Fails if no matches found- name: Extract JIRA Tickets
id: jira
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 20
extract_command: "grep -oE 'JIRA-[0-9]+'"
key_variable: 'JIRA_TICKETS'
output_format: 'json'
- name: Process Tickets
run: |
echo '${{ steps.jira.outputs.value_variable }}' | jq -r '.[]'- name: Extract with Debug
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'env:(\\w+)'"
key_variable: 'ENVIRONMENT'
debug: true # Enable verbose output
timeout: 60 # Set custom timeoutThe action supports three output formats:
| Format | Description | Example Output |
|---|---|---|
text |
Plain text (default) | value1value2value3 |
json |
JSON array | ["value1", "value2", "value3"] |
csv |
Comma-separated | value1,value2,value3 |
Given extracted values: JIRA-123, JIRA-456, JIRA-789
JIRA-123
JIRA-456
JIRA-789
["JIRA-123", "JIRA-456", "JIRA-789"]JIRA-123,JIRA-456,JIRA-789
| Purpose | Command | Example Match |
|---|---|---|
| Environment | grep -oE 'env:(\\w+)' |
env:production |
| Fix IDs | grep -oE 'fix-[0-9]+' |
fix-123 |
| Versions | grep -oE 'v[0-9]+\\.[0-9]+\\.[0-9]+' |
v1.2.3 |
| Features | grep -oE 'feature:(\\w+)' |
feature:login |
| JIRA IDs | grep -oE 'JIRA-[0-9]+' |
JIRA-456 |
| Conventional Commits | `grep -oE '^(feat | fix |
Note: Use
grep -oE(Extended regex) instead ofgrep -oP(Perl regex) for better compatibility.
- Use consistent commit message formats (e.g., Conventional Commits)
- Include relevant tags or identifiers
- Example:
feat(auth): add login functionality env:production
- Test regex patterns locally before implementation:
echo "feat: add login env:production" | grep -oE 'env:(\\w+)'
- Use specific patterns to avoid false matches
- Consider edge cases and special characters
- Set appropriate
commit_limitbased on your needs - Lower values = faster execution
- Typical range: 10-50 commits
- Ensure sufficient
fetch-depthin checkout action:- uses: actions/checkout@v4 with: fetch-depth: 20 # Match or exceed commit_limit
- Verify commit messages contain expected patterns:
git log -10 --pretty=%B
- Test your regex pattern locally:
git log -10 --pretty=%B | grep -oE 'your-pattern'
- Ensure
fetch-depthin checkout is sufficient - Check if
fail_on_emptyis set appropriately
- Review and refine your regex pattern
- Use more specific patterns with word boundaries
- Test with sample commit messages first
- Use online regex testers like regex101.com
fail_on_empty: trueis set and no matches found (intended behavior)- Invalid regex pattern in
extract_command - Git repository not available
- Insufficient permissions
- name: Debug Commit Messages
run: git log -${{ inputs.commit_limit }} --pretty=%B
- name: Test Extract Command
run: |
git log -10 --pretty=%B | grep -oE 'your-pattern' || echo "No matches"
# Or use built-in debug mode
- name: Extract with Debug Mode
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'your-pattern'"
debug: true # Shows detailed execution information- Increase timeout value (default is 30 seconds):
- uses: somaz94/commit-info-extractor@v1 with: commit_limit: 10 extract_command: "complex-command" timeout: 120 # Increase to 2 minutes
- Reduce
commit_limitto process fewer commits - Simplify your
extract_commandpattern
When multiple values are extracted, you can process them in subsequent steps:
- name: Extract JIRA Tickets
id: extract
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'JIRA-[0-9]+'"
key_variable: 'JIRA_TICKETS'
- name: Process Each Ticket
run: |
while IFS= read -r ticket; do
echo "Processing: $ticket"
# Your processing logic here
done <<< "${{ steps.extract.outputs.value_variable }}"- name: Extract as JSON
id: extract_json
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 10
extract_command: "grep -oE 'JIRA-[0-9]+'"
output_format: 'json'
- name: Process JSON Array
run: |
echo '${{ steps.extract_json.outputs.value_variable }}' | \
jq -r '.[]' | while read -r ticket; do
echo "Processing: $ticket"
done- name: Extract Deployment Info
id: deploy
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 5
extract_command: "grep -oE 'env:(\\w+)'"
key_variable: 'ENVIRONMENT'
- name: Notify Slack
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "Deploying to: ${{ steps.deploy.outputs.value_variable }}"
}- name: Check for Production Tag
id: check_env
uses: somaz94/commit-info-extractor@v1
with:
commit_limit: 1
extract_command: "grep -oE 'env:production'"
fail_on_empty: false
- name: Deploy to Production
if: steps.check_env.outputs.value_variable == 'env:production'
run: |
echo "Deploying to production..."When using this action, keep the following in mind:
- The
extract_commandexecutes shell commands - Never use untrusted user input in extraction commands
- Always validate and sanitize inputs
- Be careful not to extract secrets or credentials from commit messages
- Use GitHub's secret scanning alongside this action
- Consider filtering sensitive patterns
- This action only requires read access to repository content
- Follow the principle of least privilege in your workflows
Test the Python script locally without Docker:
# Clone the repository
git clone https://github.com/somaz94/commit-info-extractor.git
cd commit-info-extractor
# Run tests
python3 tests/test_local.py
# Or test manually
export INPUT_COMMIT_LIMIT=10
export INPUT_EXTRACT_COMMAND="grep -oE 'feat|fix|chore'"
export INPUT_PRETTY=true
export INPUT_DEBUG=true # Enable debug mode
export INPUT_TIMEOUT=60 # Set timeout
python3 entrypoint.pySee tests/TESTING.md for more details.
See CHANGELOG.md for version history and updates.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to:
- Report bugs
- Suggest new features
- Submit pull requests
- Improve documentation
If you find this action helpful, please consider:
- Starring the repository
- Sharing with others
- Contributing improvements
- actions/checkout - Checkout your repository
- github-script - Write workflows using JavaScript
- setup-python - Set up Python environment
Made by somaz94