Skip to content

Commit

Permalink
improving package lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed May 29, 2024
1 parent 1e793d3 commit 09bbf91
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/package-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ jobs:
sudo apt-get install ./temp/webosbrew-toolbox-*.deb
- name: Lint package information
shell: bash
run: |
export lint_retcode=0
for changed_file in ${{ inputs.packages }}; do
echo "## Check Results for $(basename "${changed_file}"):" >> /tmp/lint-report.md
echo "# Check Results for $(basename "${changed_file}"):" >> /tmp/lint-report.md
echo >> /tmp/lint-report.md
echo '### Metadata Lint Result' >> /tmp/lint-report.md
echo '## Package Metadata' >> /tmp/lint-report.md
echo >> /tmp/lint-report.md
python3 -m repogen.lintpkg -f "${changed_file}" >> /tmp/lint-report.md || export lint_retcode=1
Expand All @@ -57,7 +58,7 @@ jobs:
ipkfile=/tmp/$(sha256sum "${changed_file}" | cut -d ' ' -f 1).ipk
python3 -m repogen.downloadipk -i "${changed_file}" -o "${ipkfile}" >> /tmp/lint-report.md || { export lint_retcode=1; continue; }
echo '### Compatibility Check Results' >> /tmp/lint-report.md
echo '## Compatibility Check' >> /tmp/lint-report.md
python3 -m repogen.check_compat -i "${changed_file}" -p "${ipkfile}" >> /tmp/lint-report.md || export lint_retcode=1
done
Expand Down
12 changes: 7 additions & 5 deletions repogen/check_compat.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import subprocess
from pathlib import Path

import shellescape

from repogen import pkg_info
from repogen.pkg_info import PackageInfo

Expand All @@ -12,9 +10,13 @@ def check(info_file: Path, package_file: Path):
compat_check_args = ['--format', 'markdown', '--details']
if 'requirements' in info:
if 'webosRelease' in info['requirements']:
compat_check_args.extend(['--fw-releases', shellescape.quote(info["requirements"]["webosRelease"])])
p = subprocess.run(f'webosbrew-ipk-verify {" ".join(compat_check_args)} {str(package_file.absolute())}',
shell=True)
compat_check_args.extend(['--fw-releases', info["requirements"]["webosRelease"]])
p = subprocess.run(args=['webosbrew-ipk-verify', *compat_check_args, str(package_file.absolute())],
shell=False, stdout=subprocess.PIPE, universal_newlines=True)
for line in p.stdout.splitlines():
if line.startswith('## Package'):
continue
print(line)
exit(p.returncode)


Expand Down
39 changes: 20 additions & 19 deletions repogen/lintpkg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
from typing import Tuple, List
from urllib.parse import urlparse
from urllib.request import url2pathname
from xml.etree import ElementTree
Expand Down Expand Up @@ -31,8 +32,9 @@ def run(self, root: ElementTree.Element):
self.errors.append("Use HTTPS URL for %s" % src)
return None

def lint(self, info: PackageInfo) -> [str]:
errors: [str] = []
def lint(self, info: PackageInfo) -> Tuple[List[str], List[str]]:
errors: List[str] = []
warnings: List[str] = []

# Pool property
if info['pool'] not in ['main', 'non-free']:
Expand All @@ -50,21 +52,19 @@ def lint(self, info: PackageInfo) -> [str]:
errors.append('iconUrl must be data URI or use HTTPS')

# Process manifest
if 'manifestUrl' in info:
PackageInfoLinter._validate_manifest_url(info['manifestUrl'], 'manifestUrl', errors)
elif 'manifest' not in info:
errors.append('Either `manifestUrl` or `manifest` is required')

if 'manifestUrlBeta' in info:
PackageInfoLinter._validate_manifest_url(info['manifestUrlBeta'], 'manifestUrlBeta', errors)
manifest = info['manifest']
if info['id'].startswith('org.webosbrew.'):
source_url = manifest.get('sourceUrl', None)
if not source_url or not source_url.startswith('https://github.com/webosbrew/'):
warnings.append('Only package from github.com/webosbrew can have id starting with `org.webosbrew.`')

description = info.get('description', '')
mk = Markdown()
# patch in the customized image pattern matcher with url checking
mk.treeprocessors.register(
self.ImageProcessor(errors), 'image_link', 1)
mk.convert(description)
return errors
return errors, warnings

@staticmethod
def _validate_manifest_url(url: str, key: str, e: [str]):
Expand Down Expand Up @@ -94,12 +94,13 @@ def _validate_manifest_url(url: str, key: str, e: [str]):
raise ValueError('No package info')

linter = PackageInfoLinter()
lint_errors = linter.lint(lint_pkginfo)

if len(lint_errors):
print('#### Issue:')
for err in lint_errors:
print(' * %s' % err)
exit(1)
else:
print('Check passed.')
lint_errors, lint_warnings = linter.lint(lint_pkginfo)

for err in lint_errors:
print(' * :x: %s' % err)
for warn in lint_warnings:
print(' * :warning: %s' % warn)

if not len(lint_errors) and not len(lint_warnings):
print(':white_check_mark: Check passed.')
exit(1 if len(lint_errors) else 0)
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ invoke~=2.2.0
ar~=0.8
jsonschema~=4.21.1
semantic-version~=2.10.0
shellescape~=3.8.1
lxml~=5.1.0
debian-parser~=0.1.2
git+https://github.com/Kronuz/pyScss.git@60414f5d573315a8458b5fbcdf69e5c648c44a9a#egg=pyscss
Expand Down

0 comments on commit 09bbf91

Please sign in to comment.