Search code examples
python-3.xgithub-actionsartifactorysetuptools

Fail uploading python package to artifactory if version already exists


I have a Github repository for a python package, github-actions pushes the package to artifactory whenever a change to main has been made. I want to add something in github-actions that doesn't publish the package to artifactory if a version number alreaedy exists.

github actions code looks like:

      - name: Deploying Package
    env:
      PYRC: ${{ secrets.DI_PYPIRC }}
      PYCONF: ${{ secrets.DI_PY_PIP_CONF }}
    run: |
      echo "$PYRC" >> ~/.pypirc
      ls -a
      python setup.py sdist bdist_wheel upload -r local
    

PYRC and PYCONF are secrets that build the .pypirc and pip.conf file that are used to upload to artifactory and pip.conf is used to point the pip install to repositories to pull packages from.

Trying to add something here that would fail the build if setup.py has a version that is already available in artifactory. Is it possible to do through a github workflow?


Solution

  • There are two approaches to do this:

    1. Configure the Artifactory account used to upload to not have delete/overwrite permissions (you can read more about how permissions work here: Artifactory Docs - Permissions.

      In your GitHub Action then, it will recieve an error when it tries to upload, which fits your requirements.

      If interested, you could look more into Artifactory Docs - Access Tokens as an approach, where you can create a token with specific permissions for specific repositories.

    2. Write a script which checks via the Artifactory API whether that version exists and if it doesn't, then upload. You could use this endpoint Artifactory API Docs - File Info probably to get this info.

      I would only do this approach if you don't have the ability to do the above, as the above would be the simpler/better approach.

    Let us know how you go!