Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Comment thread
nineinchnick marked this conversation as resolved.
Outdated
)

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Comment thread
nineinchnick marked this conversation as resolved.
Outdated
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
Comment thread
hashhar marked this conversation as resolved.
Outdated

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