From cdde716d18857d56fb929492bc0805940cb654b2 Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Jun 07 2019 16:09:03 +0000 Subject: CI: Make CI work on non-master branches Now that Pagure.io supports $BRANCH_TO, we can handle non-master branches. Signed-off-by: Stephen Gallagher --- diff --git a/.cico.pipeline b/.cico.pipeline index 159a818..b6719a2 100644 --- a/.cico.pipeline +++ b/.cico.pipeline @@ -2,6 +2,7 @@ pipeline { parameters { string(defaultValue: "", description: "", name: "REPO") string(defaultValue: "", description: "", name: "BRANCH") + string(defaultValue: "", description: "", name: "BRANCH_TO") } agent { node { label 'fedora29' } } diff --git a/run_tests.sh b/run_tests.sh index 0c323d9..efb15cc 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -1,13 +1,14 @@ #!/bin/bash set -e +set -x -if [ -n "$REPO" -a -n "$BRANCH" ]; then +if [ "$BRANCH_TO" != "None" ]; then git config user.email "noreply@ci.centos.org" git config user.name "CentOS CI" # Save the commit ID of the baseline checkout - MODULE_DEFAULTS_TEST_BASELINE=$(git log -1 --pretty=%H) + MODULE_DEFAULTS_TEST_BASELINE=$(git log -1 --pretty=%H origin/$BRANCH_TO) export MODULE_DEFAULTS_TEST_BASELINE # Merge the PR into the current tree @@ -15,14 +16,22 @@ if [ -n "$REPO" -a -n "$BRANCH" ]; then git gc --auto git remote add proposed "$REPO" git fetch proposed - git checkout origin/master - git merge --no-ff "proposed/$BRANCH" -m "Merge PR" + + MODULE_DEFAULTS_TEST_UPDATED=$(git log -1 --pretty=%H proposed/$BRANCH) + export MODULE_DEFAULTS_TEST_UPDATED + + # Test that it merges cleanly + git branch -D baseline || true + git checkout -b baseline $MODULE_DEFAULTS_TEST_BASELINE + git merge --no-ff "$MODULE_DEFAULTS_TEST_UPDATED" -m "Merge PR" echo "Running tests for branch $BRANCH of repo $REPO" echo "Last commits:" - git log -2 + git log $MODULE_DEFAULTS_TEST_BASELINE..$MODULE_DEFAULTS_TEST_UPDATED - # Run any tests that only apply to PRs + # Run any tests that only apply to PRs. + # Always run these from the master branch + git checkout origin/master tests/pr_tests.sh fi diff --git a/tests/compare_defaults.py b/tests/compare_defaults.py index 790ab21..346b304 100755 --- a/tests/compare_defaults.py +++ b/tests/compare_defaults.py @@ -56,6 +56,7 @@ def get_index_and_defaults (repo, filename, commit): def main(): filename = sys.argv[1] baseline_commit = sys.argv[2] + updated_commit = sys.argv[3] script_dir = os.path.dirname(os.path.realpath(__file__)) @@ -74,7 +75,7 @@ def main(): return unusable_baseline() try: - updated_commit = 'HEAD' + updated_commit = updated_commit updated_index, updated_defaults = get_index_and_defaults ( repo, filename, updated_commit) except IOError as e: diff --git a/tests/pr_tests.sh b/tests/pr_tests.sh index 027ca83..85a0752 100755 --- a/tests/pr_tests.sh +++ b/tests/pr_tests.sh @@ -16,12 +16,15 @@ pushd $GIT_ROOT modified_files=$(git log --name-only \ --pretty=oneline \ --full-index \ - $MODULE_DEFAULTS_TEST_BASELINE..HEAD \ + $MODULE_DEFAULTS_TEST_BASELINE..$MODULE_DEFAULTS_TEST_UPDATED \ | grep -vE '^[0-9a-f]{40} ' | sort -u) for file in ${modified_files[@]}; do if [[ $file == *".yaml" ]]; then - $SCRIPT_DIR/compare_defaults.py $file $MODULE_DEFAULTS_TEST_BASELINE + $SCRIPT_DIR/compare_defaults.py \ + $file \ + $MODULE_DEFAULTS_TEST_BASELINE \ + $MODULE_DEFAULTS_TEST_UPDATED fi done