diff --git a/.github/workflows/package-lint.yml b/.github/workflows/package-lint.yml index ef1ba37..045448f 100644 --- a/.github/workflows/package-lint.yml +++ b/.github/workflows/package-lint.yml @@ -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 @@ -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 diff --git a/repogen/check_compat.py b/repogen/check_compat.py index dc65e45..912e3fe 100644 --- a/repogen/check_compat.py +++ b/repogen/check_compat.py @@ -1,8 +1,6 @@ import subprocess from pathlib import Path -import shellescape - from repogen import pkg_info from repogen.pkg_info import PackageInfo @@ -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) diff --git a/repogen/lintpkg.py b/repogen/lintpkg.py index 7822a11..cfe09a1 100644 --- a/repogen/lintpkg.py +++ b/repogen/lintpkg.py @@ -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 @@ -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']: @@ -50,13 +52,11 @@ 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() @@ -64,7 +64,7 @@ def lint(self, info: PackageInfo) -> [str]: 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]): @@ -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) diff --git a/requirements.txt b/requirements.txt index c626d96..99b8f69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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