From c0a70cce3ff10f4eeb87b11ef9d71aa85d3f6f69 Mon Sep 17 00:00:00 2001 From: Martijn Braam Date: Sun, 30 Jul 2017 21:43:02 +0200 Subject: [PATCH] Implemented checksum test in the travis script (#298) * Implemented checksum test in the travis script * Added workaround for squashed forced pushes * Made test possible to run locally * Match multiple git versions for the working directory message --- .travis.yml | 6 +++- test/check_checksums.py | 61 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100755 test/check_checksums.py diff --git a/.travis.yml b/.travis.yml index dcc806b1..829ee4e4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: "python" python: "3.6" +sudo: required addons: apt: sources: @@ -7,5 +8,8 @@ addons: packages: - shellcheck install: "pip install flake8" -script: "test/static_code_analysis.sh" +script: + - test/static_code_analysis.sh + - yes "" | ./pmbootstrap.py init + - test/check_checksums.py diff --git a/test/check_checksums.py b/test/check_checksums.py new file mode 100755 index 00000000..019c9e0d --- /dev/null +++ b/test/check_checksums.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +import os +import subprocess + + +def get_changed_files(): + try: + raw = subprocess.check_output(['git', 'diff', '--name-only', os.environ['TRAVIS_COMMIT_RANGE']]) + except (KeyError, subprocess.CalledProcessError) as e: + raw = subprocess.check_output(['git', 'diff', '--name-only', 'HEAD~1']) + return raw.decode().splitlines() + + +def get_changed_packages(): + files = get_changed_files() + packages = set() + for file in files: + if not file.startswith("aports/"): + continue + name = file.split("/")[2] + packages.add(name) + return packages + + +def check_output_always(command): + try: + return subprocess.check_output(command) + except subprocess.CalledProcessError as e: + return e.output + + +def check_checksums(package): + command = ['./pmbootstrap.py', 'checksum', package] + try: + subprocess.check_output(command) + except subprocess.CalledProcessError as e: + print("Something gone wrong in pmbootstrap. Log:") + logfile = os.path.expanduser("~/.local/var/pmbootstrap/log.txt") + with open(logfile) as log: + print(log.read()) + + result = check_output_always(['git', 'status', '--porcelain', '--untracked-files=no']).decode() + + if result == "": + print("** The checksums are correct") + else: + print(result) + print("** The checksums are not correct") + exit(1) + + +if __name__ == "__main__": + packages = get_changed_packages() + + if len(packages) == 0: + print("No aports packages changed in this commit") + exit(0) + + for package in packages: + print("Checking {} for correct checksums".format(package)) + check_checksums(package)