Search code examples
github-actions

GITHUB ACTION string chars from string


I have set an env variable called BRANCH and in there I have "release/v4.1.2". I'm on ubuntu and I want to update that env variable to just be left with "v4.1.2". I am totally stuck. Nothing I try works.

something like this?

run:|
BRANCH="${BRANCH//[^0-9]/}"

Solution

  • You could use the Bash Shell Parameter Expansion feature, like:

    >echo "${BRANCH#"release/"}"
    v4.1.2
    

    so you can combine it in your action like:

    run:|
    release="${BRANCH#"release/"}"
    echo "BRANCH=${release}" >> $GITHUB_ENV
    
    

    By setting an env variable, like described here