Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GITHUB ACTIONS replace character in string

I'm trying to replace a character in a variable within a GITHUB actions step

  - name: Set Up DB Name
    run: |
      DB_NAME="${GITHUB_REF_SLUG/-/_}"
      echo $DB_NAME

I'm getting a bad request error

What am I doing wrong?

like image 686
Blue Moon Avatar asked Nov 29 '25 22:11

Blue Moon


1 Answers

I successfully made the character replace works (with GITHUB_REPOSITORY) using this implementation:

job1:
  runs-on: ubuntu-latest
  steps:
    - name: character-replacement-test
      run: |
        REPO=$GITHUB_REPOSITORY
        DB_NAME="${REPO//-/_}"
        echo $DB_NAME

I couldn't get to the same result with 2 lines. (But someone more experienced with bash might help us get there as well).

Evidence:

evidence

So in your case, it should work using this code if you substitute the GITHUB_REPOSITORY by GITHUB_REF_SLUG in your workflow.

I used this post as reference.

like image 182
GuiFalourd Avatar answered Dec 01 '25 19:12

GuiFalourd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!