Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CI only build/test modules with any changes #10323

Merged
merged 9 commits into from
Feb 28, 2022
78 changes: 78 additions & 0 deletions .github/bin/build-matrix-from-impacted.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/usr/bin/env python3

import argparse
import yaml
import json
import logging
import sys


def main():
parser = argparse.ArgumentParser(
description="Filter test matrix modules using list of impacted modules."
)
parser.add_argument(
"-m",
"--matrix",
type=argparse.FileType("r"),
default=".github/test-matrix.yaml",
help="A YAML file with the test matrix",
)
parser.add_argument(
"-i",
"--impacted",
type=argparse.FileType("r"),
default="gib-impacted.log",
help="File containing list of impacted modules, one per line, "
"as paths, not artifact ids",
)
parser.add_argument(
"-o",
"--output",
type=argparse.FileType("w"),
default=sys.stdout,
help="Filename to write impacted modules matrix JSON to",
)
parser.add_argument(
"-v",
"--verbose",
action="store_const",
dest="loglevel",
const=logging.INFO,
default=logging.WARNING,
help="Print info level logs",
nineinchnick marked this conversation as resolved.
Show resolved Hide resolved
)

args = parser.parse_args()
logging.basicConfig(level=args.loglevel)
build(args.matrix, args.impacted, args.output)


def build(matrix_file, impacted_file, output_file):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd propose (as a follow-up) to move this to a dev directory and add some basic tests there too (i.e. handwritten list of modules and impacted modules) to ensure we can confidently change/refactor in future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'm still waiting for some confirmation the whole idea is ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bump, let's create follow-up issues to track

matrix = yaml.load(matrix_file, Loader=yaml.Loader)
impacted = list(filter(None, [line.strip() for line in impacted_file.readlines()]))
logging.info("Read matrix: %s", matrix)
logging.info("Read impacted: %s", impacted)
include = []
for item in matrix.get("include", []):
modules = item.get("modules", [])
if isinstance(modules, str):
modules = [modules]
if not any(module in impacted for module in modules):
logging.info("Excluding matrix section: %s", item)
continue
nineinchnick marked this conversation as resolved.
Show resolved Hide resolved
include.append(
{
# concatenate because matrix values should be primitives
"modules": ",".join(modules),
"profile": item.get("profile", ""),
}
)
if include:
matrix["include"] = include
json.dump(matrix, output_file)
output_file.write("\n")


if __name__ == "__main__":
main()
10 changes: 10 additions & 0 deletions .github/bin/git-fetch-base-ref.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
hashhar marked this conversation as resolved.
Show resolved Hide resolved

set -euo pipefail

if [ -z "${GITHUB_BASE_REF:-}" ] || [ "$GITHUB_BASE_REF" == master ]; then
echo >&2 "GITHUB_BASE_REF is not set or is master, not fetching it"
exit 0
fi

git fetch --no-tags --prune origin "$GITHUB_BASE_REF"
Loading