英文:
Github actions sed -i "s/" not escaping properly "//" in url
问题
我遇到了这样一个愚蠢的问题,我无法解决。我正在使用 GitHub 操作,想要替换一些 URL。
我的 sed 看起来像这样:
sed -i "s/${{ inputs.original-variable }} 对于 inputs.original-variable,我想使用这样的 URL:'wss://mm-websocket.mydomain.com' 但每次运行时它没有正确转义,我得到这个错误 sed: -e expression #1, char 11: unknown option to s' "s/wss://mm-websocket.mydomain.com
我试图使用 const,并替换整个常量为一个字符串,但对我来说仍然无法工作。
此外,我如何在本地运行我的 CI 作业,gh run file.yml 能行吗?
编辑:
在 sed 之前,我有 'wss://mm-websocket.mydomains.com/'
经过 sed 后,我想要得到 wss://mm-websocket.mydomain.com
.yml 文件中的实际步骤
original-variable: wss://mm-websocket.mydomains.com/
destination-variable: wss://mm-websocket.mydomain.com/
file-path: 'apps/app/src/environments/environment.prod.ts'
实际替换步骤
run: |
  destinationVariable=${{ inputs.destination-variable }}
  parsedDestinationVariable="${destinationVariable//\//\\/}"
  sed -i "s/${{ inputs.original-variable }}/$parsedDestinationVariable/" "${{ inputs.file-path }}"
英文:
I have such silly issue that I can't get working. I am using GitHub actions and I want to replace some ulr.
My sed looks like this:
 sed -i "s/${{ inputs.original-variable }} for inputs.original-variable i want to use such url: 'wss://mm-websocket.mydomain.com' but every time this is running it is not properly escaping and i do get this error sed: -e expression #1, char 11: unknown option to s' "s/wss://mm-websocket.mydomain.com
I was trying to use const and replace whole const with a string not string itslef, but still did not work for me
Also how i can run my ci job localy will gh run file.yml work?
Edit:
Before sed I have 'wss://mm-websocket.mydomains.com/'
After sed I want to have wss://mm-websocket.mydomain.com
Actual step in .yml file
original-variable: wss://mm-websocket.mydomains.com/
destination-variable: wss://mm-websocket.mydomain.com/
file-path: 'apps/app/src/environments/environment.prod.ts'
actual replace step
run: |
  destinationVariable=${{ inputs.destination-variable }}
  parsedDestinationVariable="${destinationVariable//\//\\/}"
  sed -i "s/${{ inputs.original-variable }}/$parsedDestinationVariable/" "${{ inputs.file-path }}"
答案1
得分: 2
使用 sed 处理 URL 时,使用斜杠 / 可能会引起问题,尝试使用不同的分隔符,如 @
sed -i "s@${{ inputs.original-variable }}@$parsedDestinationVariable@" "${{ inputs.file-path }}"
英文:
When using sed for URLs, using forward slashes / could cause problems, try using a different deliminator like @
sed -i "s@${{ inputs.original-variable }}@$parsedDestinationVariable@" "${{ inputs.file-path }}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论