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

Cannot test matrix.python-version in a if statement if version is dynamic (eg, *, 3.12-dev, 3.x) #644

Open
4 of 5 tasks
lrq3000 opened this issue Apr 7, 2023 · 6 comments · May be fixed by #645
Open
4 of 5 tasks
Labels
bug Something isn't working

Comments

@lrq3000
Copy link

lrq3000 commented Apr 7, 2023

Description:
When using a dynamic (x-range) version such as *, 3.12-dev or 3.x, then the usual method of doing conditional steps (by testing in matrix.python-version >= 3.7 for example) does not work.

Action version:
1.5

Platform:

  • Ubuntu
  • macOS
  • Windows

Runner type:

  • Hosted
  • Self-hosted

Tools version:
Dynamic versions.

Repro steps:
See for example the github action config file I used which caused this error:
https://github.com/lrq3000/pyFileFixity/blob/ea3ce6564a145687ca6519e8f5422c38ec88c2a1/.github/workflows/ci-build.yml

And the run:
https://github.com/lrq3000/pyFileFixity/actions/runs/4639718475

Expected behavior:
The dynamic version should resolve to a fixed version after instanciation.

Actual behavior:
Dynamic version remains as-is. If fails.

@lrq3000 lrq3000 added bug Something isn't working needs triage labels Apr 7, 2023
@lrq3000
Copy link
Author

lrq3000 commented Apr 7, 2023

Maybe there is a way around but I did not find any such info in the documentation nor on internet (I guess dynamic versions aren't very popular), or maybe I'm dumb, please let me know if I missed something.

@nulano
Copy link

nulano commented Apr 7, 2023

The version you specify in the matrix is just a string that you can use anywhere, an action cannot modify it. However, this action does provide the actual resolved Python version in an output that you can use instead: https://github.com/actions/setup-python/blob/main/docs/advanced-usage.md#python-version

@lrq3000
Copy link
Author

lrq3000 commented Apr 9, 2023

@nulano Perfect, this is exactly what I needed! But I see why I missed it, there are words missing in the description, and the example is misleading (why set the id to "cp310" which clearly refers to CPython 3.10, but here it has nothing to do with that as it refers to setup-python action!).

@lrq3000
Copy link
Author

lrq3000 commented Apr 9, 2023

PS: Sorry the comment button was hit inadvertently. I will make a PR to fix this. Thank you very much for pointing this resource!

@lrq3000 lrq3000 linked a pull request Apr 9, 2023 that will close this issue
2 tasks
@dmitry-shibanov
Copy link
Contributor

Hello @lrq3000. I've took a look on your pull request and I'd not like to recommend using of * because it stays for installing the most possible latest version and it can lead to unexpected version change and possible breaking changes. The better approach is to specify version as 3.x or specify also minor version. Besides, I'm not sure that we need to add examples with if checks.

@lrq3000
Copy link
Author

lrq3000 commented Apr 11, 2023

@dmitry-shibanov Thank you for reviewing my PR and for your feedback.

Ok I understand your reasoning, I have removed the example involving *.

About the if statement, I have reworked it to only pertain to pypy and not *. I would like to suggest once more to consider adding it, as I think it is a common use case, and is often a cause for errors and frustration. Indeed, if you just try to do this to check the PyPy version:

if: ${{ python-version != pypy-2.7 }}

It will keep on failing with a syntax error. Whereas to check Python versions, the following works fine:

if: ${{ python-version != 2.7 }}

This is because python-version can be specified as either a float or a string literal. The problem is that for pypy, only a string literal is possible since it must include the characters 'pypy' to signal the version refers to pypy.

But now where things get muddy is that in the definition of python-version, string literals can be specified without single-quotes, as shown in the Specifying multiple Python/PyPy version section! So then it's very expectable that users will try to simply copy/paste their definition in the if expression, and then the issue will arise. Then they will try double quotes, and again it will fail. Until they stumble on the Expression manual page of GitHub workflows, and see in a footnote that only single quotes are a valid syntax for string literals...

All that is to say, with this one-line addition of an example if statement, a lot of frustration and GitHub Workflow know-how prerequisites can be avoided.

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

Successfully merging a pull request may close this issue.

3 participants