Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace string in expression with GitHub actions

This is my action that returns $TOXENV that looks like this py3.6-django2.2 I'd like to $TOXENV to look like this instead py36-django22 is there any substitute/replace function that I could use to replace . char?

name: CI
on:
  workflow_dispatch:
    branches: [ master, actions ]
jobs:
  demo:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python: [3.6, 3.7, 3.8, 3.9]
        django: ['2.2', '3.0']
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v1
        name: Set up Python ${{ matrix.python }} ${{ matrix.django }}
        with:
          python-version: ${{ matrix.python }}
      - name: python version
        env:
            TOXENV: "py${{ matrix.python }}-django${{ matrix.django }}"
        run:
          echo $TOXENV
like image 866
Lukasz Dynowski Avatar asked Dec 04 '25 15:12

Lukasz Dynowski


1 Answers

Another way by using BASH native variable substitution:

  - name: python version
    env:
        TOXENV: "py${{ matrix.python }}-django${{ matrix.django }}"
    run: |
      TOXENV=${{ env.TOXENV }}
      TOXENV=${TOXENV//.} # replace all dots
      echo TOXENV=${TOXENV} >> $GITHUB_ENV # update GitHub ENV vars
  - name: print env
    run: echo ${{ env.TOXENV }}

The idea is to read the GitHub actions expression variable into a BASH variable and do the string manipulation then export or set-output to update in GitHub actions runtime.

like image 70
Seff Avatar answered Dec 07 '25 04:12

Seff