Skip to content

Expose strategy and matrix variables in context #615

Open
@tony-pizza

Description

@tony-pizza

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions