From 2e14c1a1d0784acc7536158df3eb7ea58cb73ff7 Mon Sep 17 00:00:00 2001 From: Fred Barclay Date: Sat, 21 Sep 2019 10:19:38 -0500 Subject: Adding sort.py to GitLab CI (#2973) * Add contrib/sort.py to Gitlab CI Not adding to Debian Jessie or CentOS since python >=3.6 is not available See https://github.com/netblue30/firejail/pull/2870 * Updates Explicitly install python3 on Ubuntu (should be pre-installed but not working as-is) Remove running python3 code on CentOS * ci: comment out contrib/sort.py for Alpine Getting this error: $ python3 contrib/sort.py etc/*.{profile,inc} [ Error ] Can't find `etc/*.{profile,inc}' ERROR: Job failed: exit code 1 For now it's better to debug later and enable this test for the other jobs --- .gitlab-ci.yml | 7 +++++-- contrib/sort.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 37e5cc2d0..19dd2b320 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,8 +9,9 @@ build_ubuntu_package: image: ubuntu:rolling script: - apt-get update -qq - - apt-get install -y -qq build-essential lintian pkg-config + - apt-get install -y -qq build-essential lintian pkg-config python3 - ./configure --prefix=/usr && make deb && dpkg -i firejail*.deb + - python3 contrib/sort.py etc/*.{profile,inc} build_debian_package: image: debian:jessie @@ -32,14 +33,16 @@ build_fedora_package: - dnf update -y - dnf install -y rpm-build gcc make - ./configure --prefix=/usr && make rpms && rpm -i firejail*.rpm + - python3 contrib/sort.py etc/*.{profile,inc} build_src_package: image: alpine:latest script: - apk update - apk upgrade - - apk add build-base linux-headers + - apk add build-base linux-headers python3 - ./configure --prefix=/usr && make && make install-strip + # - python3 contrib/sort.py etc/*.{profile,inc} build_apparmor: image: ubuntu:latest diff --git a/contrib/sort.py b/contrib/sort.py index 97315fba8..f77e2a1fc 100755 --- a/contrib/sort.py +++ b/contrib/sort.py @@ -23,11 +23,13 @@ Exit-Codes: # python >= 3.6 from sys import argv + def sort_alphabetical(raw_items): items = raw_items.split(",") items.sort(key=lambda s: s.casefold()) return ",".join(items) + def sort_protocol(protocols): """sort the given protocole into this scheme: unix,inet,inet6,netlink,packet""" # shortcut for common protocol lines @@ -64,6 +66,7 @@ def sort_protocol(protocols): fixed_protocols += "packet," return fixed_protocols[:-1] + def fix_profile(filename): with open(filename, "r+") as profile: lines = profile.read().split("\n") @@ -94,6 +97,7 @@ def fix_profile(filename): return 101 return 0 + def main(args): exit_code = 0 for filename in args: @@ -103,15 +107,16 @@ def main(args): else: fix_profile(filename) except FileNotFoundError: - print(f"[ Error ] Can't find {filename}") + print(f"[ Error ] Can't find `{filename}'") exit_code = 1 except PermissionError: - print(f"[ Error ] Can't read/write {filename}") + print(f"[ Error ] Can't read/write `{filename}'") exit_code = 1 except: - print(f"[ Error ] An error occurred while processing {filename}") + print(f"[ Error ] An error occurred while processing `{filename}'") exit_code = 1 return exit_code + if __name__ == "__main__": exit(main(argv[1:])) -- cgit v1.2.3-54-g00ecf