Skip to content
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

False positive error for array of labels in matrix for self-hosted runners #164

Closed
AndreyNautilus opened this issue Jun 29, 2022 · 1 comment

Comments

@AndreyNautilus
Copy link

I'm using actionlint at my work to lint workflows and I encountered an error report which seems to be false-positive.
I have the following (very simplified) workflow:

on:
  push:
  workflow_dispatch:

jobs:
  build:
    strategy:
      matrix:
        include:
          - msg: hello macos
            host-labels: ["self-hosted", "macOS", "X64"]
          - msg: hello linux
            host-labels: ["self-hosted", "linux"]
    runs-on: ${{ matrix.host-labels }}
    steps:
      - run: echo "${{ matrix.msg }}"

which works fine on Github Actions, but actionlint reports an error for line runs-on: ${{ matrix.host-labels }} (see the online checker):

object, array, and null values should not be evaluated in template with ${{ }} but evaluating the value of type array

The workflow should run the job on 2 different self-hosted runners for which we defined our own labels. According to Github documentation runs-on supports either a string or a list of string:

Use jobs.<job_id>.runs-on to define the type of machine to run the job on. The machine can be either a GitHub-hosted runner or a self-hosted runner. You can provide runs-on as a single string or as an array of strings. If you specify an array of strings, your workflow will run on a self-hosted runner whose labels match all of the specified runs-on values, if available.

So, it seems that evaluating an array of string via ${{ }} should be allowed in this context.

How can I fix/workaround/disable this error for my workflows?

@AndreyNautilus
Copy link
Author

I found a workaround: first transform matrix.host-labels to JSON and then from JSON:

runs-on: ${{ fromJSON(toJSON(matrix.host-labels)) }}

This works and doesn't trigger lint errors.
However, it's not really convenient to apply such workaround in every workflow that uses self-hosted runners.

@rhysd rhysd closed this as completed in b19e12a Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant