Skip to content

Commit 8120146

Browse files
committed
Add github workflow for testing and building
1 parent 3b9847c commit 8120146

File tree

3 files changed

+116
-4
lines changed

3 files changed

+116
-4
lines changed

.github/workflows/ci-cd.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: CI_CD
2+
3+
on: [push, pull_request]
4+
5+
permissions: {}
6+
jobs:
7+
Unit_tests:
8+
runs-on: ${{ matrix.os }}
9+
timeout-minutes: 10
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
python-version: [
14+
"2.7",
15+
"3.7", "3.8", "3.9", "3.10", "3.11-dev",
16+
"pypy-2.7", "pypy-3.8"
17+
]
18+
os: [ubuntu-latest, macOS-latest, windows-latest]
19+
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
- name: Install dependencies
27+
run: |
28+
pip install -r test-requirements.txt -r requirements.txt
29+
- name: Run tests
30+
run: |
31+
pytest
32+
33+
Integration_tests:
34+
runs-on: ${{ matrix.os }}
35+
timeout-minutes: 10
36+
needs: Unit_tests
37+
strategy:
38+
fail-fast: false
39+
matrix:
40+
python-version: [
41+
"3.10",
42+
]
43+
os: [ubuntu-latest, macOS-latest, windows-latest]
44+
steps:
45+
- uses: actions/checkout@v3
46+
- name: Set up Python ${{ matrix.python-version }}
47+
uses: actions/setup-python@v4
48+
with:
49+
python-version: ${{ matrix.python-version }}
50+
- name: Install dependencies
51+
run: |
52+
pip install -r test-requirements.txt -r requirements.txt
53+
- name: Run tests
54+
env:
55+
TINIFY_KEY: ${{ secrets.TINIFY_KEY }}
56+
run: |
57+
pytest test/integration.py
58+
59+
Publish:
60+
if: |
61+
github.repository == 'tinify/tinify-python' &&
62+
startsWith(github.ref, 'refs/tags') &&
63+
github.event_name == 'push'
64+
timeout-minutes: 10
65+
needs: [Unit_tests, Integration_tests]
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v3
69+
with:
70+
fetch-depth: 0
71+
persist-credentials: false
72+
- name: Set up Python
73+
uses: actions/setup-python@v4
74+
with:
75+
python-version: "3.10"
76+
- name: Install dependencies
77+
run: |
78+
pip install -r requirements.txt
79+
pip install build wheel
80+
- name: Build package (sdist & wheel)
81+
run: |
82+
python -m build --sdist --wheel --outdir dist/
83+
- name: Test sdist install
84+
run: |
85+
python -m venv sdist_env
86+
./sdist_env/bin/pip install dist/tinify*.tar.gz
87+
- name: Test wheel install
88+
run: |
89+
python -m venv wheel_env
90+
./wheel_env/bin/pip install dist/tinify*.whl
91+
- name: Publish package to PyPI
92+
uses: pypa/gh-action-pypi-publish@master
93+
with:
94+
user: __token__
95+
password: ${{ secrets.PYPI_ACCESS_TOKEN }}
96+
# Use the test repository for testing the publish feature
97+
# repository_url: https://test.pypi.org/legacy/
98+
packages_dir: dist/
99+
print_hash: true
100+

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
author_email='[email protected]',
2727
license='MIT',
2828
long_description='Python client for the Tinify API. Tinify compresses your images intelligently. Read more at https://tinify.com.',
29+
long_description_content_type='text/markdown',
2930
url='https://tinify.com/developers',
3031

3132
packages=['tinify'],
@@ -46,8 +47,6 @@
4647
'Programming Language :: Python',
4748
'Programming Language :: Python :: 2.7',
4849
'Programming Language :: Python :: 3',
49-
'Programming Language :: Python :: 3.5'
50-
'Programming Language :: Python :: 3.6'
5150
'Programming Language :: Python :: 3.7',
5251
'Programming Language :: Python :: 3.8',
5352
'Programming Language :: Python :: 3.9',

test/integration.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import sys, os
2-
from test.helper import create_named_tmpfile
2+
from contextlib import contextmanager
3+
import tinify, unittest, tempfile
34

45
if not os.environ.get("TINIFY_KEY"):
56
sys.exit("Set the TINIFY_KEY environment variable.")
67

7-
import tinify, unittest, tempfile
8+
@contextmanager
9+
def create_named_tmpfile():
10+
# Due to NamedTemporaryFile requiring to be closed when used on Windows
11+
# we create our own NamedTemporaryFile contextmanager
12+
# See note: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile
13+
14+
tmp = tempfile.NamedTemporaryFile(delete=False)
15+
try:
16+
tmp.close()
17+
yield tmp.name
18+
finally:
19+
os.unlink(tmp.name)
20+
821

922
class ClientIntegrationTest(unittest.TestCase):
1023
tinify.key = os.environ.get("TINIFY_KEY")

0 commit comments

Comments
 (0)