Skip to content

Commit 11a9eb0

Browse files
authored
Introduce github-actions (push & pull_requests) (kivy#2025)
* [actions] Add push workflow (linting) * [actions] Fix `expected compiler` for tests Because the compiler path depends on the platform where the tests are run. * [actions] Mock environ variables for `test_create_no_sdk_dir` * [actions] Fix `test_toolchain.test_create` for macos * [actions] Fix venv/virtualenv tests * [actions] Add build stage: pull docker image & build an testapp * [actions] Make flake8 tests via tox * [actions] Run pytest via tox We also remove the env var `COVERALLS_REPO_TOKEN`, so we test if coveralls is working with `gh-actions` Note: Since Python 2 it's almost at the end of his life we only perform the Python3 tests, but we still have the travis tests for Python 2 * [actions] Reintroduce `COVERALLS_REPO_TOKEN` * [actions] Make tox tests via Makefile The coveralls report will only be send with our travis tests, since the `CI` environment variable it will only exist for travis. * [actions] Add `rebuild updated recipes` test * [actions] Shorten long line below 79 characters for libtorrent The purpose of this commit is to test the rebuild updated recipes behaviour with a long time consuming recipe * [actions] Revert "[actions] Shorten long line ..." This reverts commit c6c3ea8, to keep travis happy
1 parent e2851d9 commit 11a9eb0

File tree

8 files changed

+105
-16
lines changed

8 files changed

+105
-16
lines changed

.github/workflows/push.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Unit tests & Build Testapp
2+
3+
on: ['push', 'pull_request']
4+
5+
jobs:
6+
7+
flake8:
8+
name: Flake8 tests
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout python-for-android
12+
uses: actions/checkout@master
13+
- name: Set up Python 3.7
14+
uses: actions/setup-python@v1.1.0
15+
with:
16+
python-version: 3.7
17+
- name: Run flake8
18+
run: |
19+
python -m pip install --upgrade pip
20+
pip install tox>=2.0
21+
tox -e pep8
22+
23+
test:
24+
name: Pytest [Python ${{ matrix.python-version }} | ${{ matrix.os }}]
25+
needs: flake8
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
matrix:
29+
python-version: [3.6, 3.7]
30+
os: [ubuntu-latest, macOs-latest]
31+
steps:
32+
- name: Checkout python-for-android
33+
uses: actions/checkout@master
34+
- name: Set up Python ${{ matrix.python-version }}
35+
uses: actions/setup-python@v1.1.0
36+
with:
37+
python-version: ${{ matrix.python-version }}
38+
- name: Tox tests
39+
run: |
40+
python -m pip install --upgrade pip
41+
pip install tox>=2.0
42+
make test
43+
44+
build:
45+
name: Build testapp
46+
needs: [flake8]
47+
runs-on: ubuntu-latest
48+
steps:
49+
- name: Checkout python-for-android
50+
uses: actions/checkout@master
51+
- name: Pull docker image
52+
run: |
53+
make docker/pull
54+
- name: Build apk for Python 3 arm64-v8a
55+
run: |
56+
make docker/run/make/testapps/python3/arm64-v8a
57+
58+
rebuild_updated_recipes:
59+
name: Test updated recipes
60+
needs: [flake8]
61+
runs-on: ubuntu-latest
62+
steps:
63+
- name: Checkout python-for-android
64+
uses: actions/checkout@master
65+
- name: Pull docker image
66+
run: |
67+
make docker/pull
68+
- name: Rebuild updated recipes
69+
run: |
70+
make docker/run/make/rebuild_updated_recipes

tests/recipes/recipe_lib_test.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from unittest import mock
2+
from platform import system
23
from tests.recipes.recipe_ctx import RecipeCtx
34

45

@@ -13,7 +14,7 @@ class BaseTestForMakeRecipe(RecipeCtx):
1314

1415
recipe_name = None
1516
expected_compiler = (
16-
"{android_ndk}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang"
17+
"{android_ndk}/toolchains/llvm/prebuilt/{system}-x86_64/bin/clang"
1718
)
1819

1920
sh_command_calls = ["./configure"]
@@ -48,7 +49,7 @@ def test_get_recipe_env(
4849
some internal methods has been called.
4950
"""
5051
mock_find_executable.return_value = self.expected_compiler.format(
51-
android_ndk=self.ctx._ndk_dir
52+
android_ndk=self.ctx._ndk_dir, system=system().lower()
5253
)
5354
mock_glob.return_value = ["llvm"]
5455
mock_check_recipe_choices.return_value = sorted(
@@ -85,7 +86,7 @@ def test_build_arch(
8586
mock_current_directory,
8687
):
8788
mock_find_executable.return_value = self.expected_compiler.format(
88-
android_ndk=self.ctx._ndk_dir
89+
android_ndk=self.ctx._ndk_dir, system=system().lower()
8990
)
9091
mock_glob.return_value = ["llvm"]
9192

@@ -133,7 +134,7 @@ def test_build_arch(
133134
mock_current_directory,
134135
):
135136
mock_find_executable.return_value = self.expected_compiler.format(
136-
android_ndk=self.ctx._ndk_dir
137+
android_ndk=self.ctx._ndk_dir, system=system().lower()
137138
)
138139
mock_glob.return_value = ["llvm"]
139140

tests/recipes/test_icu.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import unittest
33
from unittest import mock
4+
from platform import system
45

56
from tests.recipes.recipe_ctx import RecipeCtx
67
from pythonforandroid.recipes.icu import ICURecipe
@@ -47,7 +48,7 @@ def test_build_arch(
4748
):
4849
mock_find_executable.return_value = os.path.join(
4950
self.ctx._ndk_dir,
50-
"toolchains/llvm/prebuilt/linux-x86_64/bin/clang",
51+
f"toolchains/llvm/prebuilt/{system().lower()}-x86_64/bin/clang",
5152
)
5253
mock_archs_glob.return_value = [
5354
os.path.join(self.ctx._ndk_dir, "toolchains", "llvm")

tests/test_archs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import unittest
33
from os import environ
44
from unittest import mock
5+
from platform import system
56

67
from pythonforandroid.bootstrap import Bootstrap
78
from pythonforandroid.distribution import Distribution
@@ -70,8 +71,8 @@ def setUp(self):
7071
# Here we define the expected compiler, which, as per ndk >= r19,
7172
# should be the same for all the tests (no more gcc compiler)
7273
self.expected_compiler = (
73-
"/opt/android/android-ndk/toolchains/"
74-
"llvm/prebuilt/linux-x86_64/bin/clang"
74+
f"/opt/android/android-ndk/toolchains/"
75+
f"llvm/prebuilt/{system().lower()}-x86_64/bin/clang"
7576
)
7677

7778

tests/test_bootstrap.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import unittest
55

66
from unittest import mock
7+
from platform import system
8+
79
from pythonforandroid.bootstrap import (
810
_cmp_bootstraps_by_priority, Bootstrap, expand_dependencies,
911
)
@@ -546,7 +548,7 @@ def test_bootstrap_strip(
546548
):
547549
mock_find_executable.return_value = os.path.join(
548550
self.ctx._ndk_dir,
549-
"toolchains/llvm/prebuilt/linux-x86_64/bin/clang",
551+
f"toolchains/llvm/prebuilt/{system().lower()}-x86_64/bin/clang",
550552
)
551553
mock_glob.return_value = [
552554
os.path.join(self.ctx._ndk_dir, "toolchains", "llvm")

tests/test_pythonpackage_basic.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,9 @@ def test_virtualenv(self):
308308
sys_python_path = self.run__get_system_python_executable(
309309
os.path.join(test_dir, "virtualenv", "bin", "python")
310310
)
311-
assert os.path.normpath(sys_python_path) == os.path.normpath(pybin)
311+
assert os.path.normpath(sys_python_path).startswith(
312+
os.path.normpath(pybin)
313+
)
312314
finally:
313315
shutil.rmtree(test_dir)
314316

@@ -341,6 +343,8 @@ def test_venv(self):
341343
sys_python_path = self.run__get_system_python_executable(
342344
os.path.join(test_dir, "venv", "bin", "python")
343345
)
344-
assert os.path.normpath(sys_python_path) == os.path.normpath(pybin)
346+
assert os.path.normpath(sys_python_path).startswith(
347+
os.path.normpath(pybin)
348+
)
345349
finally:
346350
shutil.rmtree(test_dir)

tests/test_recipe.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import warnings
66
from unittest import mock
77
from backports import tempfile
8+
from platform import system
9+
810
from pythonforandroid.build import Context
911
from pythonforandroid.recipe import Recipe, import_recipe
1012
from pythonforandroid.archs import ArchAarch_64
@@ -278,8 +280,8 @@ def test_get_recipe_env_with(
278280
should be tested in the proper test.
279281
"""
280282
expected_compiler = (
281-
"/opt/android/android-ndk/toolchains/"
282-
"llvm/prebuilt/linux-x86_64/bin/clang"
283+
f"/opt/android/android-ndk/toolchains/"
284+
f"llvm/prebuilt/{system().lower()}-x86_64/bin/clang"
283285
)
284286
mock_find_executable.return_value = expected_compiler
285287
mock_glob.return_value = ["llvm"]

tests/test_toolchain.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,14 @@ def test_create(self):
7878
m_get_ndk_platform_dir.return_value = (
7979
'/tmp/android-ndk/platforms/android-21/arch-arm', True)
8080
ToolchainCL()
81-
assert m_get_available_apis.call_args_list == [
82-
mock.call('/tmp/android-sdk')]
83-
assert m_get_toolchain_versions.call_args_list == [
84-
mock.call('/tmp/android-ndk', mock.ANY)]
81+
assert m_get_available_apis.call_args_list in [
82+
[mock.call('/tmp/android-sdk')], # linux case
83+
[mock.call('/private/tmp/android-sdk')] # macos case
84+
]
85+
assert m_get_toolchain_versions.call_args_list in [
86+
[mock.call('/tmp/android-ndk', mock.ANY)], # linux case
87+
[mock.call('/private/tmp/android-ndk', mock.ANY)], # macos case
88+
]
8589
build_order = [
8690
'hostpython3', 'libffi', 'openssl', 'sqlite3', 'python3',
8791
'genericndkbuild', 'setuptools', 'six', 'pyjnius', 'android',
@@ -100,6 +104,10 @@ def test_create(self):
100104
]
101105
assert m_run_distribute.call_args_list == [mock.call()]
102106

107+
@mock.patch(
108+
'pythonforandroid.build.environ',
109+
# Make sure that no environ variable modifies `sdk_dir`
110+
{'ANDROIDSDK': None, 'ANDROID_HOME': None})
103111
def test_create_no_sdk_dir(self):
104112
"""
105113
The `--sdk-dir` is mandatory to `create` a distribution.

0 commit comments

Comments
 (0)