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

Project template: various improvements #77

Merged
merged 13 commits into from
Apr 28, 2021
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ exclude =
./src
./venv*
.eggs/
./acsoo/templates/**
32 changes: 14 additions & 18 deletions acsoo/templates/project/+project.name+/.gitlab-ci.yml.bob
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ before_script:
venv-acsoo/bin/pip install acsoo
ln -s venv-acsoo/bin/acsoo
}
function install_pre_commit {
virtualenv --python=$PYTHON venv-pre-commit
venv-pre-commit/bin/pip install pre-commit
ln -s venv-pre-commit/bin/pre-commit
}
function start_ssh_agent {
eval $(ssh-agent -s)
ssh-add <(echo "$SSH_DEPLOY_KEY")
Expand All @@ -26,29 +21,22 @@ before_script:
git push --push-option ci.skip "[email protected]:${CI_PROJECT_PATH}" "HEAD:${CI_COMMIT_REF_NAME}"
}

after_script:
# important to cleanup after ourselves to avoid
# leaving ssh agents running on the shell executor
- if [ -f ssh-agent.pid ] ; then kill $(cat ssh-agent.pid) ; fi
- dropdb --if-exists ${DB_NAME}
- rm -fr ${HOME}/.local/share/Odoo/filestore/${DB_NAME}

variables:
PYTHON: {{{ python_version }}}
DB_NAME: "${CI_PROJECT_NAME}-${CI_JOB_ID}"

pre-commit:
stage: test
tags:
- python
image: {{{ python_version }}}
cache:
key: pre-commit
paths:
- .pre-commit
script:
- install_pre_commit
- PRE_COMMIT_HOME=$PWD/.pre-commit ./pre-commit run --all-files
- pip install pre-commit
- PRE_COMMIT_HOME=$PWD/.pre-commit pre-commit run --all-files
needs: []
interruptible: true

build:
stage: build
Expand All @@ -65,6 +53,7 @@ build:
paths:
- release/
name: "${CI_PROJECT_NAME}-${CI_JOB_ID}-build"
interruptible: true

{{% if odoo.series in ['8.0', '9.0'] %}}
{{% set odoocmd = 'openerp-server' %}}
Expand All @@ -73,6 +62,7 @@ build:
{{% endif %}}
test:
stage: test
image: quay.io/acsone/odoo-ci:v20210312.0
tags:
- odoo-{{{ odoo.series }}}
script:
Expand Down Expand Up @@ -100,9 +90,13 @@ test:
name: "${CI_PROJECT_NAME}-${CI_JOB_ID}-coverage-html"
dependencies:
- build
interruptible: true
after_script:
- dropdb --if-exists ${DB_NAME}

deploy-test:
stage: deploy
image: quay.io/acsone/deploy-tools
script:
- start_ssh_agent
- ./deploy-test
Expand All @@ -111,5 +105,7 @@ deploy-test:
url: https://odoo-{{{ project.name }}}-test.acsone.eu
only:
- /^\d+\.\d+\.\d+$/
dependencies:
- build
when: manual
needs:
- job: build
artifacts: true
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ repos:
name: pylint
files: odoo/addons/
args: []
additional_dependencies: [pylint-odoo==3.5.0]
additional_dependencies: [pylint-odoo==3.7.1]
- repo: https://github.com/asottile/pyupgrade
rev: v2.7.4
hooks:
Expand Down
2 changes: 1 addition & 1 deletion acsoo/templates/project/+project.name+/README.rst.bob
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Initialize virtualenv
Install everything
------------------

In an activated python 3.6 virtualenv, run::
In an activated {{{ python_version }}} virtualenv, run::

pip-df sync

Expand Down
70 changes: 41 additions & 29 deletions acsoo/templates/project/+project.name+/deploy-test.bob
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
#!/usr/bin/env {{{ python_version }}}
#!/usr/bin/env python3
import subprocess
import textwrap
from {{{ 'configparser' if python_version == 'python3' else 'ConfigParser' }}} import ConfigParser
from configparser import ConfigParser

config = ConfigParser()
config.read('acsoo.cfg')
config.read("acsoo.cfg")

VERSION = config.get('acsoo', 'version')
HOST = 'odoo-{{{ project.name }}}.acsone.eu'
USER = 'odoo-{{{ project.name }}}-test'
VERSION = config.get("acsoo", "version")
HOST = "odoo-{{{ project.name }}}.acsone.eu"
USER = "odoo-{{{ project.name }}}-test"

subprocess.check_call([
'rsync', '--verbose', '--recursive', '--times', '--delete',
'--rsync-path', 'sudo -u {USER} rsync'.format(**locals()),
'release/',
'{HOST}:/home/{USER}/instance/release/'.format(**locals()),
])
subprocess.check_call([
'ssh', HOST,
textwrap.dedent("""\
sudo -u {USER} -H -s <<'EOF'
set -ex -o pipefail
cd /home/{USER}/instance
./installvenv {VERSION}
./maintenance_start
rm -f venv
ln -s venv-{VERSION} venv
for db in $(cat DATABASES) ; do
venv/bin/click-odoo-update -c odoo.cfg -d $db --i18n-overwrite 2>&1 | tee upgrade-logs/upgrade-{VERSION}-$db.log
done
./maintenance_stop
EOF
""".format(**locals())),
])
subprocess.check_call(
[
"rsync",
"--verbose",
"--recursive",
"--times",
"--delete",
"--rsync-path",
f"sudo -u {USER} rsync",
"release/",
f"gitlab-runner@{HOST}:/home/{USER}/instance/release/",
]
)
subprocess.check_call(
[
"ssh",
f"gitlab-runner@{HOST}",
textwrap.dedent(
f"""\
sudo -u {USER} -H -s <<'EOF'
set -ex -o pipefail
cd /home/{USER}/instance
./installvenv {VERSION}
./maintenance_start
rm -f venv
ln -s venv-{VERSION} venv
for db in $(cat DATABASES) ; do
venv/bin/click-odoo-update -c odoo.cfg -d $db --i18n-overwrite 2>&1 | tee upgrade-logs/upgrade-{VERSION}-$db.log
done
./maintenance_stop
EOF
"""
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Copyright 2020 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': "{{{ project.name }}}",
'name': "{{{ project.name|capitalize }}}",
'description': """
Odoo aplication for {{{ project.name }}}""",
'author': 'ACSONE SA/NV',
Expand All @@ -14,13 +14,10 @@
# {{{ project.name }}} open source addons
# !!! no odoo enterprise addons dependencies !!!
# OCA/server-tools
'base_optional_quick_create',
'mail_environment',
'server_environment_ir_config_parameter',
# OCA/web
'web_dialog_size',
'web_environment_ribbon',
'web_sheet_full_width',
],
'data': [
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
[outgoing_mail]
smtp_host=localhost
smtp_port=1025

[ir.config_parameter]
ribbon.name=TEST 1.0.0<br/>({db_name})
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
--find-links https://wheelhouse.acsone.eu/manylinux1
#--find-links https://wheelhouse.acsone.eu/acsone-odoo
#--extra-index-url https://wheelhouse.odoo-community.org/oca-simple
4 changes: 2 additions & 2 deletions acsoo/templates/project/+project.name+/setup.py.bob
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from {{{ 'configparser' if python_version == 'python3' else 'ConfigParser' }}} import ConfigParser
from configparser import ConfigParser
from setuptools import setup


Expand All @@ -14,7 +14,7 @@ setup(
install_requires=[
'click-odoo-contrib>=1.4.1',
'xlrd',
{{% if odoo.enterprise }}'odoo-addons-enterprise',{{% endif -%}}
{{% if odoo.enterprise %}}'odoo-addons-enterprise',{{% endif -%}}
],
odoo_addons=True,
)
2 changes: 2 additions & 0 deletions tests/test_pr_status.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import textwrap

import pytest
import respx
from click.testing import CliRunner

from acsoo.pr_status import pr_status


@pytest.mark.xfail()
@respx.mock
def test_pr_status_basic():
req1 = respx.get(
Expand Down