diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 601325f..ebeb1c1 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,6 +57,7 @@ jobs: permissions: write-all runs-on: ubuntu-22.04 needs: [check_templated_files, create_matrix] + if: ${{ needs.create_matrix.outputs.matrix != '' && needs.create_matrix.outputs.matrix != '{"include":[]}' }} strategy: fail-fast: false matrix: ${{ fromJson(needs.create_matrix.outputs.matrix) }} diff --git a/matrix.py b/matrix.py index fefd435..9254de3 100644 --- a/matrix.py +++ b/matrix.py @@ -46,14 +46,14 @@ def main(): parser.add_argument( "--dockerfiles", "--filepaths", + type=argparse.FileType("r"), help="Path to file containing list of Dockerfiles to filter on, e.g. `--dockerfiles files.txt`", - type=str, ) parser.add_argument( "--platforms", - help="List of platforms to filter on, e.g. `--platforms n64 ps2`", type=str, nargs="+", + help="List of platforms to filter on, e.g. `--platforms n64 ps2`", ) args = parser.parse_args() @@ -69,26 +69,28 @@ def main(): ] ) - allowed_dockerfiles = [] if args.dockerfiles: - with open(args.dockerfiles, "r") as f: - lines = [x.strip() for x in f.readlines()] - for line in lines: - path = Path(line) - res = parse_dockerfile_path(path) - if res is not None: - allowed_dockerfiles.append(res) + allowed_dockerfiles = [] + lines = [x.strip() for x in args.dockerfiles.readlines()] + for line in lines: + path = Path(line) + res = parse_dockerfile_path(path) + if res is not None: + allowed_dockerfiles.append(res) + + if len(allowed_dockerfiles) > 0: + local_dockerfiles = filter( + lambda x: x in allowed_dockerfiles, local_dockerfiles + ) + else: + # no Dockerfiles were modified + local_dockerfiles = [] if args.platforms: local_dockerfiles = filter( lambda x: x[0] in args.platforms, local_dockerfiles ) - if len(allowed_dockerfiles) > 0: - local_dockerfiles = filter( - lambda x: x in allowed_dockerfiles, local_dockerfiles - ) - includes = [process_dockerfile(p, c, a) for (p, c, a) in local_dockerfiles] matrix = dict(include=includes) print(json.dumps(matrix, separators=(",", ":")))