Skip to content

onliner/sanitize-branch-name

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🌿 Sanitize Branch Name

A lightweight GitHub Action that determines the current branch name
and generates a sanitized version safe for artifact names, cache keys, and file paths.

GitHub Actions Shell License


✨ Features

  • Detects the current branch name automatically
  • Supports both push and pull_request workflows
  • Replaces / and _ with -
  • Exposes both original and sanitized branch names as outputs
  • Lightweight and dependency-free

📦 Outputs

Output Description
branch_name Original branch name
sanitized_branch_name Branch name with / and _ replaced by -

🚀 Usage

- name: Sanitize branch name
  id: branch
  uses: onliner/sanitize-branch-name@v1

- name: Print outputs
  run: |
    echo "Original: ${{ steps.branch.outputs.branch_name }}"
    echo "Sanitized: ${{ steps.branch.outputs.sanitized_branch_name }}"

🧪 Example

Branch name Sanitized branch name
feature/login-ui feature-login-ui
hotfix_bug_123 hotfix-bug-123
release/v1_2_0 release-v1-2-0

💡 Use Cases

  • Artifact naming (upload-artifact)
  • Cache keys (actions/cache)
  • Docker tags
  • File paths
  • Any CI workflow where branch names must be filesystem-safe

📜 License

Released under the MIT License.

About

Determine the current branch name and generate a sanitized version safe for artifacts, cache keys, and file paths.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors