Skip to content

Commit

Permalink
Merge pull request #152 from Graur/141
Browse files Browse the repository at this point in the history
added test from auto pull script
  • Loading branch information
yegor256 authored Jun 28, 2023
2 parents 4bfbf7e + 212fede commit 5b7c86d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/make.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,8 @@ jobs:
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- run: gem install pdd
- run: make
10 changes: 5 additions & 5 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ jobs:
- name: checkout code
uses: actions/checkout@v3
- name: install dependencies
run: |
sudo apt-get update
sudo apt-get install -y python3 python3-pip
pip3 install requests
- uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: install ruby
uses: ruby/setup-ruby@v1
with:
Expand All @@ -23,14 +22,15 @@ jobs:
run: gem install pdd
- name: pull releases
run: |
python3 auto-pull.py
python3 /py/auto_pull.py
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v5
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
# passphrase: ${{ secrets.PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true
git_push_gpgsign: ""
- name: create pull request
uses: peter-evans/create-pull-request@v5
with:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
all:
make -C make
pdd --format xml . | grep -v 'puzzle '
python3 tests/py/deps_tests.py

clean:
make -C make clean
38 changes: 0 additions & 38 deletions auto-pull.py

This file was deleted.

31 changes: 31 additions & 0 deletions py/auto_pull.py
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())
22 changes: 22 additions & 0 deletions py/deps.py
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
26 changes: 26 additions & 0 deletions tests/py/deps_tests.py
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()

0 comments on commit 5b7c86d

Please sign in to comment.