From 5dda955b834664163bc5048d05fe3788cc72d828 Mon Sep 17 00:00:00 2001 From: Mike Gouline <1960272+gouline@users.noreply.github.com> Date: Sat, 17 Jul 2021 21:56:35 +1000 Subject: [PATCH] Automatic releases (#35) * Setup version improvements * Release trigger and PyPI publish --- .github/workflows/{validate.yml => main.yml} | 21 ++++++++++++---- .gitignore | 1 + MANIFEST.in | 4 ++-- Makefile | 15 +++++++----- README.rst | 4 ++-- dbtmetabase/__init__.py | 2 +- pyproject.toml | 21 ++++++++++++++++ setup.py | 25 ++++++++++---------- 8 files changed, 64 insertions(+), 29 deletions(-) rename .github/workflows/{validate.yml => main.yml} (57%) create mode 100644 pyproject.toml mode change 100644 => 100755 setup.py diff --git a/.github/workflows/validate.yml b/.github/workflows/main.yml similarity index 57% rename from .github/workflows/validate.yml rename to .github/workflows/main.yml index 8c717686..05fbfb85 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/main.yml @@ -1,14 +1,16 @@ -name: Build and Validate +name: Main on: pull_request: branches: - master + release: + types: [created] jobs: - validate: + build: + name: Build and validate runs-on: ubuntu-latest - name: validate steps: - uses: actions/checkout@v2 @@ -18,12 +20,14 @@ jobs: key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} restore-keys: | ${{ runner.os }}-pip- - - uses: nanasess/setup-chromedriver@master - name: Requirements run: make requirements - - name: Lint + - name: Build + run: make build + + - name: Lint check run: make lint - name: Type check @@ -31,3 +35,10 @@ jobs: - name: Test run: make test + + - name: Publish a Python distribution to PyPI + if: github.event_name == 'release' + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_TOKEN }} diff --git a/.gitignore b/.gitignore index e69bd306..c3401424 100644 --- a/.gitignore +++ b/.gitignore @@ -26,6 +26,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +*/_version.py # PyInstaller # Usually these files are written by a python script from a template diff --git a/MANIFEST.in b/MANIFEST.in index 3d23561e..8a22ce41 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,4 @@ include requirements.txt -include test-requirements.txt +include requirements-test.txt include LICENSE -include README.rst \ No newline at end of file +include README.rst diff --git a/Makefile b/Makefile index bf6c24b0..1df0cc8e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,3 @@ -.PHONY: all build check clean dev-requirements - -all: build - build: clean python3 setup.py sdist bdist_wheel @@ -11,21 +7,28 @@ clean: requirements: pip3 install -r requirements.txt pip3 install -r requirements-test.txt +.PHONY: requirements lint: - pylint --disable=R,C dbtmetabase + pylint dbtmetabase +.PHONY: lint type: - mypy --ignore-missing-imports dbtmetabase + mypy dbtmetabase +.PHONY: type test: python3 -m unittest tests +.PHONY: test check: build twine check dist/* +.PHONY: check upload: check twine upload dist/* +.PHONY: upload dev-install: build pip3 uninstall -y dbt-metabase && pip3 install dist/dbt_metabase-*-py3-none-any.whl +.PHONY: dev-install diff --git a/README.rst b/README.rst index e510d4ef..88733a44 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ dbt-metabase ############ -.. image:: https://github.com/gouline/dbt-metabase/actions/workflows/validate.yml/badge.svg - :target: https://github.com/gouline/dbt-metabase/actions/workflows/validate.yml +.. image:: https://github.com/gouline/dbt-metabase/actions/workflows/main.yml/badge.svg + :target: https://github.com/gouline/dbt-metabase/actions/workflows/main.yml :alt: GitHub Actions .. image:: https://img.shields.io/pypi/v/dbt-metabase :target: https://pypi.org/project/dbt-metabase/ diff --git a/dbtmetabase/__init__.py b/dbtmetabase/__init__.py index 78277a62..30ea7b72 100644 --- a/dbtmetabase/__init__.py +++ b/dbtmetabase/__init__.py @@ -9,7 +9,7 @@ from typing import Iterable, List, Union -__version__ = "0.8.0" +from ._version import version as __version__ def export( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..65483e03 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,21 @@ +[build-system] +requires = ["setuptools>=45", "wheel", "setuptools_scm"] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +write_to = "dbtmetabase/_version.py" + +[tool.black] +line-length = 100 +target-version = ['py36', 'py37', 'py38', 'py39'] +include = '\.pyi?$' + +[tool.mypy] +python_version = "3.8" + +[[tool.mypy.overrides]] +module = ["dbtmetabase"] +ignore_missing_imports = true + +[tool.pylint.master] +disable = ["R", "C"] diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index b4fb7b77..c8a39808 --- a/setup.py +++ b/setup.py @@ -6,20 +6,16 @@ if sys.version_info < (3, 6): raise ValueError("Requires Python 3.6+") -from dbtmetabase import __version__ - -with open("requirements.txt", "r") as f: - requires = [x.strip() for x in f if x.strip()] - -with open("requirements-test.txt", "r") as f: - test_requires = [x.strip() for x in f if x.strip()] +def requires_from_file(filename: str) -> list: + with open(filename, "r") as f: + return [x.strip() for x in f if x.strip()] with open("README.rst", "r") as f: readme = f.read() setup( name="dbt-metabase", - version=__version__, + use_scm_version=True, description="Model synchronization from dbt to Metabase.", long_description=readme, long_description_content_type="text/x-rst", @@ -27,14 +23,15 @@ author_email="hello@gouline.net", url="https://github.com/gouline/dbt-metabase", license="MIT License", + scripts=["dbtmetabase/bin/dbt-metabase"], packages=find_packages(exclude=["tests"]), test_suite="tests", - scripts=["dbtmetabase/bin/dbt-metabase"], - tests_require=test_requires, - install_requires=requires, - extras_require={"test": test_requires}, + install_requires=requires_from_file("requirements.txt"), + extras_require={ + "test":requires_from_file("requirements-test.txt") + }, + setup_requires=["setuptools_scm"], classifiers=[ - "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", @@ -42,6 +39,8 @@ "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", ],