Skip to content

Commit

Permalink
add code to use log groups for GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
kmaehashi committed Sep 10, 2024
1 parent 296db0d commit 35b576a
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions dist.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import annotations

import argparse
from contextlib import contextmanager
import json
import os
import platform
Expand All @@ -10,6 +13,7 @@
import sys
import tempfile
import time
from collections.abc import Generator


from dist_config import (
Expand Down Expand Up @@ -41,6 +45,16 @@ def log(msg):
out.flush()


@contextmanager
def log_group(title: str) -> Generator:
"""
Emits a log group (for GitHub Actions).
"""
print(f'::group::{title}')
yield
print('::endgroup::')


def run_command(*cmd, extra_env=None, **kwargs):
env = None
if extra_env is not None:
Expand Down Expand Up @@ -152,24 +166,28 @@ def main(self):
args = self.parse_args()

if args.action == 'build':
if args.target == 'wheel-win':
self.build_windows(
args.target, args.cuda, args.python,
args.source, args.output)
else:
self.build_linux(
args.target, args.cuda, args.python,
args.source, args.output, args.dry_run, args.push,
args.rmi)
with log_group('Build'):
if args.target == 'wheel-win':
self.build_windows(
args.target, args.cuda, args.python,
args.source, args.output)
else:
self.build_linux(
args.target, args.cuda, args.python,
args.source, args.output, args.dry_run, args.push,
args.rmi)
elif args.action == 'verify':
if args.target == 'wheel-win':
self.verify_windows(
args.target, args.cuda, args.python,
args.dist, args.test)
with log_group('Verify'):
self.verify_windows(
args.target, args.cuda, args.python,
args.dist, args.test)
else:
# Log group will be emit for each verification run.
self.verify_linux(
args.target, args.cuda, args.python,
args.dist, args.test, args.dry_run, args.push, args.rmi)
args.dist, args.test, args.dry_run, args.push,
args.rmi)

def _create_builder_linux(
self, image_tag, base_image, builder_dockerfile, system_packages,
Expand Down Expand Up @@ -631,14 +649,16 @@ def verify_linux(
raise RuntimeError('unknown target')

for system in systems:
image = base_image.format(system=system)
image_tag_system = '{}-{}'.format(image_tag, system)
log('Starting verification for {} on {} with Python {}'.format(
dist, image, python_version))
self._verify_linux(
image_tag_system, image, kind, dist, tests,
python_version,
cuda_version, preloads, system_packages, dry_run, push, rmi)
with log_group(f'Verify: {dist} ({system} / Py {python_version})'):
image = base_image.format(system=system)
image_tag_system = '{}-{}'.format(image_tag, system)
log('Starting verification for {} on {} with Python {}'.format(
dist, image, python_version))
self._verify_linux(
image_tag_system, image, kind, dist, tests,
python_version,
cuda_version, preloads, system_packages, dry_run, push,
rmi)

def _verify_linux(
self, image_tag, base_image, kind, dist, tests, python_version,
Expand Down

0 comments on commit 35b576a

Please sign in to comment.