For Python projects in GitHub it would be useful to build projects automatically upon pushing changes to the master branch. Here is the file I used for my repository.

The job has the following steps:

  1. Checkout code
  2. Setup Python
  3. Lint the code
  4. Build the packages
  5. Get the version for the release from setup.py
  6. Create release and upload packages

This action pulls in the version from setup.py. It sets the environment variable using echo:

    - name: get-version
      run: |
        VERSION=$(grep version setup.py | cut -d "'" -f 2)
        echo "VERSION=$VERSION" >> $GITHUB_ENV        

This allows you to set any Environment variable for GitHub actions. Then we use it later when tagging the release:

    - name: Upload binaries to release
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.API_TOKEN }}
        file: dist/*
        tag: ${{ env.VERSION }}
        overwrite: true
        file_glob: true

If the action fails on linting or building it will not continue to create a release.