#!/usr/bin/env bash # This file is part of scripts. # scripts is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3. # scripts is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with scripts. If not, see . # Original author: Maciej Barć # Copyright (c) 2020, src_prepare group # Licensed under the GNU GPL v3 License # CI Ebuild commit tester # Run this in a overlay directory. # This script uses pkgcheck and repoman # to check the latest commit for QA issues. # Check if we are in a git repo if ! git status >/dev/null; then printf "%s\n" "Not a git repo... exiting" >> /dev/stderr exit 1 fi # Variables needed for tools [ -z "${ARCH}" ] && export ARCH=x86_64 [ -z "${ACCEPT_KEYWORDS}" ] && export ACCEPT_KEYWORDS='**' # create "eclass" # apparently pkgcheck needs it # "pkgcheck scan: error: failed running git: fatal: eclass: no such path in the working tree." [ -d eclass ] || mkdir eclass # First test for a whole repo # This will likely exit firh error, because repoman # has to download some files (metadata.xsd) # We do that so we can truthfully test the actual latest commit printf "%s\n" \ ">>> Starting full test" \ "Running repoman -Idix" repoman -Idix printf "%s\n" "Running pkgcheck scan" pkgcheck scan printf "%s\n" ">>> Starting latest commit test" test_success=true # Use pkgchek printf "%s\n" "Running pkgcheck scan --commits" pkgcheck scan --commits || test_success=false # Iterate through changed files in last commit # For each of these use dirname to change directory # to the one where the changed file resides # and run repoman in there for file in $(git diff --name-only HEAD HEAD~1) do commit_dir="$(dirname "${file}")" # skip these directories [[ "${commit_dir}" = *eclass ]] && continue [[ "${commit_dir}" = *files ]] && continue [[ "${commit_dir}" = *licenses* ]] && continue [[ "${commit_dir}" = *metadata* ]] && continue [[ "${commit_dir}" = *profiles ]] && continue if cd "${commit_dir}" then printf "\n%s\n" \ "Directory $(pwd):" \ "Running repoman -Idix" repoman -Idix || test_success=false cd - >/dev/null || return fi done # If any of the QA tools fail the test will fail if [ ${test_success} = false ] then printf "%s\n" ">>> Exiting with failure due to previous errors..." >> /dev/stderr exit 1 else exit 0 fi