3

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?

5
  • Like this? Commented Feb 26, 2023 at 15:12
  • I’ve updated the question to show the matrix. Each row of the matrix has a particular combination of arch, OCaml version and possibly other parameters, so we’d still need to resolve that somehow. As for your example – is that meant as a syntactically correct example? Commented Feb 26, 2023 at 15:37
  • btw, according to actionlint playground, my matrix and usage of matrix variables in shell passes verification. Github rejects it nonetheless. Commented Feb 26, 2023 at 15:40
  • Oh, right. Then, it's better if you added a minimal workflow example in your example. That would be easier to test. Commented Feb 26, 2023 at 15:42
  • 1
    Looks like it's an open issue (github.com/actions/runner/issues/444) and shell doesn't take custom arguments at the moment. Commented Feb 26, 2023 at 16:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.