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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] implement an outputs for matrix compatible jobs #530

Closed
2 tasks done
onedr0p opened this issue Jun 22, 2022 · 11 comments 路 Fixed by #557
Closed
2 tasks done

[Feature] implement an outputs for matrix compatible jobs #530

onedr0p opened this issue Jun 22, 2022 · 11 comments 路 Fixed by #557
Labels
enhancement New feature or request

Comments

@onedr0p
Copy link

onedr0p commented Jun 22, 2022

Is this feature missing in the latest version?

  • I'm using the latest release

Is your feature request related to a problem? Please describe.

Hi 馃憢馃徏

It would be need if you had an outputs that can work with a matrix, this does not work

Check out this workflow: https://github.com/onedr0p/containers/blob/c15d8b71b288f812edb971a4c3966e62592bba1c/.github/workflows/release.yaml

And the run: https://github.com/onedr0p/containers/runs/6996087930?check_suite_focus=true

And the error: https://github.com/onedr0p/containers/actions/runs/2539358559

Describe the solution you'd like?

Implement a outputs.all_changed_files_json or similar that can be used with toJSON and fromJSON to pass the outputs on to a matrix.

Thanks!

Describe alternatives you've considered?

No response

Anything else?

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@onedr0p onedr0p added the enhancement New feature or request label Jun 22, 2022
@github-actions
Copy link
Contributor

Thanks for reporting this issue, don't forget to star this project to help us reach a wider audience.

@jackton1
Copy link
Member

jackton1 commented Jun 22, 2022

Hi @onedr0p, based on the error

Error when evaluating 'strategy' for job 'release'. .github/workflows/release.yaml (Line: 44, Col: 15): Unexpected type of value 'images/lidarr/nightly/metadata.json', expected type: Sequence.

You seem to be passing a space-delimited string to the toJSON function without quotes.

Possible Solution

outputs:
      matrix: "{\"container\": \"${{ steps.changed-files.outputs.all_changed_files }}\" }"

Note: You might also need to use the separator input to return a comma-separated string and wrap them in an array.

See: https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object

@jackton1 jackton1 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 22, 2022
@jackton1
Copy link
Member

@onedr0p Edited 猬嗭笍

@SiddhantSadangi
Copy link

@jackton1
I think the separator parameter is stripping out escaped double quotes:

Step:

    - name: Get changed notebooks
      id: changed-notebooks
      uses: tj-actions/changed-files@v23.1
      with:
        separator: "\", \""
        files: |
          **/*.ipynb

Code:

echo -e "Separator: \", \""
echo -e "Output: ${{ steps.changed-notebooks.outputs.all_changed_files }}"
echo -e "JSON format: {\"path\":[\"${{ steps.changed-notebooks.outputs.all_changed_files }}\""]}"
echo -e "::set-output name=changed_notebooks::{\"path\":[\"${{ steps.changed-notebooks.outputs.all_changed_files }}\""]}"
echo -e "JSON: ${{toJSON(needs.get-notebooks.outputs.changed_notebooks)}}"

Result:

Separator: ", "
Output: fail.ipynb, pass.ipynb
JSON format: {"path":["fail.ipynb, pass.ipynb"]}
echo -e ::set-output name=changed_notebooks::{"path":["fail.ipynb, pass.ipynb"]}
JSON: null

Expected result:

Separator: ", "
Output: fail.ipynb", "pass.ipynb
JSON format: {"path":["fail.ipynb", "pass.ipynb"]}
echo -e ::set-output name=changed_notebooks::{"path":["fail.ipynb", "pass.ipynb"]}

@jackton1 jackton1 reopened this Aug 3, 2022
@jackton1 jackton1 linked a pull request Aug 3, 2022 that will close this issue
@sebestenyb
Copy link

Hi, I still have the error with the latest version:

Error when evaluating 'strategy' for job 'matrix-job'. .github/workflows/default.yml (Line: 30, Col: 15): Unexpected type of value '[\".github/workflows/default.yml\",\"demo.json\"]', expected type: Sequence.

I'm using the workflow file from the repository: https://github.com/tj-actions/changed-files/blob/dd1d85da10027d585a8e394aeee7524eb2f17bcf/.github/workflows/manual-matrix-test.yml

Even if I change the matrix definition in the workflow file to the one from above ( matrix: "{\"container\": \"${{ steps.changed-files.outputs.all_changed_files }}\" }"), the same error happens, slightly different output:

Error when evaluating 'strategy' for job 'matrix-job'. .github/workflows/default.yml (Line: 30, Col: 15): Unexpected type of value '[".github/workflows/default.yml","demo.json"]', expected type: Sequence.

@jackton1
Copy link
Member

jackton1 commented Aug 8, 2022

@sebestenyb @guitmz Note the lack of space between the key and value a full example of this can be seen here: https://docs.github.com/en/actions/learn-github-actions/expressions#example-returning-a-json-object

CHANGE

matrix: "{\"container\": \"${{ steps.changed-files.outputs.all_changed_files }}\" }"

TO

matrix:"{\"container\":${{ steps.changed-files.outputs.all_changed_files }}}"

See: https://github.com/tj-actions/changed-files/blob/main/.github/workflows/manual-matrix-test.yml#L27

@guitmz
Copy link

guitmz commented Aug 8, 2022

Actually what fixed for me was to specify 24.1 in my GitHub actions instead of only 24 for the version.
The syntax I grabbed from the repo test actions and it works fine!

@jackton1
Copy link
Member

jackton1 commented Aug 8, 2022

Cool.

@sebestenyb
Copy link

The latest test action in the repo is slightly different than the one in the PR merge commit above, it uses a separate step to set the matrix, like

- id: set-matrix
  run: echo "::set-output name=matrix::{\"container\":${{ steps.changed-files.outputs.all_changed_files }}}"

Not sure this fixed, or the lack of spaces, but it works now, thanks for you help folks!

@prein
Copy link

prein commented Sep 5, 2022

Would any of you mind posting full working example with passing the json to matrix strategy in another job?

@jackton1
Copy link
Member

jackton1 commented Sep 5, 2022

@prein Here鈥檚 an example: https://github.com/tj-actions/changed-files/blob/main/.github/workflows/manual-matrix-test.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants