Issue
In my actions yml file, I set an environment variable pointing to the root directory for my ctest input image files (I run ctest to test an image codec decompressor, and these are the input images).
env:
DATA_ROOT: ${{github.workspace}}/data
On windows, this is gives me something like c:\Foo\Bar/data
, and I would like to convert it to
c:/Foo/Bar/data
I can do the conversion in PowerShell:
$temp = ${DATA_ROOT}
$pattern = '[\\]'
$temp = $temp -replace $pattern, '/'
but how do I then reset ${DATA_ROOT}
to equal $temp
?
I want subsequent steps to use the new ${DATA_ROOT} .
Solution
I'm not sure why this is tagged CMake, but you can set environment variables in GitHub Actions by writing a line containing NAME=VALUE
to $GITHUB_ENV
.
From the GitHub Actions 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}
For a CMake solution, if you have a path with potentially mixed slashes, you can use file(TO_CMAKE_PATH)
file(TO_CMAKE_PATH "c:\\Foo\\Bar/data" path)
message(STATUS "path = ${path}") # prints: path = c:/Foo/Bar/data
Note that this function assumes the incoming path is a native path for the platform on which CMake is running. So on Linux, an input with a drive letter would be invalid (the :
would be interpreted as a PATH
separator and converted to a ;
)
Answered By - Alex Reinking Answer Checked By - David Marino (WPSolving Volunteer)