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

Ci and tests #36

Merged
merged 6 commits into from
Oct 27, 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
2 changes: 2 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bumpversion]
current_version = 0.15.1
82 changes: 82 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: BUMP Version
on:
push:
# For copy pase proposes, change this variable
branches: [ master ]

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

env:
# For copy pase proposes, change this variable
VERSION_FILE: setup.py
HOME: /home/ci_repos
SCRIPTS_PATH: /home/ci_repos/ci_scripts
USER: ci_repos

permissions:
actions: write
checks: write
contents: write
deployments: write
issues: write
pull-requests: write
statuses: read

jobs:
bump-version:
runs-on: [self-hosted, Keroberos]
if: ${{ !startsWith(github.event.head_commit.message, 'Bump to v') }}
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.PUB_MASTER_PUSH_TOKEN }}
- name: Update python packages
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate bump
pip install --upgrade bump2version
pip install --upgrade giscemultitools

- name: Get PR info
env:
GITHUB_TOKEN: ${{ secrets.RO_GH_ACTIONS_TOKEN }}
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate bump
echo 'PR_INFO<<EOF' >> $GITHUB_ENV
gisce_github get-commits-sha-from-merge-commit --owner ${{ github.repository_owner }} --repository ${{ github.event.repository.name }} --sha ${{ github.sha }} >> $GITHUB_ENV
echo 'EOF' >> $GITHUB_ENV

- name: Bump Version
run: |
. $SCRIPTS_PATH/load_pyenv.sh
pyenv activate bump
pr_labels=$( echo '${{ env.PR_INFO }}' | jq -r '.pullRequest.labels' )
is_minor=false
is_major=false
is_patch=false
for label in echo $( echo $pr_labels | jq -r '.[].name' ); do
if [[ $label == 'minor' ]]; then
is_minor=true
elif [[ $label == 'major' ]]; then
is_major=true
elif [[ $label == 'patch' ]]; then
is_patch=true
fi
done
VERSION_TYPE=false
if [[ $is_major == true ]]; then
VERSION_TYPE="major"
elif [[ $is_minor == true ]]; then
VERSION_TYPE="minor"
elif [[ $is_patch == true ]]; then
VERSION_TYPE="patch"
fi
if [[ $VERSION_TYPE != false ]]; then
git config user.name Release Bot
git config user.email [email protected]
bump2version $VERSION_TYPE --tag --commit -m "Bump to v{new_version}" $VERSION_FILE
git push origin master --tags
fi
49 changes: 49 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: OOPGRADE/Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
run-tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
# You can use PyPy versions in python-version.
# For example, pypy2 and pypy3
matrix:
python-version: ["2.7", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
if: matrix.python-version != '2.7'
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install Python 2
if: matrix.python-version == '2.7'
run: |
sudo apt update
sudo apt install python2 python-pip
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
printf '1\n' | sudo update-alternatives --config python
cd /usr/bin
sudo ln -s /usr/bin/pip2 ./pip

- name: Upgrade pip
run: |
pip install --upgrade pip setuptools wheel

- name: Install dependencies
run: |
pip install -r requirements-dev.txt
pip install -e .

- name: Run test
run: |
mamba
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mamba<0.11
mamba<0.11.0;python_version<="2.7.18"
mamba;python_version>"2.7.18"
expects
mock
25 changes: 16 additions & 9 deletions spec/data_migration_spec.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
from .fixtures import get_fixture
from expects import *
import six
if six.PY2:
Expand All @@ -10,11 +9,19 @@
from oopgrade import DataMigration
from oopgrade.data import DataRecord
from oopgrade.oopgrade import add_columns
import os


_ROOT = os.path.abspath(os.path.dirname(__file__))


def get_fixture(*args):
return os.path.join(_ROOT, *args)


with description('Migrating _data.xml'):
with before.all:
with open(get_fixture('migration_data.xml'), 'rb') as f:
with open(get_fixture('fixtures/migration_data.xml'), 'rb') as f:
self.xml = f.read()

with it('must parse xml files with records'):
Expand Down Expand Up @@ -90,7 +97,7 @@
with it('must raise a KeyError exception'):

def callback():
xml = """<?xml version="1.0" encoding="UTF-8" ?>
xml = b"""<?xml version="1.0" encoding="UTF-8" ?>
<openerp>
<data>
<record id="record_id_0001" model="test.search.model">
Expand Down Expand Up @@ -148,18 +155,18 @@ def callback():
dm.migrate()
expected_sql = [
call('SELECT "a"."id" AS "id" FROM "test_model" AS "a" WHERE (("a"."name" = %s) AND ("a"."description" = %s))', ('name', 'this is a description')),
call('INSERT INTO "test_model" ("name", "description") VALUES (%s, %s) RETURNING "test_model"."id"', ('name', 'this is a description')),
call('INSERT INTO "ir_model_data" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0001', 'test.model', 0, 1, 'module')),
call('INSERT INTO "test_model" AS "a" ("name", "description") VALUES (%s, %s) RETURNING "a"."id"', ('name', 'this is a description')),
call('INSERT INTO "ir_model_data" AS "a" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0001', 'test.model', False, 1, 'module')),
call('SELECT "a"."res_id" FROM "ir_model_data" AS "a" WHERE (("a"."module" = %s) AND ("a"."name" = %s))', ('other_module', 'xml_id')),
call('SELECT "a"."id" AS "id" FROM "res_partner" AS "a" WHERE (("a"."ref" = %s))', ('123',)),
call('SELECT "a"."id" AS "id" FROM "test_search_model" AS "a" WHERE (("a"."code" = %s))', ('code',)),
call('INSERT INTO "ir_model_data" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0003', 'test.search.model', 0, 3, 'module')),
call('INSERT INTO "ir_model_data" AS "a" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0003', 'test.search.model', False, 3, 'module')),
call('SELECT "a"."id" AS "id" FROM "test_model" AS "a" WHERE (("a"."name" = %s) AND ("a"."description" = %s))', ('name 2', 'this is a description 2')),
call('INSERT INTO "ir_model_data" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0002', 'test.model', 1, 2, 'module')),
call('INSERT INTO "ir_model_data" AS "a" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0002', 'test.model', True, 2, 'module')),
call('SELECT "a"."res_id" FROM "ir_model_data" AS "a" WHERE (("a"."module" = %s) AND ("a"."name" = %s))', ('module', 'record_id_0002')),
call('SELECT "a"."id" AS "id" FROM "test_other_model" AS "a" WHERE (("a"."code" = %s) AND ("a"."test_model_id" = %s))', ('1', 2)),
call('INSERT INTO "test_other_model" ("code", "test_model_id") VALUES (%s, %s) RETURNING "test_other_model"."id"', ('1', 2)),
call('INSERT INTO "ir_model_data" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0004', 'test.other.model', 0, 4, 'module'))
call('INSERT INTO "test_other_model" AS "a" ("code", "test_model_id") VALUES (%s, %s) RETURNING "a"."id"', ('1', 2)),
call('INSERT INTO "ir_model_data" AS "a" ("name", "model", "noupdate", "res_id", "module") VALUES (%s, %s, %s, %s, %s)', ('record_id_0004', 'test.other.model', False, 4, 'module'))
]
expect(cursor.execute.call_args_list).to(contain_exactly(
*expected_sql
Expand Down
Loading