I am trying to understand the logic behind the following line from the GitHub docs:
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }}
GitHub's explanation of what this line does makes sense: if the repository running the workflow is named 'github/docs-internal' then a self-hosted runner is used. If the github repo is any other name then the workflow will use a managed ubuntu runner.
I am looking for an explanation as to why the fromJSON function is being used, and why the second value (self-hosted) is used if the condition is true and why the first value (ubuntu-latest) is used if the condition is false.
Suppose I wanted to add an additional condition to use a windows runner if the repository name was 'github/docs-external.' Would the new line look something like this:
runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted", "windows-latest"]')[github.repository == 'github/docs-internal'][github.repository == 'github/docs-external'] }}