Cannot run github action to publish python package

I am trying to run this workflow to publish a python package from the directory cvplay repository inside the main repo cvplayground
I have tried multiple answers here and on stackoverflow but keep getting

every step must define a `uses` or `run` key

or setup.py not found inside the directory and cannot figure out the main issue here.Need help

Here is the workflow file for quick view


name: Upload Python Package

on: [push]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Change directory
        working-directory: ./cvplay
      - name: Install dependencies
        working-directory: ./cvplay
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine
      - name: Build and publish
        working-directory: ./cvplay
        env:
          TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
          TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
        run: |
          python setup.py sdist bdist_wheel
          twine upload testpypi dist/* 

UPDATE : Does it mean I add uses tag before every name?

No, the error means each step must contain (order doesn’t matter) either a uses attribute (to use a predefined action) or a run attribute (to use a custom script).

There is one step in your workflow that doesn’t follow that rule:

You can just remove it.

Hi @ashwin-phadke,

As the error mentioned, every step must define a uses or run key. However below step doens’t follow the rule:

      - name: Change directory
        working-directory: ./cvplay

You can remove step. Instead of setting working directory for each step, you can set it in job level just once.

jobs:
  deploy:
    defaults:
      run:
        working-directory: ./cvplay   # job level working directory
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine
        ......

Doc here: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#defaultsrun

Thanks

1 Like

Thank you @weide-zhou , that helped, only one thing gives error now after I specified python versions using setup-python that twine command not found. If all other packages are being installed by default in home directory how can one package install in some other place, I guess command not found was more pertaining to this error message that I get while installing dependencies

WARNING: The script wheel is installed in '/home/runner/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. multiple times.

Here is the error I get in actual build and publish part :
/home/runner/work/_temp/ace6d6e16507.sh: line 2: twine: command not found ##[error]Process completed with exit code 127.

and this is how I have specified python version in the workflow :

      uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      - name: Install dependencies

and I do

        run: |
          python -m pip install --upgrade pip
          pip3 install --user setuptools wheel twine

to install packages, I added --user option to overcome this error but it is still there.

Here is the full updated workflow

# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: Upload Python Package

on: [push]

jobs:
  deploy:
    defaults:
      run:
        working-directory: ./cvplay   # job level working directory
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip3 install --user setuptools wheel twine
      - name: Build and publish
        env:
          TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
          TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
        run: |
          python setup.py sdist bdist_wheel
          twine upload testpypi dist/* 

UPDATE : adding ~/.local/bin/twine worked but there should be a workaround

Thank you that helped.

1 Like

Hi @ashwin-phadke,

By default, the twine is installed in below location and runner can find it without issue:

pip3 install setuptools wheel twine

image

If you install in user directory, system cannot find twine command automatically, and you need add system path to fix it.

echo "::add-path::/home/runner/.local/bin"

image

Doc here: https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#adding-a-system-path

Thanks

1 Like

For me it is by default getting installed at /local/bin.
Thanks for the help.