def validate_file(filename: str) -> int:
    """
    Validate `filename`, print its errors, and return the number of errors.

    :param filename: YAML filename
    :return: Number of errors
    """
    lr = lint_file(filename)

    if not lr.messages:
        success(f'{filename}: No errors')
        return 0
    click.secho('{filename}: {error_count} errors, {warning_count} warnings'.format(
        filename=filename,
        error_count=lr.error_count,
        warning_count=lr.warning_count,
    ), fg='yellow', bold=True)
    for message in lr.messages:
        click.echo('  {type}: {message}'.format(**message))
    click.echo()
    return int(lr.error_count)