Test tags #8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python | |
name: Python package | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
tags: | |
- '*' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.9", "3.10", "3.11"] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v3 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install flake8 pytest | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
- name: Lint with flake8 | |
run: | | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
deploy-tag-to-pypi: | |
# only deploy on tags, see https://stackoverflow.com/a/58478262/1320237 | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: | |
- build | |
runs-on: ubuntu-latest | |
# This environment stores the TWINE_USERNAME and TWINE_PASSWORD | |
# see https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment | |
environment: | |
name: PyPI | |
url: https://pypi.org/project/hanging_threads/ | |
# after using the environment, we need to make the secrets available | |
# see https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash | |
env: | |
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.9" | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install wheel twine | |
- name: Check the tag | |
run: | | |
PACKAGE_VERSION=`python setup.py --version` | |
TAG_NAME=v$PACKAGE_VERSION | |
echo "Package version $PACKAGE_VERSION with possible tag name $TAG_NAME on $GITHUB_REF_NAME" | |
# test that the tag represents the version | |
# see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html | |
# see https://docs.github.com/en/actions/learn-github-actions/environment-variables | |
if [ "$TAG_NAME" != "$GITHUB_REF_NAME" ]; then | |
echo "ERROR: This tag is for the wrong version. Got \"$GITHUB_REF_NAME\" expected \"$TAG_NAME\"." | |
exit 1 | |
fi | |
- name: remove old files | |
run: rm -rf dist/* | |
- name: build distribution files | |
run: python setup.py bdist_wheel sdist | |
- name: deploy to pypi | |
run: | | |
# You will have to set the variables TWINE_USERNAME and TWINE_PASSWORD | |
# You can use a token specific to your project by setting the user name to | |
# __token__ and the password to the token given to you by the PyPI project. | |
# sources: | |
# - https://shambu2k.hashnode.dev/gitlab-to-pypi | |
# - http://blog.octomy.org/2020/11/deploying-python-pacakges-to-pypi-using.html?m=1 | |
# Also, set the tags as protected to allow the secrets to be used. | |
# see https://docs.gitlab.com/ee/user/project/protected_tags.html | |
if [ -z "$TWINE_USERNAME" ]; then | |
echo "WARNING: TWINE_USERNAME not set!" | |
fi | |
if [ -z "$TWINE_PASSWORD" ]; then | |
echo "WARNING: TWINE_PASSWORD not set!" | |
fi | |
twine check dist/* | |
twine upload dist/* |