Home > Mobile >  How to remove special characters from a branch name on github actions
How to remove special characters from a branch name on github actions

Time:03-15

My Branch name IS AKA-2120

i using this as a job to get the branch name.

  extract_branch_name:
    runs-on: ubuntu-latest
    steps:
      - name: Extract branch name
        shell: bash
        run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
        id: extract_branch
    outputs:
      branch: ${{ steps.extract_branch.outputs.branch }}

but what i actually need to my output is aka2120

theres a way to remove special characters and lower the branch name?

CodePudding user response:

There are several ways to solve your problem. One way is to use existing actions in Marketplace:

- uses: mad9000/actions-find-and-replace-string@2
  id: findandreplace
  with:
    source: ${{ github.ref }}
    find: '-'        
    replace: ''
- uses: ASzc/change-string-case-action@v2
  id: lowercase
  with:
     string: ${{ steps.findandreplace.outputs.value }}
- name: Get the above output
  run: echo "The replaced value is ${{ steps.lowercase.outputs.lowercase }}"

If you want just bash formula, that will work:

echo ${GITHUB_REF#refs/heads/} | tr "[:upper:]" "[:lower:]" | sed -e 's/-//g'
  • Related