I created a GitHub Actions Job with a strategy matrix that creates a set of environment variables.
One of them is machine_architecture
which is either 32 or 64.
In most steps I can use it directly i.e. via ${{ machine_architecture }}
.
But some steps requires strings like 'i386' vs 'x86_64'. Is there an easy way in github actions to create a map-object that I can use in expressions like:
map_object = { 32: "i386", 64: 'x86_64' }
...
${{ map_object[machine_architecture] }}
If not, what is the idiomatic way in github actions to solve that problem?
PS: I am aware, that I can set environment variables in steps, but the problem is, that these variables are only available for the following steps (i.e. not for usage in "run-on:" tag)
To set a custom environment variable, you must define it in the workflow file. The scope of a custom environment variable is limited to the element in which it is defined. You can define environment variables that are scoped for: The entire workflow, by using env at the top level of the workflow file.
You should use run: echo "$GITHUB. REPOSITORY" and run: echo "$GITHUB. REPOSITORY_OWNER" to see them directly on your workflow.
In the meantime I found a solution:
Although GitHub Actions has no syntax for directly creating a Mappings/Objects it can be done indirectly with fromJson():
${{ fromJson('{ 32: "i386", 64: "x86_64" }')[machine_architecture] }}
this fromJson() will create a mapping from int to string. the following []-operator resolves the int type "machine_architecture" to a string type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With