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

actionlint detect warning when using inputs type conversion with fromJSON #181

Closed
guitarrapc opened this issue Jul 20, 2022 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@guitarrapc
Copy link

Summary

actionlint warn when trying to use JSON data type conversion pattern and it's too strict, or other word too smart then what agent do.

Warning message

$ actionlint

.github\workflows\actionlint_issue.yaml:15:30: 1st argument of function call is not assignable. "bool" cannot be assigned to "string". called function type is "fromJSON(string) -> any" [expression]
   |
15 |       is-valid: ${{ fromJson(github.event.inputs.is-valid) }}

Detail

When reusable workflow have inputs type boolean and want pass boolean from workflow_dispatch, JSON data type convert with fromJSON expression is officially introduced pattern.

see: https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-data-type

Without fromJSON, github.event.inputs.foo treat as string and cannot pass to workflow_call.
However actionlint warn this and seems guessing parameter as boolean is too smart then what agent do.

Reproduce code

  1. Prepare 2 workflows actionlint.yaml and _reusable.yaml
name: actionlint issue

on:
  workflow_dispatch:
    inputs:
      is-valid:
        required: true
        description: "is-valid: true or false"
        type: boolean

jobs:
  issue:
    uses: ./.github/workflows/_reusable.yaml
    with:
      is-valid: ${{ fromJson(github.event.inputs.is-valid) }}
name: _reusable

on:
  workflow_call:
    inputs:
      is-valid:
        required: true
        description: username to show
        type: boolean

jobs:
  reusable_workflow_job:
    runs-on: ubuntu-latest
    steps:
      - name: called is-valid
        run: echo "called is-valid. ${{ inputs.is-valid }}"
  1. run actionlint.

Workaround

Pass string to fromJSON not boolean, via format('{0}', github.event.inputs.foo).

name: actionlint issue

<reducted>

jobs:
  issue:
    uses: ./.github/workflows/_reusable.yaml
    with:
      is-valid: ${{ fromJson(format('{0}', github.event.inputs.is-valid)) }}
@rhysd rhysd added the bug Something isn't working label Aug 17, 2022
@rhysd
Copy link
Owner

rhysd commented Aug 17, 2022

Thank you for the detailed report with reproduction. This looks a bug of actionlint.

@rhysd
Copy link
Owner

rhysd commented Aug 17, 2022

Type of the input is specified as boolean at on.workflow_dispatch.inputs.<name>.type but it is only used for validation. Type of inputs.<name> is always string. But actionlint statically types inputs.<name> is boolean looking at the specification.

I'm not sure this is an expected behavior because the official document says:

inputs.<name> | string or number or boolean | Each input value passed from an external workflow.

https://docs.github.com/en/actions/learn-github-actions/contexts#inputs-context

From this document, correct type of the inputs.is-valid sounds boolean.

@rhysd
Copy link
Owner

rhysd commented Aug 17, 2022

I made a question at https://github.com/orgs/community/discussions/29796

@rhysd
Copy link
Owner

rhysd commented Aug 17, 2022

@guitarrapc By the way, inputs context instead of github.event.inputs solves this issue. It is typed correctly as boolean. If you still have this issue, please try the following:

is-valid: ${{ inputs.is-valid }}

@rhysd rhysd closed this as completed in 511e12a Aug 17, 2022
@johnfoconnor
Copy link

johnfoconnor commented Sep 29, 2022

Im running into this issue with the following code

Error: .github/workflows/populate_caches.yaml:38:16: input "timeout" is typed as number by reusable workflow "./.github/workflows/unity-tests.yaml". string value cannot be assigned [expression]

    strategy:
      matrix:
        timeout:
          # hack to allow a configurable number timeout as input. see
          # https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-data-type
          - ${{ fromJSON(inputs.timeout || '40') }}
    with:
      timeout: ${{ matrix.timeout }}

If a fix is not possible, I would appreciate a way to annotate the code to ignore the linter for this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants