| 1 |
name: tests |
| 2 |
|
| 3 |
on: |
| 4 |
push: |
| 5 |
branches: |
| 6 |
- main |
| 7 |
tags: |
| 8 |
- v* |
| 9 |
pull_request: |
| 10 |
workflow_dispatch: |
| 11 |
|
| 12 |
jobs: |
| 13 |
run-tests: |
| 14 |
strategy: |
| 15 |
matrix: |
| 16 |
config: |
| 17 |
# [Python version, tox env] |
| 18 |
- ["3.9", "py39"] |
| 19 |
- ["3.10", "py310"] |
| 20 |
- ["3.11", "py311"] |
| 21 |
- ["3.12", "py312"] |
| 22 |
- ["3.13", "py313"] |
| 23 |
|
| 24 |
runs-on: ubuntu-latest |
| 25 |
name: ${{ matrix.config[1] }} |
| 26 |
steps: |
| 27 |
- uses: actions/checkout@v4 |
| 28 |
- name: Set up Python |
| 29 |
uses: actions/setup-python@v4 |
| 30 |
with: |
| 31 |
python-version: ${{ matrix.config[0] }} |
| 32 |
- name: Pip cache |
| 33 |
uses: actions/cache@v3 |
| 34 |
with: |
| 35 |
path: ~/.cache/pip |
| 36 |
key: ${{ runner.os }}-pip-${{ matrix.config[0] }}-${{ hashFiles('setup.*', 'tox.ini') }} |
| 37 |
restore-keys: | |
| 38 |
${{ runner.os }}-pip-${{ matrix.config[0] }}- |
| 39 |
${{ runner.os }}-pip- |
| 40 |
- name: Install dependencies |
| 41 |
run: | |
| 42 |
python -m pip install --upgrade pip |
| 43 |
pip install tox |
| 44 |
- name: Test |
| 45 |
run: | |
| 46 |
test/test_code_quality.sh |
| 47 |
tox -e ${{ matrix.config[1] }} -- --x-wr-timezone=all |
| 48 |
|
| 49 |
deploy-tag-to-pypi: |
| 50 |
# only deploy on tags, see https://stackoverflow.com/a/58478262/1320237 |
| 51 |
if: startsWith(github.ref, 'refs/tags/v') |
| 52 |
needs: |
| 53 |
- run-tests |
| 54 |
runs-on: ubuntu-latest |
| 55 |
# This environment stores the TWINE_USERNAME and TWINE_PASSWORD |
| 56 |
# see https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment |
| 57 |
environment: |
| 58 |
name: PyPI |
| 59 |
url: https://pypi.org/project/x-wr-timezone/ |
| 60 |
# after using the environment, we need to make the secrets available |
| 61 |
# see https://docs.github.com/en/actions/security-guides/encrypted-secrets#example-using-bash |
| 62 |
env: |
| 63 |
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }} |
| 64 |
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }} |
| 65 |
steps: |
| 66 |
- uses: actions/checkout@v4 |
| 67 |
- name: Set up Python |
| 68 |
uses: actions/setup-python@v4 |
| 69 |
with: |
| 70 |
python-version: "3.9" |
| 71 |
- name: Install dependencies |
| 72 |
run: | |
| 73 |
python -m pip install --upgrade pip |
| 74 |
pip install wheel twine |
| 75 |
- name: Check the tag |
| 76 |
run: | |
| 77 |
PACKAGE_VERSION=`python setup.py --version` |
| 78 |
TAG_NAME=v$PACKAGE_VERSION |
| 79 |
echo "Package version $PACKAGE_VERSION with possible tag name $TAG_NAME on $GITHUB_REF_NAME" |
| 80 |
# test that the tag represents the version |
| 81 |
# see https://docs.gitlab.com/ee/ci/variables/predefined_variables.html |
| 82 |
# see https://docs.github.com/en/actions/learn-github-actions/environment-variables |
| 83 |
if [ "$TAG_NAME" != "$GITHUB_REF_NAME" ]; then |
| 84 |
echo "ERROR: This tag is for the wrong version. Got \"$GITHUB_REF_NAME\" expected \"$TAG_NAME\"." |
| 85 |
exit 1 |
| 86 |
fi |
| 87 |
- name: remove old files |
| 88 |
run: rm -rf dist/* |
| 89 |
- name: build distribution files |
| 90 |
run: python setup.py bdist_wheel sdist |
| 91 |
- name: deploy to pypi |
| 92 |
run: | |
| 93 |
# You will have to set the variables TWINE_USERNAME and TWINE_PASSWORD |
| 94 |
# You can use a token specific to your project by setting the user name to |
| 95 |
# __token__ and the password to the token given to you by the PyPI project. |
| 96 |
# sources: |
| 97 |
# - https://shambu2k.hashnode.dev/gitlab-to-pypi |
| 98 |
# - http://blog.octomy.org/2020/11/deploying-python-pacakges-to-pypi-using.html?m=1 |
| 99 |
# Also, set the tags as protected to allow the secrets to be used. |
| 100 |
# see https://docs.gitlab.com/ee/user/project/protected_tags.html |
| 101 |
if [ -z "$TWINE_USERNAME" ]; then |
| 102 |
echo "WARNING: TWINE_USERNAME not set!" |
| 103 |
fi |
| 104 |
if [ -z "$TWINE_PASSWORD" ]; then |
| 105 |
echo "WARNING: TWINE_PASSWORD not set!" |
| 106 |
fi |
| 107 |
twine check dist/* |
| 108 |
twine upload dist/* |