question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting strategy.matrix.value to expression throws invalid type error

See original GitHub issue

Getting “Invalid type found: array was expected but string was found” at matrix: value: ${{fromJson(needs.setup.outputs.matrix)}}

Any ${{}} expression fails. Only [] is allowed now, with at least one value. But the value cannot be an expression.

`name: Test Matrix

on: workflow_dispatch:

jobs:

setup: runs-on: ubuntu-latest outputs: matrix: ${{ steps.matrix.outputs.value }} steps: - id: matrix run: | echo ‘::set-output name=value::["a", "b", "c"]’ build: needs: [ setup ] runs-on: ubuntu-latest strategy: matrix: value: ${{fromJson(needs.setup.outputs.matrix)}} steps: - run: | echo “${{ matrix.value }}”`

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:31 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
javierlgacommented, Dec 20, 2022

This was driving me crazy, originally I was using cat and jq together to get the content into a string: cat releases.json | jq 'tostring' and then adding it to the GITHUB_OUTPUT:

echo "matrix=$(cat releases.json | jq 'tostring')" >> $GITHUB_OUTPUT

but when I ran the workflow I always got this error:

Unexpected type of value '[{"name":"XXX","ip_address":"XXX"},{"name":"XXX","ip_address":"XXX"}]', expected type: Sequence.

Note: I’ve been using the include property when defining the matrix.

Anyways, for some reason a pair of single quotes were added even removing with sed threw another error message:

Error parsing fromJson,.github/workflows/XXX.yaml (Line: 164, Col: 18): Invalid property identifier character: \. Path '[0]', line 1, position 2.,.github/workflows/XXX.yaml (Line: 164, Col: 18): Unexpected type of value '', expected type: Sequence.

The solution that I found was to use a multiline string, e.g.:

    steps:
      - name: Get JSON content
        id: get-json-content
        run: |
          echo 'JSON_CONTENT<<EOF' >> $GITHUB_OUTPUT
          cat releases.json >> $GITHUB_OUTPUT
          echo 'EOF' >> $GITHUB_OUTPUT
    outputs:
      new_content: ${{ steps.get-json-content.outputs.JSON_CONTENT }} 

Job using matrix:

  matrix_job_test:
    name: Matrix job test
    runs-on: ubuntu-latest
    needs: test_job
    strategy:
      matrix:
        include: ${{ fromJSON(needs.test_job.outputs.new_content) }}
    steps:
      - run: |
          echo $STACK_NAME
          echo $STACK_IP
        env:
          STACK_NAME: ${{ matrix.name }}
          STACK_IP: ${{ matrix.ip_address }}

In case someone wonder, this is the JSON content structure:

[
  {
  "name": "string",
  "ip_address": "string"
  },
  {
    "name": "string",
    "ip_address": "string"
  }
]

I hope this helps other people, cheers!

3reactions
gfridcommented, Jul 24, 2022

hi,

seems to be a bug and it did fail until I rewrote every line manually with all the correct indentations and spaces
also i found out that if you copy-paste it from somewhere it does not run seems to me that there are hidden chars while copypasting

i ignored the error ‘invalid type found: array was expected but string was found’ and continued it might a case of incorrect indentations and spaces , not sure, if so its a bug for sure.

still error should not appear while editing

my account.txt file is:

1111111 2222222

jobs:
  list-manifests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - id: set-matrix
        run: echo "::set-output name=matrix::$(cat accounts.txt | jq -R -s -c 'split("\n")[:-1]')"
    outputs:
       matrix: ${{ steps.set-matrix.outputs.matrix }}
  

  check:
    needs: [list-manifests]
    runs-on: ubuntu-latest
    strategy:
      matrix: 
        manifest: ${{ fromJson(needs.list-manifests.outputs.matrix) }}
    steps:
      - name: test
        run: |
          echo ${{ matrix.manifest }}
        shell: bash
Read more comments on GitHub >

github_iconTop Results From Across the Web

Github Actions: How use strategy/matrix with script
One final note: I attempted to just pass the matrix array of values to jobs.<job_id>.strategy.matrix.includes but this fails because matrix.
Read more >
With github actions, Is it possible to populate a matrix ...
The above throws the following error: Error when evaluating 'strategy' for job 'job1'. Unexpected type of value '[One String, ...
Read more >
Expression evaluation error at function 'contains' [line 39]
Hello All, I need to read an array extracted by a datasubset just to know if it contains a particular string. Following the...
Read more >
How to Fix: runtimewarning: invalid value encountered in ...
This error simply occurs when we performing a math operation and we encounter which is not valid as input. When we perform some...
Read more >
How to Handle the Incompatible Types Error in Java
The Java incompatible types error happens when a value assigned to a variable or returned by a method is incompatible with the one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found