Search code examples
linuxsedgithub-actions

Github Action - How to keep the quotes in the sed command replacement?


I have a github action that run this job:

update_version_numbers:
  needs: [build_release_notes, build_artifacts]
  runs-on: ubuntu-latest
  name: Update Version Numbers

  steps:
    - uses: actions/checkout@v3
    
    # Find and replace version
    - name: Increment Version Numbers
      run: sed -i 's/version=".\+",/version="${{ inputs.milestone }}",/' setup.py
    
    - name: Display setup.py
      run: cat setup.py

    - name: Push Changes
      run: |
        git config --local user.email "github-actions[bot]@users.noreply.github.com"
        git config --local user.name "github-actions[bot]"
        git add setup.py
        git commit -m "Bump Ikabot version ${{ inputs.milestone }}"
        git push

The job consists of replacing the version value of a file named setup.py.

Here is a sample of my setup.py file:

import setuptools

setuptools.setup(
    name="ikabot",
    version="6.0.6",
    license='MIT'
)

This file contains a line version="6.0.6",. And I would like to change the value 6.0.6 to my new version received as a parameter.

When I run the action, the value of my file is changed but the quotes are removed: version=6.0.7,

In console this command displayed as

sed -i 's/version=".\+",/version="6.0.6",/' setup.py

I tried using an online sed editor and I don't see any issue with my regex.

How can I ensure that the command does not delete the quotes?


Solution

  • Have you tried to add an escape sequence to your sed? Try it like this and check the output :

    run: sed -i 's/version=".\+",/version="\"${{ inputs.milestone }}\"",/' setup.py