Using GitHub Actions to Build Python Packages
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:
- Checkout code
- Setup Python
- Lint the code
- Build the packages
- Get the version for the release from setup.py
- 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.