需要在 github 操作工作流程中将反斜杠转换为正斜杠
Need to convert back slashes to forward slashes in github action work flow
在我的 actions yml 文件中,我为我的 ctest 输入图像文件设置了一个指向根目录的环境变量(我 运行 ctest 测试图像编解码器解压缩器,这些是输入图像)。
env:
DATA_ROOT: ${{github.workspace}}/data
在 windows 上,这给了我类似 c:\Foo\Bar/data
的东西,我想将其转换为
c:/Foo/Bar/data
我可以在 PowerShell 中进行转换:
$temp = ${DATA_ROOT}
$pattern = '[\]'
$temp = $temp -replace $pattern, '/'
但是我该如何将 ${DATA_ROOT}
重置为等于 $temp
?
我希望后续步骤使用新的 ${DATA_ROOT} 。
我不确定为什么这被标记为 CMake,但您可以在 GitHub 操作中设置环境变量,方法是将包含 NAME=VALUE
的行写入 $GITHUB_ENV
.
来自 GitHub 操作 documentation:
echo "{name}={value}" >> $GITHUB_ENV
Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.
Example
steps:
- name: Set the value
id: step_one
run: |
echo "action_state=yellow" >> $GITHUB_ENV
- name: Use the value
id: step_two
run: |
echo "${{ env.action_state }}" # This will output 'yellow'
Multiline strings
For multiline strings, you may use a delimiter with the following syntax.
{name}<<{delimiter}
{value}
{delimiter}
对于 CMake 解决方案,如果您的路径可能包含混合斜杠,则可以使用 file(TO_CMAKE_PATH)
file(TO_CMAKE_PATH "c:\Foo\Bar/data" path)
message(STATUS "path = ${path}") # prints: path = c:/Foo/Bar/data
请注意,此函数假定传入路径是 本机 CMake 所在平台的路径 运行。因此在 Linux 上,带有驱动器号的输入将无效(:
将被解释为 PATH
分隔符并转换为 ;
)
请注意,${{github.workspace}}
在 windows 上使用 \
路径分隔符现在正在伤害我,使用 bash 破坏任何“运行”操作shell。所以这行不通;
defaults:
run:
shell: bash
jobs:
build:
steps:
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build
一种解决方法是在 '${{github.workspace}}/build'
周围加上单引号,以防止 bash 将 \
路径分隔符视为转义。
在我的 actions yml 文件中,我为我的 ctest 输入图像文件设置了一个指向根目录的环境变量(我 运行 ctest 测试图像编解码器解压缩器,这些是输入图像)。
env:
DATA_ROOT: ${{github.workspace}}/data
在 windows 上,这给了我类似 c:\Foo\Bar/data
的东西,我想将其转换为
c:/Foo/Bar/data
我可以在 PowerShell 中进行转换:
$temp = ${DATA_ROOT}
$pattern = '[\]'
$temp = $temp -replace $pattern, '/'
但是我该如何将 ${DATA_ROOT}
重置为等于 $temp
?
我希望后续步骤使用新的 ${DATA_ROOT} 。
我不确定为什么这被标记为 CMake,但您可以在 GitHub 操作中设置环境变量,方法是将包含 NAME=VALUE
的行写入 $GITHUB_ENV
.
来自 GitHub 操作 documentation:
echo "{name}={value}" >> $GITHUB_ENV
Creates or updates an environment variable for any actions running next in a job. The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.
Example
steps: - name: Set the value id: step_one run: | echo "action_state=yellow" >> $GITHUB_ENV - name: Use the value id: step_two run: | echo "${{ env.action_state }}" # This will output 'yellow'
Multiline strings
For multiline strings, you may use a delimiter with the following syntax.
{name}<<{delimiter} {value} {delimiter}
对于 CMake 解决方案,如果您的路径可能包含混合斜杠,则可以使用 file(TO_CMAKE_PATH)
file(TO_CMAKE_PATH "c:\Foo\Bar/data" path)
message(STATUS "path = ${path}") # prints: path = c:/Foo/Bar/data
请注意,此函数假定传入路径是 本机 CMake 所在平台的路径 运行。因此在 Linux 上,带有驱动器号的输入将无效(:
将被解释为 PATH
分隔符并转换为 ;
)
请注意,${{github.workspace}}
在 windows 上使用 \
路径分隔符现在正在伤害我,使用 bash 破坏任何“运行”操作shell。所以这行不通;
defaults:
run:
shell: bash
jobs:
build:
steps:
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build
一种解决方法是在 '${{github.workspace}}/build'
周围加上单引号,以防止 bash 将 \
路径分隔符视为转义。