def test_fail_get_upstream_artifacts_full_paths_per_task_id(context):
    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/failed_mandatory_file'],
            'taskId': 'failedDependency',
            'taskType': 'signing',
        }]
    }
    with pytest.raises(ScriptWorkerTaskException):
        get_upstream_artifacts_full_paths_per_task_id(context)
Example #2
0
def test_fail_get_upstream_artifacts_full_paths_per_task_id(context):
    context.task["payload"] = {
        "upstreamArtifacts": [{
            "paths": ["public/failed_mandatory_file"],
            "taskId": "failedDependency",
            "taskType": "signing"
        }]
    }
    with pytest.raises(ScriptWorkerTaskException):
        get_upstream_artifacts_full_paths_per_task_id(context)
Example #3
0
def test_fail_get_upstream_artifacts_full_paths_per_task_id(context):
    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/failed_mandatory_file'],
            'taskId': 'failedDependency',
            'taskType': 'signing',
        }]
    }
    with pytest.raises(ScriptWorkerTaskException):
        get_upstream_artifacts_full_paths_per_task_id(context)
Example #4
0
async def async_main(context):
    android_product = task.extract_android_product_from_scopes(context)
    product_config = _get_product_config(context, android_product)
    publish_config = get_publish_config(product_config, context.task['payload'], android_product)
    contact_server = not bool(context.config.get('do_not_contact_server'))

    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(contact_server, publish_config['dry_run'], publish_config['target_store'])

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(context)

    all_apks_paths = [
        artifact
        for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list
        if artifact.endswith('.apk')
    ]

    if not publish_config.get('skip_check_signature', True):
        log.info('Verifying APKs\' signatures...')
        for apk_path in all_apks_paths:
            jarsigner.verify(context, publish_config, apk_path)
            manifest.verify(product_config, apk_path)
    else:
        log.info('This product is configured with "skip_check_signature", so the signing of the '
                 'APK will not be verified.')

    log.info('Delegating publication to mozapkpublisher...')
    with contextlib.ExitStack() as stack:
        files = [stack.enter_context(open(apk_file_name)) for apk_file_name in all_apks_paths]
        publish.publish(product_config, publish_config, files, contact_server)

    log.info('Done!')
Example #5
0
async def async_main(context):
    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(context)

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = get_upstream_artifacts_full_paths_per_task_id(context)

    all_apks_paths = [
        artifact
        for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list
        if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    [jarsigner.verify(context, apk_path) for apk_path in all_apks_paths]

    log.info('Finding whether Google Play strings can be updated...')
    google_play_strings_path = googleplay.get_google_play_strings_path(
        artifacts_per_task_id, failed_artifacts_per_task_id
    )

    log.info('Delegating publication to mozapkpublisher...')
    googleplay.publish_to_googleplay(
        context, all_apks_paths, google_play_strings_path,
    )

    log.info('Done!')
Example #6
0
def test_get_upstream_artifacts_full_paths_per_task_id(context):
    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/file_a'],
            'taskId': 'dependency1',
            'taskType': 'signing',
        }, {
            'paths': ['public/file_b'],
            'taskId': 'dependency2',
            'taskType': 'signing',
        }],
    }

    for artifact in context.task['payload']['upstreamArtifacts']:
        folder = os.path.join(context.config['work_dir'], 'cot',
                              artifact['taskId'])
        os.makedirs(os.path.join(folder, 'public'))
        touch(os.path.join(folder, artifact['paths'][0]))

    assert get_upstream_artifacts_full_paths_per_task_id(context) == {
        'dependency1': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency1',
                         'public', 'file_a')
        ],
        'dependency2': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency2',
                         'public', 'file_b')
        ],
    }
def get_snap_file_path(context):
    artifacts_per_task_id, _ = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_artifacts = [
        artifact for artifacts in artifacts_per_task_id.values()
        for artifact in artifacts
    ]

    return get_single_item_from_sequence(
        all_artifacts,
        condition=lambda artifact: artifact.endswith('.snap'),
        ErrorClass=TaskVerificationError,
        no_item_error_message='No upstream artifact is a snap',
        too_many_item_error_message='Too many snaps detected',
    )
Example #8
0
def get_flatpak_file_path(context):
    artifacts_per_task_id, _ = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_artifacts = [
        artifact for artifacts in artifacts_per_task_id.values()
        for artifact in artifacts
    ]

    return get_single_item_from_sequence(
        all_artifacts,
        condition=lambda artifact: artifact.endswith(".flatpak.tar.xz"),
        ErrorClass=TaskVerificationError,
        no_item_error_message="No upstream artifact is a tar.xz",
        too_many_item_error_message="Too many flatpaks detected",
    )
Example #9
0
async def async_main(context):
    android_product = task.extract_android_product_from_scopes(context)
    product_config = _get_product_config(context, android_product)
    contact_google_play = not bool(
        context.config.get('do_not_contact_google_play'))

    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(contact_google_play, context.task['payload'])

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_apks_paths = [
        artifact for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    for apk_path in all_apks_paths:
        jarsigner.verify(context, apk_path)
        manifest.verify(product_config, apk_path)

    if product_config['update_google_play_strings']:
        log.info('Finding whether Google Play strings can be updated...')
        strings_path = googleplay.get_google_play_strings_path(
            artifacts_per_task_id, failed_artifacts_per_task_id)
    else:
        log.warning(
            'This product does not upload strings automatically. Skipping Google Play strings search.'
        )
        strings_path = None

    log.info('Delegating publication to mozapkpublisher...')
    with contextlib.ExitStack() as stack:
        files = [
            stack.enter_context(open(apk_file_name))
            for apk_file_name in all_apks_paths
        ]
        strings_file = stack.enter_context(
            open(strings_path)) if strings_path is not None else None
        googleplay.publish_to_googleplay(context.task['payload'],
                                         product_config, files,
                                         contact_google_play, strings_file)

    log.info('Done!')
Example #10
0
def test_get_upstream_artifacts_full_paths_per_task_id(context):
    artifacts_to_succeed = [{
        'paths': ['public/file_a'],
        'taskId': 'dependency1',
        'taskType': 'signing',
    }, {
        'paths': ['public/file_b'],
        'taskId': 'dependency2',
        'taskType': 'signing',
    }]

    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/failed_optional_file1'],
            'taskId': 'failedDependency1',
            'taskType': 'signing',
            'optional': True
        }, {
            'paths': ['public/failed_optional_file2', 'public/failed_optional_file3'],
            'taskId': 'failedDependency2',
            'taskType': 'signing',
            'optional': True
        }],
    }

    context.task['payload']['upstreamArtifacts'].extend(artifacts_to_succeed)
    for artifact in artifacts_to_succeed:
        folder = os.path.join(context.config['work_dir'], 'cot', artifact['taskId'])
        os.makedirs(os.path.join(folder, 'public'))
        touch(os.path.join(folder, artifact['paths'][0]))

    succeeded_artifacts, failed_artifacts = get_upstream_artifacts_full_paths_per_task_id(context)

    assert succeeded_artifacts == {
        'dependency1': [os.path.join(context.config['work_dir'], 'cot', 'dependency1', 'public', 'file_a')],
        'dependency2': [os.path.join(context.config['work_dir'], 'cot', 'dependency2', 'public', 'file_b')],
    }
    assert failed_artifacts == {
        'failedDependency1': ['public/failed_optional_file1'],
        'failedDependency2': ['public/failed_optional_file2', 'public/failed_optional_file3'],
    }
Example #11
0
async def async_main(context):
    logging.getLogger('oauth2client').setLevel(logging.WARNING)
    _log_warning_forewords(context)

    log.info('Verifying upstream artifacts...')
    artifacts_per_task_id, failed_artifacts_per_task_id = artifacts.get_upstream_artifacts_full_paths_per_task_id(
        context)

    all_apks_paths = [
        artifact for artifacts_list in artifacts_per_task_id.values()
        for artifact in artifacts_list if artifact.endswith('.apk')
    ]

    log.info('Verifying APKs\' signatures...')
    for apk_path in all_apks_paths:
        jarsigner.verify(context, apk_path)
        manifest.verify(context, apk_path)

    if task.extract_android_product_from_scopes(context) in [
            'focus', 'reference-browser'
    ]:
        log.warning(
            'This product does not upload strings automatically. Skipping Google Play strings search.'
        )
        google_play_strings_path = None
    else:
        log.info('Finding whether Google Play strings can be updated...')
        google_play_strings_path = googleplay.get_google_play_strings_path(
            artifacts_per_task_id, failed_artifacts_per_task_id)

    log.info('Delegating publication to mozapkpublisher...')
    googleplay.publish_to_googleplay(
        context,
        all_apks_paths,
        google_play_strings_path,
    )

    log.info('Done!')
def test_get_upstream_artifacts_full_paths_per_task_id(context):
    artifacts_to_succeed = [{
        'paths': ['public/file_a1'],
        'taskId': 'dependency1',
        'taskType': 'signing',
    }, {
        'paths': ['public/file_b1', 'public/file_b2'],
        'taskId': 'dependency2',
        'taskType': 'signing',
    }, {
        'paths': ['some_other_folder/file_c'],
        'taskId': 'dependency3',
        'taskType': 'signing',
    }, {
        # Case where the same taskId was given. In some occasion we may want to split
        # upstreamArtifacts of the same taskId into 2. For instance: 1 taskId with a given
        # parameter (like beetmover's "locale") but not the other
        'paths': ['public/file_a2'],
        'taskId': 'dependency1',
        'taskType': 'signing',
    }]

    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/failed_optional_file1'],
            'taskId': 'failedDependency1',
            'taskType': 'signing',
            'optional': True
        }, {
            'paths': ['public/failed_optional_file2', 'public/failed_optional_file3'],
            'taskId': 'failedDependency2',
            'taskType': 'signing',
            'optional': True
        }],
    }

    context.task['payload']['upstreamArtifacts'].extend(artifacts_to_succeed)
    for artifact in artifacts_to_succeed:
        folder = os.path.join(context.config['work_dir'], 'cot', artifact['taskId'])

        for path in artifact['paths']:
            try:
                os.makedirs(os.path.join(folder, os.path.dirname(path)))
            except FileExistsError:
                pass
            touch(os.path.join(folder, path))

    succeeded_artifacts, failed_artifacts = get_upstream_artifacts_full_paths_per_task_id(context)

    assert succeeded_artifacts == {
        'dependency1': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency1', 'public', 'file_a1'),
            os.path.join(context.config['work_dir'], 'cot', 'dependency1', 'public', 'file_a2'),
        ],
        'dependency2': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency2', 'public', 'file_b1'),
            os.path.join(context.config['work_dir'], 'cot', 'dependency2', 'public', 'file_b2'),
        ],
        'dependency3': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency3', 'some_other_folder', 'file_c'),
        ],
    }
    assert failed_artifacts == {
        'failedDependency1': ['public/failed_optional_file1'],
        'failedDependency2': ['public/failed_optional_file2', 'public/failed_optional_file3'],
    }
def test_get_upstream_artifacts_full_paths_per_task_id(context):
    artifacts_to_succeed = [{
        'paths': ['public/file_a1'],
        'taskId': 'dependency1',
        'taskType': 'signing',
    }, {
        'paths': ['public/file_b1', 'public/file_b2'],
        'taskId': 'dependency2',
        'taskType': 'signing',
    }, {
        'paths': ['some_other_folder/file_c'],
        'taskId': 'dependency3',
        'taskType': 'signing',
    }, {
        # Case where the same taskId was given. In some occasion we may want to split
        # upstreamArtifacts of the same taskId into 2. For instance: 1 taskId with a given
        # parameter (like beetmover's "locale") but not the other
        'paths': ['public/file_a2'],
        'taskId': 'dependency1',
        'taskType': 'signing',
    }]

    context.task['payload'] = {
        'upstreamArtifacts': [{
            'paths': ['public/failed_optional_file1'],
            'taskId': 'failedDependency1',
            'taskType': 'signing',
            'optional': True
        }, {
            'paths': ['public/failed_optional_file2', 'public/failed_optional_file3'],
            'taskId': 'failedDependency2',
            'taskType': 'signing',
            'optional': True
        }],
    }

    context.task['payload']['upstreamArtifacts'].extend(artifacts_to_succeed)
    for artifact in artifacts_to_succeed:
        folder = os.path.join(context.config['work_dir'], 'cot', artifact['taskId'])

        for path in artifact['paths']:
            try:
                os.makedirs(os.path.join(folder, os.path.dirname(path)))
            except FileExistsError:
                pass
            touch(os.path.join(folder, path))

    succeeded_artifacts, failed_artifacts = get_upstream_artifacts_full_paths_per_task_id(context)

    assert succeeded_artifacts == {
        'dependency1': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency1', 'public', 'file_a1'),
            os.path.join(context.config['work_dir'], 'cot', 'dependency1', 'public', 'file_a2'),
        ],
        'dependency2': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency2', 'public', 'file_b1'),
            os.path.join(context.config['work_dir'], 'cot', 'dependency2', 'public', 'file_b2'),
        ],
        'dependency3': [
            os.path.join(context.config['work_dir'], 'cot', 'dependency3', 'some_other_folder', 'file_c'),
        ],
    }
    assert failed_artifacts == {
        'failedDependency1': ['public/failed_optional_file1'],
        'failedDependency2': ['public/failed_optional_file2', 'public/failed_optional_file3'],
    }
Example #14
0
def test_get_upstream_artifacts_full_paths_per_task_id(context):
    artifacts_to_succeed = [
        {
            "paths": ["public/file_a1"],
            "taskId": "dependency1",
            "taskType": "signing"
        },
        {
            "paths": ["public/file_b1", "public/file_b2"],
            "taskId": "dependency2",
            "taskType": "signing"
        },
        {
            "paths": ["some_other_folder/file_c"],
            "taskId": "dependency3",
            "taskType": "signing"
        },
        {
            # Case where the same taskId was given. In some occasion we may want to split
            # upstreamArtifacts of the same taskId into 2. For instance: 1 taskId with a given
            # parameter (like beetmover's "locale") but not the other
            "paths": ["public/file_a2"],
            "taskId": "dependency1",
            "taskType": "signing",
        },
    ]

    context.task["payload"] = {
        "upstreamArtifacts": [
            {
                "paths": ["public/failed_optional_file1"],
                "taskId": "failedDependency1",
                "taskType": "signing",
                "optional": True
            },
            {
                "paths": [
                    "public/failed_optional_file2",
                    "public/failed_optional_file3"
                ],
                "taskId":
                "failedDependency2",
                "taskType":
                "signing",
                "optional":
                True
            },
        ]
    }

    context.task["payload"]["upstreamArtifacts"].extend(artifacts_to_succeed)
    for artifact in artifacts_to_succeed:
        folder = os.path.join(context.config["work_dir"], "cot",
                              artifact["taskId"])

        for path in artifact["paths"]:
            try:
                os.makedirs(os.path.join(folder, os.path.dirname(path)))
            except FileExistsError:
                pass
            touch(os.path.join(folder, path))

    succeeded_artifacts, failed_artifacts = get_upstream_artifacts_full_paths_per_task_id(
        context)

    assert succeeded_artifacts == {
        "dependency1": [
            os.path.join(context.config["work_dir"], "cot", "dependency1",
                         "public", "file_a1"),
            os.path.join(context.config["work_dir"], "cot", "dependency1",
                         "public", "file_a2"),
        ],
        "dependency2": [
            os.path.join(context.config["work_dir"], "cot", "dependency2",
                         "public", "file_b1"),
            os.path.join(context.config["work_dir"], "cot", "dependency2",
                         "public", "file_b2"),
        ],
        "dependency3": [
            os.path.join(context.config["work_dir"], "cot", "dependency3",
                         "some_other_folder", "file_c")
        ],
    }
    assert failed_artifacts == {
        "failedDependency1": ["public/failed_optional_file1"],
        "failedDependency2":
        ["public/failed_optional_file2", "public/failed_optional_file3"],
    }