0

So i have a github actions that fetches a json and then extracts a specific field into a new json array using

jq -r '[.hits[].id]' 

which results in this file: https://github.com/Jodsderechte/Jodsderechte.github.io/blob/main/Data/WaList_Converted.json

however if i try to use that in a matrix job using

${{fromJson(needs.setup.outputs.wa_List)}}

i get

Error when evaluating 'strategy' for job 'Request'. .github/workflows/RequestWagoData.yml (Line: 67, Col: 19): Error parsing fromJson,.github/workflows/RequestWagoData.yml (Line: 67, Col: 19): Error parsing fromJson,.github/workflows/RequestWagoData.yml (Line: 67, Col: 19): Error reading JToken from JsonReader. Path '', line 0, position 0.,.github/workflows/RequestWagoData.yml (Line: 67, Col: 19): Unexpected value ''

I guess this is because of the newlines but i'm not sure. i tried like a million different things trying to follow the advice in How to Remove \n and \r from JSON string using Bash? and Github Actions: How use strategy/matrix with script

but i can't for the live of me figure it out

https://github.com/Jodsderechte/Jodsderechte.github.io/edit/main/.github/workflows/RequestWagoData.yml here is the whole action including my history of 300 failed atempts of getting this to work

Jods
  • 1
  • 2
  • It might indeed be related to the new lines. Did you try informing the JSON hardcoded in the matrix strategy as it is, and then without breaking lines to check? – GuiFalourd Jun 15 '23 at 11:36
  • `-c` with `jq` will give you the compact JSON without newlines. – Azeem Jun 15 '23 at 11:39
  • In `jq -r '[.hits[].id]' << fetch-api-data-action/WeakAurasList.json >> $GITHUB_OUTPUT`, the output parameter name is missing i.e. `wa_List`. What is `content` [here](https://github.com/Jodsderechte/Jodsderechte.github.io/blob/main/.github/workflows/RequestWagoData.yml#LL24C1-L24C1)? – Azeem Jun 15 '23 at 11:42
  • i did hardcode the json into the matrix strategy and it works then yeah i'll try that -c thanks! – Jods Jun 15 '23 at 11:42
  • @Azeem content is the result of using https://github.com/jaywcjlove/github-action-read-file to read in the json file. that is just something i tried that is supposed to read the json and make it available – Jods Jun 15 '23 at 11:59
  • Right. Seems like something that you experimented with. Your recent [update](https://github.com/Jodsderechte/Jodsderechte.github.io/blob/main/.github/workflows/RequestWagoData.yml#L37) doesn't look right. Given your current configuration, it should be something like this: `run: echo "content=$(jq -r -c '[.hits[].id]' << fetch-api-data-action/WeakAurasList.json)" >> "$GITHUB_OUTPUT"`. Here, `content` is the array of `id`s. You need to set `id` for this step to access it in the `outputs`. See [Defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs). – Azeem Jun 15 '23 at 12:14
  • @Azeem but the step of that job has an id . i also tried your solution. i even tried printing using echo but all i'm getting is echo "" so somethign is still not right – Jods Jun 15 '23 at 12:27
  • This file path `fetch-api-data-action/WeakAurasList.json` is not correct. It should be [`./Data/WeakAurasList.json`](https://github.com/Jodsderechte/Jodsderechte.github.io/blob/main/Data/WeakAurasList.json) that's where it's located in your repo. And, that `<< file` needs to be `< file`. – Azeem Jun 15 '23 at 12:33
  • @Azeem Output or > output? also the /data/WeakAurasList.json only gets written after the step Build and Deploy and it is as mentioned in https://github.com/JamesIves/fetch-api-data-action in fetch-api-data-action/ – Jods Jun 15 '23 at 12:35
  • Or, if you're not using that file then you must be referring to the output of the steps [`fetchData`](https://github.com/Jodsderechte/Jodsderechte.github.io/blob/main/.github/workflows/RequestWagoData.yml#L26) then it should be handled accordingly i.e. `run: echo "content=$(jq -r -c '[.hits[].id]' < ./WeakAurasList)" >> "$GITHUB_OUTPUT"`. – Azeem Jun 15 '23 at 12:37
  • Looks like your workflow is all mixed at this point i.e. API output and the sample files. You might want to clean that up first. – Azeem Jun 15 '23 at 12:38
  • that results in /home/runner/work/_temp/27b5ceca-1570-4bc8-8a19-17e3e6689486.sh: line 1: ./WeakAurasList: No such file or directory But i cleaned it up it should now be better to read – Jods Jun 15 '23 at 12:40
  • Add `.json` extension. That action adds the extension to file name. See https://github.com/JamesIves/fetch-api-data-action#optional-choices. – Azeem Jun 15 '23 at 12:43
  • the whole data should also exist in env.fetch-api-data tried using that instead https://github.com/Jodsderechte/Jodsderechte.github.io/actions/runs/5278980602/jobs/9549039260 but that resulted in /home/runner/work/_temp/40b2debc-59a3-4f48-936c-0ebdbed45e52.sh: line 1: unexpected EOF while looking for matching `"' – Jods Jun 15 '23 at 12:51
  • Missing closing double quote after file name [here](https://github.com/Jodsderechte/Jodsderechte.github.io/actions/runs/5279007003/jobs/9549100152#step:5:2). – Azeem Jun 15 '23 at 12:52
  • ok and with Run echo "content=$(jq -r -c '[.hits[].id]' < ./WeakAurasList.json >> "$GITHUB_OUTPUT" i got /home/runner/work/_temp/f1a37079-05ae-4b4b-90cc-010c9d2334c7.sh: line 1: unexpected EOF while looking for matching `)' Error: Process completed with exit code 2. https://github.com/Jodsderechte/Jodsderechte.github.io/actions/runs/5279007003/jobs/9549100152 – Jods Jun 15 '23 at 12:52
  • ok back to Error when evaluating 'strategy' for job 'Request'. .github/workflows/RequestWagoData.yml (Line: 58, Col: 19): Error parsing fromJson,.github/workflows/RequestWagoData.yml (Line: 58, Col: 19): Error parsing fromJson,.github/workflows/RequestWagoData.yml (Line: 58, Col: 19): Error reading JToken from JsonReader. Path '', line 0, position 0.,.github/workflows/RequestWagoData.yml (Line: 58, Col: 19): Unexpected value '' now – Jods Jun 15 '23 at 12:57
  • and thats the workflow run for that error https://github.com/Jodsderechte/Jodsderechte.github.io/actions/runs/5279113814/jobs/9549341773 – Jods Jun 15 '23 at 13:06
  • Try: `echo "content=$(jq '[.hits[].id] | @json' <<< ${{env.fetch-api-data}})" >> "$GITHUB_OUTPUT"`. With file, you need `< file`, with string you need `<<< string`. Also, for `fromJson`, you need escaped JSON i.e. observe `@json` with `jq`. – Azeem Jun 15 '23 at 13:08
  • Invalid numeric literal at line 1, column 6 https://github.com/Jodsderechte/Jodsderechte.github.io/actions/runs/5279237680/jobs/9549621292 – Jods Jun 15 '23 at 13:12
  • Here's your working [workflow](https://github.com/iamazeem/Jodsderechte.github.io/actions/runs/5279642375/workflow). Changes: `echo "content=$(jq -c '[.hits[].id]' < "./fetch-api-data-action/WeakAurasList.json")" >> "$GITHUB_OUTPUT"` and `WeakAura: ${{ fromJson(needs.setup.outputs.wa_list) }}` – Azeem Jun 15 '23 at 13:49
  • 1
    thank you! it also was that i previously used ${{ env.steps.createList.outputs.content }} instead of ${{ steps.createList.outputs.content }} meaning everything i tried couldn't even work anyways – Jods Jun 15 '23 at 13:59
  • Yes, that `env.steps` was an issue too. You're welcome! I'll delete that fork shorty. – Azeem Jun 15 '23 at 15:32
  • Full [workflow](https://rhysd.github.io/actionlint/#eJx9UsFu2zAMvecrCCNN2oPlIbsZddf2sK3BgA1Dgh6KolBtJlaaSI5IxRuK/vsoO0nbYdhNBN/Te3ykszm0zj8t1q59qAw1mst6MFi5R8oHAIQcmvgA8MFS6gQeHoPlkK41I/Gg67nATWDqgQBrQ5zD8PkZiLEhpRuj9hAVe/Dy0vO6dg6w56Vg9QZz+IxiAgKhh0qzhoV3G7jVS7fHQewJbypoutkhZYvISEUnjYRUl2ycvdxNjoTWcJ0fKwC0VeOMFZs1s3jIskhUrYgo4zJC7cs6Q/q0Lebi4+Tj1clkMnUVVeixrBmlHG1chUXr2lGjl1h8GJHzXLwRIb3DtB/pFvXTVfCavplDaHFeU+Ugro8cCTkH+d9BEoMqhqerLaQljO9UbZju7pWp7sdwDon698zZOyG1ImeTswQuLiAZfrmZfZ1fP3yfz37MZ0k08RO3QZbYB2MRKwm1W/n/Nt4vzkux/H2IdKPZm1+vAR9c9FcQ9zcVJ6edhOoU3h3E2V8XccznNY9x/KiXUYffhTX+A4K02Qg=). – Azeem Jun 15 '23 at 15:36

0 Answers0