Esempio n. 1
0
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

import pathlib
import sys
import os
import json
import urllib.parse

cur_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(cur_dir, '..', '..', '..'))
from raft_sdk.raft_service import RaftCLI, RaftJobConfig

def run(cli, run_zap):
    run_zap_config = RaftJobConfig(file_path=run_zap,
                        substitutions={'{defaults.deploymentName}' : (RaftCLI().definitions.deployment)})
    zap_job = cli.new_job(run_zap_config)
    print(zap_job)
    cli.poll(zap_job['jobId'])

if __name__ == "__main__":
    if '--local' in sys.argv:
        from raft_local import RaftLocalCLI
        cli = RaftLocalCLI()
    else:
        cli = RaftCLI()

    run(cli, os.path.join(cur_dir, "zap.json"))
    substitutions = {
        '{defaults.deploymentName}': (RaftCLI()).definitions.deployment
    }
    compile_job_config = RaftJobConfig(file_path=compile, substitutions=substitutions)
    print('Compile')
    # create a new job with the Compile config and get new job ID
    # in compile_job
    compile_job = cli.new_job(compile_job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(compile_job['jobId'])
    substitutions['{compile.jobId}'] = compile_job['jobId']

    print('Test')
    test_job_config = RaftJobConfig(file_path=test, substitutions=substitutions)
    test_job = cli.new_job(test_job_config)
    cli.poll(test_job['jobId'])

    print('Fuzz')
    fuzz_job_config = RaftJobConfig(file_path=fuzz, substitutions=substitutions)
    fuzz_job = cli.new_job(fuzz_job_config)
    cli.poll(fuzz_job['jobId'])

if __name__ == "__main__":
    if "--local" in sys.argv:
        from raft_local import RaftLocalCLI
        cli = RaftLocalCLI(network='bridge')
    else:
        cli = RaftCLI()
    run(cli, os.path.join(cur_dir, "compile.yaml"),
        os.path.join(cur_dir, "test.yaml"),
        os.path.join(cur_dir, "fuzz.yaml"))
Esempio n. 3
0
    # submit a new job with the Compile config and get new job ID
    job = cli.new_job(job_config)
    # wait for a job with ID from compile_job to finish the run
    cli.poll(job['jobId'])
    return job['jobId']

if __name__ == "__main__":
    try:
        defaults = None

        if sys.argv[1] == '--build':
            build_id = sys.argv[2].replace(".", "-")
        print(f"BUILD ID : {build_id}")
        if "--local" in sys.argv:
            from raft_local import RaftLocalCLI
            cli = RaftLocalCLI(network='host')

        else:
            with open(os.path.join(cli_dir, 'defaults.json'), 'r') as defaults_json:
                defaults = json.load(defaults_json, object_hook=RaftJsonDict.raft_json_object_hook)
                if len(sys.argv) > 3 and sys.argv[3] == '--secret':
                    defaults['secret'] = sys.argv[4]

            # instantiate RAFT CLI
            cli = RaftCLI(defaults)

        compile_job_id = None
        subs = {
            "{ci-run}" : f"{build_id}",
            "{build-url}" : os.environ['SYSTEM_COLLECTIONURI'] if os.environ.get('SYSTEM_COLLECTIONURI') else "",
            "{build-id}" : os.environ['BUILD_BUILDID'] if os.environ.get('BUILD_BUILDID') else ""