github-script icon indicating copy to clipboard operation
github-script copied to clipboard

Expose `strategy` and `matrix` variables in `context`

Open tony-pizza opened this issue 9 months ago • 0 comments

Is your feature request related to a problem? Please describe.

I'm using a matrix and I want to access matrix- and strategy-related variables in my github-script. The two ways to do that are:

  1. Setting env vars:
# ...
strategy:
  matrix:
    group: [1, 2]
steps:
  - uses: actions/github-script@v7
    env:
      MATRIX_GROUP: ${{ matrix.group }}
      MATRIX_NUM_GROUPS: ${{ strategy.job-total }}
    with:
      script: |
        const group = parseInt(process.env.MATRIX_GROUP)
        const numGroups = parseInt(process.env.MATRIX_NUM_GROUPS)
  1. Interpolation:
# ...
strategy:
  matrix:
    group: [1, 2]
steps:
  - uses: actions/github-script@v7
    with:
      script: |
        const group = ${{ matrix.group }}
        const numGroups = ${{ strategy.job-total }}

Describe the solution you'd like It would be nice if these were offered somewhere in the context object, which seems like an intuitive home for them. Something like...

# ...
strategy:
  matrix:
    group: [1, 2]
steps:
  - uses: actions/github-script@v7
    with:
      script: |
        const group = parseInt(context.strategy.matrix.group)
        const numGroups = context.strategy.totalJobs

tony-pizza avatar Jun 03 '25 17:06 tony-pizza