Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize CI and release process #142

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .flake8

This file was deleted.

23 changes: 4 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ jobs:
PGUSER: odoo
PGPASSWORD: odoo
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "${{ matrix.python-version }}"
- uses: actions/cache@v2
- uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ matrix.toxenv }}
Expand All @@ -78,19 +78,4 @@ jobs:
pip install tox virtualenv
- name: Run tox
run: tox -e ${{ matrix.toxenv }}
- uses: codecov/codecov-action@v1
deploy:
runs-on: ubuntu-latest
needs:
- tests
if: startsWith(github.ref, 'refs/tags')
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- name: Build a binary wheel and a source tarball
run: pipx run build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.pypi_token }}
- uses: codecov/codecov-action@v3
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
on:
release:
types:
- published

name: release

jobs:
pypi:
name: upload release to PyPI
runs-on: ubuntu-latest
environment: release

permissions:
# Used to authenticate to PyPI via OIDC.
id-token: write

steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: ">= 3.8"

- name: build
run: pipx run build

- name: publish
uses: pypa/gh-action-pypi-publish@release/v1
2 changes: 0 additions & 2 deletions .isort.cfg

This file was deleted.

37 changes: 13 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
exclude: "^tests/data/.*$"
repos:
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: ["flake8-bugbear==20.1.4"]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.3
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
- id: ruff-format
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ To run tests, type ``tox``. Tests are made using pytest. To run tests matching
a specific keyword for, say, Odoo 12 and python 3.6, use
``tox -e py36-12.0 -- -k keyword``. For running tests you need a postgres server accessible for your user without a password at ``/var/run/postgresql/.s.PGSQL.5432``.

This project uses `black <https://github.com/ambv/black>`_
as code formatting convention, as well as isort and flake8.
To make sure local coding convention are respected before
you commit, install
`pre-commit <https://github.com/pre-commit/pre-commit>`_ and
run ``pre-commit install`` after cloning the repository.

To release, create a tagged release on GitHub. This will trigger publishing to PyPI.

Credits
~~~~~~~

Expand Down
31 changes: 10 additions & 21 deletions click_odoo_contrib/initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ def odoo_createdb(dbname, demo, module_names, force_db_storage):
odoo.tools.config["init"] = dict.fromkeys(module_names, 1)
odoo.tools.config["without_demo"] = not demo
odoo.modules.registry.Registry.new(dbname, force_demo=demo, update_module=True)
_logger.info(
click.style(
"Created new Odoo database {dbname}.".format(**locals()), fg="green"
)
)
_logger.info(click.style(f"Created new Odoo database {dbname}.", fg="green"))
with odoo.sql_db.db_connect(dbname).cursor() as cr:
_save_installed_checksums(cr)
odoo.sql_db.close_db(dbname)
Expand Down Expand Up @@ -151,39 +147,32 @@ def _make_new_template_name(self, hashsum):
def _create_db_from_template(self, dbname, template):
_logger.info(
click.style(
"Creating database {dbname} "
"from template {template}".format(**locals()),
f"Creating database {dbname} from template {template}",
fg="green",
)
)
self.pgcr.execute(
"""
f"""
CREATE DATABASE "{dbname}"
ENCODING 'unicode'
TEMPLATE "{template}"
""".format(
**locals()
)
"""
)

def _rename_db(self, dbname_from, dbname_to):
self.pgcr.execute(
"""
f"""
ALTER DATABASE "{dbname_from}"
RENAME TO "{dbname_to}"
""".format(
**locals()
)
"""
)

def _drop_db(self, dbname):
_logger.info("Dropping database {dbname}".format(**locals()))
_logger.info(f"Dropping database {dbname}")
self.pgcr.execute(
"""
f"""
DROP DATABASE "{dbname}"
""".format(
**locals()
)
"""
)

def _find_template(self, hashsum):
Expand All @@ -194,7 +183,7 @@ def _find_template(self, hashsum):
SELECT datname FROM pg_database
WHERE datname like %s
ORDER BY datname DESC -- MRU first
""",
""",
(pattern,),
)
r = self.pgcr.fetchone()
Expand Down
10 changes: 4 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,10 @@ def odoocfg(request, tmpdir):
odoo_cfg = tmpdir / "odoo.cfg"
odoo_cfg.write(
textwrap.dedent(
"""\
[options]
addons_path = {}
""".format(
",".join(addons_path)
)
f"""\
[options]
addons_path = {",".join(addons_path)}
"""
)
)
yield odoo_cfg
10 changes: 4 additions & 6 deletions tests/test_initdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,10 @@ def test_create_cmd_cache(dbcache, tmpdir):
odoo_cfg = tmpdir / "odoo.cfg"
odoo_cfg.write(
textwrap.dedent(
"""\
[options]
addons_path = {}
""".format(
ADDONS_PATH
)
f"""\
[options]
addons_path = {ADDONS_PATH}
"""
)
)
cmd = [
Expand Down