需要在github操作工作流程中将反斜杠转换为正斜杠

Jac*_*cko 4 windows powershell path cmake github-actions

在我的 actions yml 文件中,我设置了一个环境变量,指向我的 ctest 输入图像文件的根目录(我运行 ctest 来测试图像编解码器解压缩器,这些是输入图像)。

env:
  DATA_ROOT: ${{github.workspace}}/data
Run Code Online (Sandbox Code Playgroud)

在 Windows 上,这给了我类似的东西c:\Foo\Bar/data,我想将其转换为 c:/Foo/Bar/data

我可以在 PowerShell 中进行转换:

$temp = ${DATA_ROOT}
$pattern = '[\\]'
$temp = $temp -replace $pattern, '/'
Run Code Online (Sandbox Code Playgroud)

但我该如何重置${DATA_ROOT}为 equal $temp

我希望后续步骤使用新的 ${DATA_ROOT} 。

小智 7

请注意,现在在 Windows 上${{github.workspace}}使用\路径分隔符对我造成了伤害,破坏了使用 bash shell 的任何“运行”操作。所以这是行不通的;

defaults:
  run:
    shell: bash

jobs:
  build:
    steps:
    - name: Configure CMake
      run: cmake -B ${{github.workspace}}/build 
Run Code Online (Sandbox Code Playgroud)

解决方法是使用单引号'${{github.workspace}}/build',以防止 bash 将\路径分隔符视为转义符。