rhysd / actionlint

:octocat: Static checker for GitHub Actions workflow files
https://rhysd.github.io/actionlint/
MIT License
2.69k stars 152 forks source link

False Positive On Aliases In Mapping Nodes #133

Open Kurt-von-Laven opened 2 years ago

Kurt-von-Laven commented 2 years ago

Actionlint complains "with" section is alias node but mapping node is expected [syntax-check] on valid YAML syntax when anchors and aliases are used with mapping nodes:

- name: Run my-action.
  run: my-organization/my-action
  with: &my-action-inputs
    a: b
    c: d
    e: f
- name: Run my-action again.
  run: my-organization/my-action
  with: *my-action-inputs

I am uncertain how one would suppress the error.

rhysd commented 2 years ago

Yeah, aliases are actually not considered because I've never used them in my workflows and anyone didn't report that previously. But I agree this should not cause false positive at least.

rhysd commented 2 years ago

I created a minimal workflow to reproduce this:

name: Test
on: push

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - name: Run my-action.
        uses: my-organization/my-action@main
        with: &my-action-inputs
          a: b
          c: d
          e: f
      - name: Run my-action again.
        uses: my-organization/my-action@main
        with: *my-action-inputs
prein commented 1 year ago

Consider also yaml anchors (if you didn't already) Example:

name:  Test
on: push
jobs:
  test1:
    runs-on: ubuntu-latest
    steps:
    - &run_action
      name: Run my-action
      uses: my-organization/my-action@main
  test2:
    runs-on: ubuntu-latest
    steps:
    - name: Restore built artifacts from cache
      <<: *run_action
dannystaple commented 1 year ago

I see a false positive on most aliases. This manifests as:

.github/workflows/terraform_apply_promote.yml:27:26: expected scalar node for string value but found alias node with "" tag [syntax-check]
   |
27 |       terraform_version: *tf_ver

As it stands, if being used in superlinter, we cannot even use the command line to override this, since the exclusions aren't available in actionlint.yml. At this point we are left with:

All of which are sub-optimal. it suggests that the way this is linting is some AST that is running before aliases are resolved.

Kurt-von-Laven commented 1 year ago

This doesn't solve your problem, but to toot my own horn, MegaLinter runs significantly faster than Super-Linter, and has many more linters. It also has actionlint.