aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/aur-check-update.yml2
-rwxr-xr-xutils/aur/check-aur-update.py39
2 files changed, 37 insertions, 4 deletions
diff --git a/.github/workflows/aur-check-update.yml b/.github/workflows/aur-check-update.yml
index adf7c63..54849bc 100644
--- a/.github/workflows/aur-check-update.yml
+++ b/.github/workflows/aur-check-update.yml
@@ -33,7 +33,7 @@ jobs:
shell: bash
run: |
sed -i -e '/as root is not allowed/i \ \ \ \ \ \ \ \ true' -e '/as root is not allowed/,+2d' /usr/bin/makepkg
- ./utils/aur/check-aur-update.py --parse-pkgbuild ./utils/parse-pkgbuild.sh repo
+ ./utils/aur/check-aur-update.py --check-deps --parse-pkgbuild ./utils/parse-pkgbuild.sh repo
- name: Push changes
id: get_env
shell: bash
diff --git a/utils/aur/check-aur-update.py b/utils/aur/check-aur-update.py
index d2e1b78..d1240be 100755
--- a/utils/aur/check-aur-update.py
+++ b/utils/aur/check-aur-update.py
@@ -2,6 +2,7 @@
import asyncio
import argparse
+import heapq
import logging
from collections.abc import Coroutine
from pathlib import Path
@@ -17,10 +18,17 @@ from AURUtils.version import vercmp
MAX_WORKERS = 16
+async def check_pkg(session: aiohttp.ClientSession, num: int, pkg: str) -> tuple[int, bool]:
+ logging.info(f'Checking {pkg}')
+ ret = await session.head(f'https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h={pkg}')
+ return num, ret.status == 200
+
+
async def check_aur_update(
session: aiohttp.ClientSession,
item: Path, dry_run: bool,
parse_pkgbuild: Optional[Path] = None,
+ check_deps: bool = True
) -> None:
if item.name.startswith('.') or not item.is_dir():
return
@@ -50,7 +58,8 @@ async def check_aur_update(
if resp.status != 200:
logging.info(f'{item.name} not register in AUR')
return
- new_version = SRCINFO.parse(await resp.text()).get_version()
+ new_srcinfo = SRCINFO.parse(await resp.text())
+ new_version = new_srcinfo.get_version()
result = vercmp(new_version, version)
if result == 0:
return
@@ -63,6 +72,22 @@ async def check_aur_update(
logging.info(f'Upgrade {item.name} from {version} to {new_version}')
else:
logging.info(f'Found update {item.name}({new_version}) (local: {version})')
+ if check_deps:
+ deps = list(*new_srcinfo.makedepends, *new_srcinfo.depends)
+ async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session:
+ tasks = [asyncio.create_task(check_pkg(session, n, pkg)) for n, pkg in enumerate(deps)]
+ yay_dep_nums = []
+ for task in asyncio.as_completed(tasks):
+ n, r = await task
+ if r:
+ heapq.heappush(yay_dep_nums, n)
+
+ yaydeps_dir = item.parent.joinpath('.yaydeps')
+
+ if len(yay_dep_nums) > 0:
+ async with aiofiles.open(yaydeps_dir.joinpath(item.parent.stem), 'w', encoding='utf-8') as f:
+ await f.write(
+ '\n'.join([*(deps[heapq.heappop(yay_dep_nums)] for _ in range(len(yay_dep_nums))), '']))
async def with_sem(sem: asyncio.Semaphore, coro: Coroutine):
@@ -73,10 +98,11 @@ async def with_sem(sem: asyncio.Semaphore, coro: Coroutine):
async def main() -> int:
parser = argparse.ArgumentParser(description='aur-check-update.py')
parser.add_argument('--dry-run', dest='dry', help='dry run', action='store_true')
+ parser.add_argument('--check-deps', dest='deps', help='check deps', action='store_true')
parser.add_argument('--parse-pkgbuild', dest='script', metavar='SCRIPT',
help='a script to parse pkgbuild',
action='store')
- parser.add_argument('--max-workers', dest='workers', metavar='MAX_WORKERS',
+ parser.add_argument('--miax-workers', dest='workers', metavar='MAX_WORKERS',
help=f'aur check max workers, default: {MAX_WORKERS}',
default=MAX_WORKERS, action='store', type=int)
parser.add_argument(dest='repo_dir', metavar='REPO_DIR', help='repository directory', nargs='?')
@@ -84,6 +110,7 @@ async def main() -> int:
args = parser.parse_args()
dry_run = args.dry
+ check_deps = args.deps
sem = asyncio.Semaphore(args.workers)
if args.repo_dir is None:
@@ -99,7 +126,13 @@ async def main() -> int:
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(10)) as session:
tasks = [asyncio.create_task(
- with_sem(sem, check_aur_update(session, item, dry_run, script_file))
+ with_sem(sem, check_aur_update(
+ session=session,
+ item=item,
+ dry_run=dry_run,
+ parse_pkgbuild=script_file,
+ check_deps=check_deps
+ ))
) for item in repo_dir.iterdir()]
await asyncio.gather(*tasks)