Skip to content

Commit 7272b4b

Browse files
authored
chore: migrate to new templates repo (#8)
Templates are now in mono repo: https://github.com/NativeScript/nativescript-app-templates
1 parent 219f078 commit 7272b4b

File tree

12 files changed

+59
-52
lines changed

12 files changed

+59
-52
lines changed

core/enums/env.py

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
class EnvironmentType(IntEnum):
88
_init_ = 'value string'
99

10+
PR = 0, 'pr'
1011
NEXT = 1, 'next'
1112
RC = 2, 'rc'
1213
LIVE = 3, 'latest'

core/settings/Settings.py

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def get_env():
2828
return EnvironmentType.NEXT
2929
elif 'rc' in env:
3030
return EnvironmentType.RC
31+
elif 'pr' in env:
32+
return EnvironmentType.LIVE
3133
else:
3234
return EnvironmentType.LIVE
3335

core/utils/git.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
A wrapper around GitHub commands.
33
"""
4+
from core.log.log import Log
45
from core.settings import Settings
56
from core.utils.file_utils import Folder
67
from core.utils.run import run
@@ -17,18 +18,17 @@ def get_repo_url(repo_url, ssh_clone=False):
1718

1819
class Git(object):
1920
@staticmethod
20-
def clone(repo_url, local_folder, branch=None):
21-
"""Clone GitHub repo to local folder
21+
def clone(repo_url, local_folder, branch='master'):
22+
"""Clone GitHub repo to local folder.
2223
:param repo_url: HTTPs url of the repo.
23-
:param branch: Branch
24+
:param branch: Branch.
2425
:param local_folder: Local folder to clone the repo.
2526
"""
2627
if Folder.exists(folder=local_folder):
2728
Folder.clean(folder=local_folder)
2829
repo_url = get_repo_url(repo_url=repo_url, ssh_clone=Settings.SSH_CLONE)
29-
command = 'git clone {0} "{1}"'.format(repo_url, str(local_folder))
30-
if branch is not None:
31-
command = command + ' -b ' + branch
30+
command = 'git clone --depth 1 {0} -b {1} "{2}"'.format(repo_url, branch, str(local_folder))
31+
Log.info(command)
3232
result = run(cmd=command)
3333
assert "fatal" not in result.output, "Failed to clone: " + repo_url
3434
assert result.exit_code is 0, "Failed to clone: " + repo_url

core/utils/npm.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ class Npm(object):
1414
@staticmethod
1515
def __run_npm_command(cmd, folder=Settings.TEST_RUN_HOME, verify=True):
1616
command = 'npm {0}'.format(cmd)
17-
Log.info(command)
17+
Log.info(command + " (at " + folder + ").")
1818
result = run(cmd=command, cwd=folder, wait=True, timeout=300)
1919
if verify:
2020
assert result.exit_code is 0, '" + command + " exited with non zero exit code!: \n' + result.output
21-
Log.debug(result.output)
2221
return result.output.strip()
2322

2423
@staticmethod

data/templates.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import os
22

33
from core.enums.app_type import AppType
4-
from core.settings.Settings import NS_GIT_ORG, TEST_SUT_HOME
4+
from core.settings.Settings import TEST_SUT_HOME
55
from products.nativescript.template_info import TemplateInfo
66

77

88
def gen_template_info(name, app_type, texts=None):
9-
return TemplateInfo(name=name, repo='https://github.com/{0}/{1}'.format(NS_GIT_ORG, name),
10-
local_package=os.path.join(TEST_SUT_HOME, '{0}.tgz'.format(name)),
11-
app_type=app_type, texts=texts)
9+
return TemplateInfo(name=name, local_package=os.path.join(TEST_SUT_HOME, '{0}.tgz'.format(name)), app_type=app_type,
10+
texts=texts)
1211

1312

1413
class Template(object):
@@ -19,7 +18,9 @@ class Template(object):
1918
dr_str = ['Home']
2019
tn_str = ['Item 1']
2120
login = ['Login']
22-
auth = ['Your Company Name']
21+
22+
# Templates repo
23+
REPO = 'https://github.com/NativeScript/nativescript-app-templates'
2324

2425
# Blank templates
2526
BLANK_JS = gen_template_info(name='template-blank', app_type=AppType.JS)
@@ -54,11 +55,6 @@ class Template(object):
5455
TAB_NAVIGATION_TS = gen_template_info(name='template-tab-navigation-ts', app_type=AppType.TS, texts=tn_str)
5556
TAB_NAVIGATION_NG = gen_template_info(name='template-tab-navigation-ng', app_type=AppType.NG, texts=tn_str)
5657

57-
# Enterprise auth templates
58-
ENTERPRISE_AUTH_JS = gen_template_info(name='template-enterprise-auth', app_type=AppType.JS, texts=auth)
59-
ENTERPRISE_AUTH_TS = gen_template_info(name='template-enterprise-auth-ts', app_type=AppType.TS, texts=auth)
60-
ENTERPRISE_AUTH_NG = gen_template_info(name='template-enterprise-auth-ng', app_type=AppType.NG, texts=auth)
61-
6258
# Health templates
6359
HEALTH_SURVEY_NG = gen_template_info(name='template-health-survey-ng', app_type=AppType.NG, texts=login)
6460
PATIENT_CARE_NG = gen_template_info(name='template-patient-care-ng', app_type=AppType.NG, texts=login)
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
class TemplateInfo(object):
2-
def __init__(self, name=None, repo=None, local_package=None, app_type=None, texts=None):
2+
def __init__(self, name=None, local_package=None, app_type=None, texts=None):
33
self.name = name
4-
self.repo = repo
54
self.local_package = local_package
65
self.app_type = app_type
76
self.texts = texts

run_common.py

+15-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from core.enums.os_type import OSType
44
from core.log.log import Log
55
from core.settings import Settings
6+
from core.utils.ci.jenkins import Jenkins
67
from core.utils.device.adb import Adb
78
from core.utils.device.device_manager import DeviceManager
89
from core.utils.file_utils import File, Folder
@@ -37,17 +38,22 @@ def __get_templates():
3738
Clone hello-world templates and pack them as local npm packages.
3839
Hints: Creating project from local npm package is much faster than from GitHub repo.
3940
"""
40-
apps = [Template.HELLO_WORLD_JS, Template.HELLO_WORLD_TS, Template.HELLO_WORLD_NG]
41+
branch = 'master'
42+
if Jenkins.is_pr():
43+
branch = Jenkins.get_pr_info().source_branch
44+
local_folder = os.path.join(Settings.TEST_SUT_HOME, 'templates')
45+
Git.clone(repo_url=Template.REPO, branch=branch, local_folder=local_folder)
46+
47+
apps = [Template.HELLO_WORLD_JS, Template.HELLO_WORLD_TS, Template.HELLO_WORLD_NG, Template.MASTER_DETAIL_NG]
4148
for app in apps:
42-
template_name = app.repo.split('/')[-1]
43-
local_folder = os.path.join(Settings.TEST_SUT_HOME, template_name)
49+
template_name = app.name
50+
template_folder = os.path.join(local_folder, 'packages', template_name)
4451
out_file = os.path.join(Settings.TEST_SUT_HOME, template_name + '.tgz')
45-
Git.clone(repo_url=app.repo, local_folder=local_folder)
46-
Npm.pack(folder=local_folder, output_file=out_file)
52+
Npm.pack(folder=template_folder, output_file=out_file)
4753
if File.exists(out_file):
4854
app.path = out_file
4955
else:
50-
raise IOError("Failed to clone and pack template: " + app.repo)
56+
raise IOError("Failed to clone and pack template: " + template_name)
5157

5258

5359
def __get_packages():
@@ -127,15 +133,15 @@ def __install_schematics():
127133
Npm.install(package=Settings.Packages.NS_SCHEMATICS, folder=Settings.TEST_RUN_HOME)
128134

129135

130-
def prepare(shared=False):
136+
def prepare(clone_templates=True, install_ng_cli=False):
131137
Log.info('================== Prepare Test Run ==================')
132138
__cleanup()
133139
__get_packages()
134140
__install_ns_cli()
135-
if shared:
141+
if install_ng_cli:
136142
__install_ng_cli()
137143
__install_schematics()
138-
else:
144+
if clone_templates:
139145
__get_templates()
140146

141147
Log.settings()

run_ns.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from core.log.log import Log
77

88
if __name__ == '__main__':
9-
run_common.prepare()
9+
run_common.prepare(clone_templates=True, install_ng_cli=False)
1010
Log.info("Running tests...")
1111
arguments = ['nosetests', '-v', '-s', '--nologcapture', '--with-doctest', '--with-xunit']
1212
for i in sys.argv:

run_schematics.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from core.log.log import Log
77

88
if __name__ == '__main__':
9-
run_common.prepare(shared=True)
9+
run_common.prepare(clone_templates=False, install_ng_cli=True)
1010
Log.info("Running tests...")
1111
arguments = ['nosetests', '-v', '-s', '--nologcapture', '--logging-filter=nose', '--with-xunit', '--with-flaky']
1212
for i in sys.argv:
File renamed without changes.

tests/cli/run/templates/master_detail_ng_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def setUpClass(cls):
3030
cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
3131

3232
# Create app
33-
Tns.create(app_name=cls.app_name, template=Template.MASTER_DETAIL_NG.repo, update=True)
33+
Tns.create(app_name=cls.app_name, template=Template.MASTER_DETAIL_NG.local_package, update=True)
3434
Tns.platform_add_android(app_name=cls.app_name, framework_path=Settings.Android.FRAMEWORK_PATH)
3535
if Settings.HOST_OS is OSType.OSX:
3636
Tns.platform_add_ios(app_name=cls.app_name, framework_path=Settings.IOS.FRAMEWORK_PATH)

tests/live/template_tests.py renamed to tests/templates/template_tests.py

+24-20
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
from core.settings import Settings
99
from core.utils.device.adb import Adb
1010
from core.utils.device.device_manager import DeviceManager
11-
from core.utils.file_utils import Folder
11+
from core.utils.file_utils import Folder, File
1212
from core.utils.gradle import Gradle
13+
from core.utils.npm import Npm
1314
from data.const import Colors
1415
from data.templates import Template
1516
from products.nativescript.app import App
@@ -25,31 +26,28 @@ class TemplateTests(TnsTest):
2526
sim = None
2627

2728
test_data = [
28-
[Template.HELLO_WORLD_JS.name, Template.HELLO_WORLD_JS],
29-
[Template.HELLO_WORLD_TS.name, Template.HELLO_WORLD_TS],
30-
[Template.HELLO_WORLD_NG.name, Template.HELLO_WORLD_NG],
3129
[Template.BLANK_JS.name, Template.BLANK_JS],
3230
[Template.BLANK_TS.name, Template.BLANK_TS],
3331
[Template.BLANK_NG.name, Template.BLANK_NG],
32+
[Template.VUE_BLANK.name, Template.VUE_BLANK],
3433
[Template.DRAWER_NAVIGATION_JS.name, Template.DRAWER_NAVIGATION_JS],
3534
[Template.DRAWER_NAVIGATION_TS.name, Template.DRAWER_NAVIGATION_TS],
3635
[Template.DRAWER_NAVIGATION_NG.name, Template.DRAWER_NAVIGATION_NG],
37-
[Template.TAB_NAVIGATION_JS.name, Template.TAB_NAVIGATION_JS],
38-
[Template.TAB_NAVIGATION_TS.name, Template.TAB_NAVIGATION_TS],
39-
[Template.TAB_NAVIGATION_NG.name, Template.TAB_NAVIGATION_NG],
40-
[Template.MASTER_DETAIL_JS.name, Template.MASTER_DETAIL_JS],
41-
[Template.MASTER_DETAIL_TS.name, Template.MASTER_DETAIL_TS],
42-
[Template.MASTER_DETAIL_NG.name, Template.MASTER_DETAIL_NG],
36+
[Template.HEALTH_SURVEY_NG.name, Template.HEALTH_SURVEY_NG],
37+
[Template.HELLO_WORLD_JS.name, Template.HELLO_WORLD_JS],
38+
[Template.HELLO_WORLD_TS.name, Template.HELLO_WORLD_TS],
39+
[Template.HELLO_WORLD_NG.name, Template.HELLO_WORLD_NG],
4340
[Template.MASTER_DETAIL_KINVEY_JS.name, Template.MASTER_DETAIL_KINVEY_JS],
4441
[Template.MASTER_DETAIL_KINVEY_TS.name, Template.MASTER_DETAIL_KINVEY_TS],
4542
[Template.MASTER_DETAIL_KINVEY_NG.name, Template.MASTER_DETAIL_KINVEY_NG],
46-
[Template.ENTERPRISE_AUTH_JS.name, Template.ENTERPRISE_AUTH_JS],
47-
[Template.ENTERPRISE_AUTH_TS.name, Template.ENTERPRISE_AUTH_TS],
48-
[Template.ENTERPRISE_AUTH_NG.name, Template.ENTERPRISE_AUTH_NG],
49-
[Template.HEALTH_SURVEY_NG.name, Template.HEALTH_SURVEY_NG],
43+
[Template.MASTER_DETAIL_JS.name, Template.MASTER_DETAIL_JS],
44+
[Template.MASTER_DETAIL_TS.name, Template.MASTER_DETAIL_TS],
45+
[Template.MASTER_DETAIL_NG.name, Template.MASTER_DETAIL_NG],
46+
[Template.VUE_MASTER_DETAIL.name, Template.VUE_MASTER_DETAIL],
5047
[Template.PATIENT_CARE_NG.name, Template.PATIENT_CARE_NG],
51-
[Template.VUE_BLANK.name, Template.VUE_BLANK],
52-
[Template.VUE_MASTER_DETAIL.name, Template.VUE_MASTER_DETAIL]
48+
[Template.TAB_NAVIGATION_JS.name, Template.TAB_NAVIGATION_JS],
49+
[Template.TAB_NAVIGATION_TS.name, Template.TAB_NAVIGATION_TS],
50+
[Template.TAB_NAVIGATION_NG.name, Template.TAB_NAVIGATION_NG]
5351
]
5452

5553
@classmethod
@@ -71,11 +69,17 @@ def tearDownClass(cls):
7169

7270
@parameterized.expand(test_data)
7371
def test(self, template_name, template_info):
72+
# Ensure template local package
73+
template_folder = os.path.join(Settings.TEST_SUT_HOME, 'templates', 'packages', template_name)
74+
out_file = os.path.join(Settings.TEST_SUT_HOME, template_name + '.tgz')
75+
Npm.pack(folder=template_folder, output_file=out_file)
76+
assert File.exists(out_file), "Failed to pack template: " + template_name
77+
7478
# Create app
7579
app_name = template_info.name.replace('template-', '')
76-
local_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
77-
Tns.create(app_name=app_name, template=template_info.repo, update=False)
78-
if Settings.ENV != EnvironmentType.LIVE:
80+
app_path = os.path.join(Settings.TEST_RUN_HOME, app_name)
81+
Tns.create(app_name=app_name, template=template_info.local_package, update=False)
82+
if Settings.ENV != EnvironmentType.LIVE and Settings.ENV != EnvironmentType.PR:
7983
App.update(app_name=app_name)
8084

8185
# Run Android
@@ -99,4 +103,4 @@ def test(self, template_name, template_info):
99103
# Cleanup
100104
Tns.kill()
101105
Gradle.kill()
102-
Folder.clean(local_path)
106+
Folder.clean(app_path)

0 commit comments

Comments
 (0)