I have a job in Github Actions that uses a matrix. I want to run some of the job steps on a custom shell that depends on a matrix variable.
Specifically, the image has a foreign chroot so I can emulate any hardware architecture and run native binaries for it. The custom shell is just a wrapper script around bash which runs the commands in the chroot and with the emulator for the desired target architecture.
The matrix looks about like this:
cross_build:
strategy:
matrix:
job:
- { release: bullseye , arch: armhf , ocaml-version: 4.14.0 , publish: true }
I have tried
shell: bash-${{ matrix.job.arch }} {0}
(bash-$ARCH being the wrapper script), but get an error:
The workflow is not valid. .github/workflows/CI.yml (Line: mmm, Col: nn): Unrecognized named-value: 'matrix'.
If I hardcode the architecture in the shell, everything works:
shell: bash-armhf {0}
So the issue really is about resolving variables in the shell element.
Is there a way to pass a variable in this place so that different instances of the job run on different custom shells?
If not, I would need to have one bash-wrapper script and somehow pass it the information about the target platform I would like to use. A command line argument is presumably not an option if I can’t pass variables in shell – so what is the standard way of passing that information to the custom shell?
As pointed out by Azeem, variables in shell are currently not supported.
This works:
In the workflow definition, add the following to the job:
env:
CROSS_ARCH: ${{ matrix.job.arch }}
Then, for the custom shell, specify the path to the wrapper script – one single script regardless of target architecture, thus no use of variable in shell.
In the wrapper script, evaluate CROSS_ARCH and choose the emulator and chroot based on that.
Since I already had multiple copies of a single script, which would determine the architecture by the name with which it was invoked, this was very easy to implement and is even cleaner than converting /bin/bash-ARCH into ARCH by stripping the beginning.
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