forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request brave#13781 from RyanJarv/fix/cibuild-draft-upload
Clean up upload/publish tools, add initial tests
- Loading branch information
Showing
13 changed files
with
361 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import os | ||
import json | ||
import traceback | ||
|
||
BROWSER_LAPTOP_REPO = 'brave/browser-laptop' | ||
TARGET_ARCH= os.environ['TARGET_ARCH'] if os.environ.has_key('TARGET_ARCH') else 'x64' | ||
|
||
def get_env(env): | ||
token = os.environ[env] | ||
message = ('Error: Please set the ${} environment variable, which is your personal token'.format(env)) | ||
assert token, message | ||
return token | ||
|
||
def release_channel(): | ||
channel = os.environ['CHANNEL'] | ||
message = ('Error: Please set the $CHANNEL ' | ||
'environment variable, which is your release channel') | ||
assert channel, message | ||
return channel | ||
|
||
def get_channel_display_name(): | ||
d = {'dev': 'Release', 'beta': 'Beta', 'developer': 'Developer', 'nightly': 'Nightly'} | ||
return d[release_channel()] | ||
|
||
def release_name(): | ||
return '{0} Channel'.format(get_channel_display_name()) | ||
|
||
def get_tag(): | ||
return 'v' + get_version() + release_channel() | ||
|
||
def get_tag_without_channel(): | ||
return 'v' + get_version() | ||
|
||
def get_version(): | ||
return json.load(open('package.json'))['version'] | ||
|
||
def get_releases_by_tag(repo, tag_name, include_drafts=False): | ||
if include_drafts: | ||
return [r for r in repo.releases.get() if r['tag_name'] == tag_name] | ||
else: | ||
return [r for r in repo.releases.get() if r['tag_name'] == tag_name and not r['draft']] | ||
|
||
def retry_func(try_func, catch, retries, catch_func=None): | ||
for count in range(0, retries + 1): | ||
try: | ||
ret = try_func(count) | ||
break | ||
except catch as e: | ||
print('[ERROR] Caught exception {}, {} retries left. {}'.format(catch, count, e.message)) | ||
if catch_func: | ||
catch_func(count) | ||
if count >= retries: | ||
raise e | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env python | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import unittest | ||
|
||
from test_helpers import * | ||
from test_publish import * | ||
from test_upload import * | ||
|
||
print unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/env python | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
class Repo(): | ||
def __init__(self): | ||
self.releases = self.Releases() | ||
|
||
class Releases(): | ||
def __init__(self): | ||
self._releases = [] | ||
def get(self): | ||
return self._releases |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env python | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import sys | ||
import unittest | ||
import os | ||
|
||
dirname = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(os.path.join(dirname, '..')) | ||
from lib.helpers import * | ||
|
||
class RetryFunc(): | ||
def __init__(self): | ||
self.ran = 0 | ||
self.calls = [] | ||
self.err = UserWarning | ||
|
||
def succeed(self, count): | ||
self.ran = self.ran + 1 | ||
self.calls.append(count) | ||
|
||
def fail(self, count): | ||
self.ran = self.ran + 1 | ||
self.calls.append(count) | ||
raise self.err | ||
|
||
class TestRetryFunc(unittest.TestCase): | ||
def setUp(self): | ||
self.retry_func = RetryFunc() | ||
self.catch_func = RetryFunc() | ||
|
||
def test_passes_retry_count(self): | ||
self.assertRaises( | ||
self.retry_func.err, | ||
retry_func, | ||
self.retry_func.fail, | ||
catch=UserWarning, retries=3 | ||
) | ||
self.assertEqual(self.retry_func.calls, [0, 1, 2, 3]) | ||
|
||
def test_retries_on_fail(self): | ||
self.assertRaises( | ||
self.retry_func.err, | ||
retry_func, | ||
self.retry_func.fail, | ||
catch=UserWarning, retries=3 | ||
) | ||
self.assertEqual(self.retry_func.ran, 4) | ||
|
||
def test_run_catch_func_on_fail(self): | ||
self.assertRaises( | ||
self.retry_func.err, | ||
retry_func, | ||
self.retry_func.fail, | ||
catch_func=self.catch_func.succeed, | ||
catch=UserWarning, retries=3 | ||
) | ||
self.assertEqual(self.catch_func.ran, 4) | ||
|
||
def test_no_retry_on_success(self): | ||
retry_func( | ||
self.retry_func.succeed, | ||
catch=UserWarning, retries=3 | ||
) | ||
self.assertEqual(self.retry_func.ran, 1) | ||
|
||
def test_no_run_catch_func_on_success(self): | ||
retry_func( | ||
self.retry_func.succeed, | ||
catch_func=self.catch_func.succeed, | ||
catch=UserWarning, retries=3 | ||
) | ||
self.assertEqual(self.catch_func.ran, 0) | ||
|
||
if __name__ == '__main__': | ||
print unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import sys | ||
import unittest | ||
import os | ||
|
||
dirname = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(os.path.join(dirname, '..')) | ||
|
||
import publish_release | ||
|
||
from mock import Repo | ||
|
||
class TestPublishGetDraft(unittest.TestCase): | ||
def setUp(self): | ||
self.repo = Repo() | ||
|
||
def test_fails_on_existing_release(self): | ||
self.repo.releases._releases = [{'tag_name': 'test', 'draft': False}] | ||
self.assertRaises(UserWarning, publish_release.get_draft, self.repo, 'test') | ||
|
||
def test_fails_on_no_draft(self): | ||
self.repo.releases._releases = [{'tag_name': 'old', 'draft': False}] | ||
self.assertRaises(UserWarning, publish_release.get_draft, self.repo, 'new') | ||
|
||
def test_succeeds_on_existing_draft(self): | ||
self.repo.releases._releases = [{'tag_name': 'test', 'draft': True}] | ||
publish_release.get_draft(self.repo, 'test') | ||
|
||
if __name__ == '__main__': | ||
print unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env python | ||
|
||
# This Source Code Form is subject to the terms of the Mozilla Public | ||
# License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
# You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import sys | ||
import unittest | ||
import os | ||
|
||
dirname = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.append(os.path.join(dirname, '..')) | ||
|
||
import upload | ||
|
||
from mock import Repo | ||
|
||
class TestGetDraft(unittest.TestCase): | ||
def setUp(self): | ||
self.repo = Repo() | ||
|
||
def test_returns_existing_draft(self): | ||
self.repo.releases._releases = [{'tag_name': 'test', 'draft': True}] | ||
self.assertEquals(upload.get_draft(self.repo, 'test')['tag_name'], 'test') | ||
|
||
def test_fails_on_existing_release(self): | ||
self.repo.releases._releases = [{'tag_name': 'test', 'draft': False}] | ||
self.assertRaises(UserWarning, upload.get_draft, self.repo, 'test') | ||
|
||
def test_returns_none_on_new_draft(self): | ||
self.repo.releases._releases = [{'tag_name': 'old', 'draft': False}] | ||
upload.get_draft(self.repo, 'new') | ||
self.assertEquals(upload.get_draft(self.repo, 'test'), None) | ||
|
||
if __name__ == '__main__': | ||
print unittest.main() |
Oops, something went wrong.