You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cannot test matrix.python-version in a if statement if version is dynamic (eg, *, 3.12-dev, 3.x) #644
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.
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 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!).
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.
@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.
Activity
lrq3000 commentedon 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 commentedon 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 commentedon 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 commentedon 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!
dmitry-shibanov commentedon Apr 11, 2023
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 as3.xor specify also minor version. Besides, I'm not sure that we need to add examples with if checks.lrq3000 commentedon 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
ifstatement, I have reworked it to only pertain topypyand 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.
v-mahabaleshwars commentedon Dec 17, 2024
Hi @lrq3000,
We’ve provided feedback on #645 . Please take a look when you have a chance, and let us know if you need any further assistance.
v-mahabaleshwars commentedon Dec 26, 2024
Hi @lrq3000, just a friendly reminder to review the feedback provided on #645 .