-
Notifications
You must be signed in to change notification settings - Fork 9
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 #152 from Graur/141
added test from auto pull script
- Loading branch information
Showing
7 changed files
with
88 additions
and
43 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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
import os | ||
import requests | ||
from deps import dependencies | ||
|
||
|
||
def pull_release(unique_deps): | ||
for dep in unique_deps: | ||
name, version = dep.split(":") | ||
print(f"{name} - {version}") | ||
url = f'https://api.github.com/repos/objectionary/{name}/releases/latest' | ||
response = requests.get(url) | ||
response.raise_for_status() | ||
latest_version = response.json()['tag_name'] | ||
if compare(latest_version, version) > version: | ||
os.system(f'./pull.sh objectionary/{name}') | ||
env_file = os.getenv('GITHUB_ENV') | ||
eo_lib_version = f'{name}_{latest_version}' | ||
with open(env_file, "a") as myfile: | ||
myfile.write(f'eo_lib_version={eo_lib_version}') | ||
print(f'Added to env: {eo_lib_version}') | ||
break | ||
|
||
def compare(latest_version, old_version): | ||
latest = latest_version.split(".") | ||
old = old_version.split(".") | ||
for i in range(len(latest)): | ||
if int(latest[i]) > int(old[i]): | ||
return True | ||
return False | ||
|
||
pull_release(dependencies()) |
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,22 @@ | ||
import os | ||
import re | ||
|
||
|
||
def dependencies(): | ||
directory = "objects/org/eolang" | ||
unique_deps = set() | ||
for subdir, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith(".eo"): | ||
with open(os.path.join(subdir, file), "r") as f: | ||
content = f.read() | ||
matches = re.findall(r"\+rt jvm org.eolang:(.*?)\n", content) | ||
for match in matches: | ||
lst = match.split(":") | ||
if len(lst) > 2: | ||
match = f'{lst[0]}:{lst[2]}' | ||
if "eo-runtime" in match: | ||
match = f'eo:{lst[1]}' | ||
unique_deps.add(match) | ||
print(f'List of current dependencies: {unique_deps}') | ||
return unique_deps |
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,26 @@ | ||
import unittest | ||
from unittest.mock import patch | ||
import sys | ||
sys.path.insert(0, './py/') | ||
from deps import dependencies | ||
|
||
class AutoPullTest(unittest.TestCase): | ||
mock_file_content = """ | ||
+rt jvm org.eolang:eo-runtime:0.29.5 | ||
""" | ||
|
||
@unittest.mock.patch( | ||
'builtins.open', | ||
new=unittest.mock.mock_open(read_data=mock_file_content), | ||
create=True | ||
) | ||
def test(self): | ||
self.assertEqual( | ||
dependencies(), | ||
{'eo:0.29.5'} | ||
) | ||
print(dependencies()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |