Skip to content

Commit

Permalink
Do not build when no Dockerfiles have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
mkst committed Sep 17, 2023
1 parent 7a8093c commit d63ae99
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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) }}
Expand Down
32 changes: 17 additions & 15 deletions matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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=(",", ":")))
Expand Down

0 comments on commit d63ae99

Please sign in to comment.