actions / setup-python

Set up your GitHub Actions workflow with a specific version of Python
MIT License
1.59k stars 505 forks source link

Multiple Python versions as a comma-separated list #870

Open paduszyk opened 1 month ago

paduszyk commented 1 month ago

Thanks for maintaining the project and considering my idea 🙂

Description: Allowing the action to accept comma-separated lists of Python versions would enhance the user experience if the versions are passed dynamically, as an output from another job.

Justification: Assume I would like to define multiple Python versions dynamically, e.g., by using a script get_python_versions.py that parses the pyproject.toml file (let us say, from classifiers or requires-python). The script prints the \n-separated list of strings to terminal:

$ python get_python_versions.py
3.9
3.10
3.11
3.12

Then I would like to use the script's output in the action. Since the action accepts newline-separated lists only, I have to do the following:

jobs:
  python-versions:
    runs-on: ubuntu-latest
    outputs:
      python-versions: ${{ steps.python-versions.outputs.python-versions }}
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
      - id: python-versions
        run: |
          echo "python-versions<<EOF" >> $GITHUB_OUTPUT
          echo "$(python get_python_versions.py)" >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT
  build:
    needs:
      - python-versions
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ needs.python-versions.outputs.python-versions }}

This works nicely. But... Now assume that the script returns a comma-separated list:

$ python get_python_versions.py
3.9,3.10,3.11,3.12

If comma-separated lists were allowed as the action's input, the python-versions step would be more concise and less verbose:

      ...
      - id: python-versions
        run: |
          echo "python-versions=$(python get_python_versions.py)" >> $GITHUB_OUTPUT
      ...

Are you willing to submit a PR?

I'm not familiar with Node/JS, so I'm not sure whether I am capable of opening a PR.

aparnajyothi-y commented 1 month ago

Hello @paduszyk, Thank you for creating this feature request and we will get back to you once we have some feedback on this :)