How to escape a placeholder-looking variable in a string?

54 views Asked by At

In Python I have the following code:

# Create or overwrite the .github/workflows/build.yml file
with open(os.path.join(workflows_dir, 'build.yml'), 'w', encoding='utf-8') as file:
    file.write(f"""\
... some YAML goes here. ...      
          client_id: ${{ secrets.CLIENT_ID }}
          client_secret: ${{ secrets.CLIENT_SECRET }}
""")

Python replaces:

client_id: ${{ secrets.CLIENT_ID }}
client_secret: ${{ secrets.CLIENT_SECRET }}

With:

client_id: ${ secrets.CLIENT_ID }
client_secret: ${ secrets.CLIENT_SECRET }

The code is meant to replace some placeholders with variables and that's fine. In this case there is no such variable and this bit is actually not meant to be replaced because it's part of a Github workflow and Github will pass in these secrets.

I have also tried escaping like this:

client_id: ${{{ secrets.CLIENT_ID }}}
client_secret: ${{{ secrets.CLIENT_SECRET }}}

What is the correct way to do this?

0

There are 0 answers