From 8d99dfd3c6cf0582d1f190a4d87070e4b11dd201 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Fri, 19 Jun 2020 10:55:15 +0200 Subject: [PATCH] gitlab-ci: only run `fdroid build` on changed build entries --- .gitlab-ci.yml | 8 ++++-- tools/find-changed-builds.py | 50 ++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 tools/find-changed-builds.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e1554a2d66..4fe2091f62 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -150,7 +150,6 @@ fdroid build: - bash fdroidserver/buildserver/provision-apt-get-install http://deb.debian.org/debian - apt-get dist-upgrade - - apt-get install sudo # TODO REMOVE ME once merged https://gitlab.com/fdroid/fdroidserver/-/merge_requests/753 # install fdroidserver from git, with deps from Debian, until fdroidserver # is stable enough to include all the things needed here @@ -162,7 +161,12 @@ fdroid build: - apt-get purge fdroidserver - export GRADLE_USER_HOME=$PWD/.gradle - - fdroid build --verbose --on-server --latest --no-tarball --no-refresh $CHANGED + # each `fdroid build --on-server` run expects sudo, then uninstalls it + - for build in `./tools/find-changed-builds.py`; do + set -x; + apt-get install sudo; + fdroid build --verbose --on-server --no-tarball $build; + done # issuebot needs secrets to run, so it has to run under the 'fdroid' diff --git a/tools/find-changed-builds.py b/tools/find-changed-builds.py new file mode 100755 index 0000000000..5439f934cf --- /dev/null +++ b/tools/find-changed-builds.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 + +import difflib +import os +import subprocess +import sys +import yaml +from colorama import Fore, Style + +changed = set(os.getenv('CHANGED').split(' ')) +changed.discard('') + +for appid in sorted(changed): + metadata_file = 'metadata/%s.yml' % appid + diff = subprocess.check_output( + ('git diff --no-color --diff-filter=d FETCH_HEAD...HEAD -- ' + metadata_file).split(' '), + ) + + with open(metadata_file) as fp: + current = yaml.safe_load(fp) + cmd = 'git apply --reverse' + p = subprocess.run(cmd.split(' '), input=diff, stdout=subprocess.DEVNULL) + if p.returncode: + print(Fore.RED + ('ERROR: %s: %d' % (cmd, p.returncode)) + Style.RESET_ALL, + file=sys.stderr) + sys.exit(p.returncode) + with open(metadata_file) as fp: + previous = yaml.safe_load(fp) + cmd = 'git apply' + p = subprocess.run(cmd.split(' '), input=diff, stdout=subprocess.DEVNULL) + if p.returncode: + print(Fore.RED + ('ERROR: %s: %d' % (cmd, p.returncode)) + Style.RESET_ALL, + file=sys.stderr) + sys.exit(p.returncode) + + to_build = [] + previous_builds = dict() + for build in previous['Builds']: + previous_builds[build['versionCode']] = build + + for build in current['Builds']: + vc = build['versionCode'] + if vc not in previous_builds: + to_build.append(vc) + continue + if build != previous_builds[vc]: + to_build.append(vc) + + for vc in to_build: + print('%s:%d' % (appid, vc), end=' ')