Skip to content

feat: describe matrix variables of type array of objects #31251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 14, 2024
Merged

feat: describe matrix variables of type array of objects #31251

merged 6 commits into from
Mar 14, 2024

Conversation

deemp
Copy link
Contributor

@deemp deemp commented Jan 24, 2024

Why:

Partially closes: #26469

I used this hidden knowledge in freckle/stack-action#35 and decided to document it.

What's being changed (if available, include any code snippets, screenshots, or gifs):

Check off the following:

  • I have reviewed my changes in staging, available via the View deployment link in this PR's timeline (this link will be available after opening the PR).

    • For content changes, you will also see an automatically generated comment with links directly to pages you've modified. The comment won't appear if your PR only edits files in the data directory.
  • For content changes, I have completed the self-review checklist.

Copy link

welcome bot commented Jan 24, 2024

Thanks for opening this pull request! A GitHub docs team member should be by to give feedback soon. In the meantime, please check out the contributing guidelines.

@github-actions github-actions bot added the triage Do not begin working on this issue until triaged by the team label Jan 24, 2024
@nguyenalex836 nguyenalex836 added content This issue or pull request belongs to the Docs Content team actions This issue or pull request should be reviewed by the docs actions team waiting for review Issue/PR is waiting for a writer's review and removed triage Do not begin working on this issue until triaged by the team labels Jan 24, 2024
@nguyenalex836
Copy link
Contributor

@deemp Thanks so much for opening a PR! I'll get this triaged for review ✨

Comment on lines 40 to 42
- matrix.os: ubuntu-latest
matrix.node.version: 14
matrix.node.env: ''
Copy link
Contributor

@ferdnyc ferdnyc Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't technically correct — matrix.node.env is simply not set for contexts where it's not included as part of the matrix. It's not part of the matrix.node object at all. All contexts are not created with the same structure, when matrix expansion is performed on homogeneous objects. Instead, each expanded context has whatever structure is explicitly defined by its set of inputs.

GitHub's workflow syntax expands ${{ foo }} to the empty string, for any undefined foo, but that doesn't mean that object actually exists.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is something that actually requires some care, because for example this workflow:

jobs:
  build:
    runs-on: ${{ matrix.os.host }}
    strategy:
      matrix:
        os:
          - host: macos-latest
          - host: windows-latest
            shell: 'msys2 {0}'
          - host: ubuntu-latest
        compiler:
          - gcc
          - clang
    defaults:
      run:
        shell: ${{ matrix.os.shell }}

...will fail on Ubuntu and macOS, when it tries to set the run.shell default value to nothing.

Error: The template is not valid. foo.yml (Line: Y, Col: X): Unexpected value ''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be fixed with a fallback, e.g.:

defaults:
  run:
    shell: ${{ matrix.os.shell || 'bash' }}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitHub's workflow syntax expands ${{ foo }} to the empty string, for any undefined foo, but that doesn't mean that object actually exists.

Where is this documented?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see (link)

If you attempt to dereference a nonexistent property, it will evaluate to an empty string.

Co-authored-by: Frank Dana <ferdnyc@gmail.com>
@deemp deemp requested a review from ferdnyc February 3, 2024 13:44
Copy link
Contributor

@jc-clark jc-clark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making this update @deemp!

I added a couple suggestions below and would love to hear what you think.

There are some versions of GitHub Enterprise Server that do not support Node 20. To adjust for this, we use feature-based versioning. The actions-node20-support feature-based versioning file to make sure that only the right versions of our documentation show information about Node 20.

My question for you is would Node 16 be a suitable replacement in this case?

Thanks!

@nguyenalex836
Copy link
Contributor

Hi @deemp 👋 ! Please let us know your thoughts regarding @jc-clark's last response 💛

@nguyenalex836 nguyenalex836 added more-information-needed More information is needed to complete review and removed waiting for review Issue/PR is waiting for a writer's review labels Mar 12, 2024
deemp and others added 3 commits March 13, 2024 00:50
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
Co-authored-by: Joe Clark <31087804+jc-clark@users.noreply.github.com>
@deemp
Copy link
Contributor Author

deemp commented Mar 12, 2024

@jc-clark, @nguyenalex836, thanks for a review. I believe these node versions are OK.

The point of this example was to demonstrate how a matrix unwraps into multiple job configurations. If you think an example without specific node versions is more maintainable, feel free to use something instead of node.

@jc-clark jc-clark enabled auto-merge March 14, 2024 16:59
@jc-clark jc-clark added this pull request to the merge queue Mar 14, 2024
Merged via the queue into github:main with commit eb02005 Mar 14, 2024
Copy link
Contributor

Thanks very much for contributing! Your pull request has been merged 🎉 You should see your changes appear on the site in approximately 24 hours. If you're looking for your next contribution, check out our help wanted issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actions This issue or pull request should be reviewed by the docs actions team content This issue or pull request belongs to the Docs Content team more-information-needed More information is needed to complete review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

What is a valid matrix value?
4 participants