Example #1
0
def getRemoteVersion(remoteTargetID):
    remoteVersionURL = common.Globals.GITHUB_MASTER_BASE_URL + "versionData.json"

    # Get remote version
    if common.Globals.DEVELOPER_MODE and os.path.exists("versionData.json"):
        allRemoteVersions, remoteError = common.getJSON("versionData.json",
                                                        isURL=False)
    else:
        allRemoteVersions, remoteError = common.getJSON(remoteVersionURL,
                                                        isURL=True)

    if remoteError is not None:
        print("Error retrieving remote version".format(remoteError))

    # The remote JSON stores a version dict for each mod-subMod pair. Extract only the one that we want
    remoteVersionObject = None
    if allRemoteVersions is not None:
        for remoteVersion in allRemoteVersions:
            if remoteVersion['id'] == remoteTargetID:
                remoteVersionObject = remoteVersion
                break

    # In theory can always re-install everything if can't get the remote server, but most likely it means
    # remote version this indicates an error with the server, so halt if this happens.
    if remoteVersionObject is None:
        raise Exception(
            "Can't get version information for {} from server! Installation stopped."
            .format(remoteTargetID))

    return SubModVersionInfo(remoteVersionObject)
    def PRToStaging(e):
        if getJSON(e['pull_request']['url'])['state'] != 'open':
            print('Skip building a closed PR')
            return

        diff = DeployableDiff.createFromPR(e['pull_request'])
        if not diff:
            setCommitStatus(e['pull_request']['head']['sha'], BuildStatus.failure, 'Merge conflict', '')
        else:
            processDiff(diff)
def processDiff(diff):
    if len(
            diff.sh(f'kubectl -n {env.CD_NAMESPACE} get ConfigMap --ignore-not-found ' +
                    getFullName(f'skip-{diff.head}'))):
        diff.log('Skipping this commit.')
        return

    setCommitStatus(diff.head, BuildStatus.pending, 'Starting deployment..', diff.outputURL)

    try:
        # here is the main pipeline, should normally not have any excpetions
        try:
            clusterUntouched = True
            upgradeOK = False
            testOK = False
            rollbackOK = False
            diff.initializeCharts()
            try:
                clusterUntouched = False
                upgradeOK = diff.deploy()
                if upgradeOK:
                    setCommitStatus(diff.head, BuildStatus.pending, 'Deployment OK, starting tests..', diff.outputURL)
                    testOK = diff.runTests()
                    if testOK:
                        setCommitStatus(diff.head, BuildStatus.success, 'Deployment and tests successful!',
                                        diff.outputURL)
                        diff.log('Result: OK')
            finally:
                if not upgradeOK or not testOK:
                    setCommitStatus(diff.head, BuildStatus.failure, 'Deployment or tests failed, starting rollback..',
                                    diff.outputURL)
                    rollbackOK = diff.rollback()
        finally:
            # report status on failure
            if not upgradeOK or not testOK:
                if clusterUntouched:
                    status = 'No changes made to cluster.'
                else:
                    status = f"Changes {'were rolled' if rollbackOK else 'failed to roll'} back."
                setCommitStatus(diff.head, BuildStatus.failure, "Deployment failed. " + status, diff.outputURL)
                diff.log(f'Result: Failure. ({status})')
                # Try to find who to notify:
                commit = getJSON(f'{env.CD_REPO_API_URL}/commits/{diff.head}')
                tags = ', '.join(
                    '@' + x for x in set(commit[role]['login'] for role in ('committer', 'author') if commit[role]))
                if tags:
                    diff.log('Tags: ' + tags)

    except:
        # Pipeline should not throw exceptions so if there is an Exception we log it to help with debugging
        setCommitStatus(diff.head, BuildStatus.failure, "Deployment failed due to an Exception!", diff.outputURL)
        diff.log('Important: got an exception! Pipeline should not have exceptions. Please look into this:')
        diff.log('Exception', traceback.format_exc())
        diff.log('Chart status summary:', diff.chartStatusSummary())
        raise
Example #4
0
def Developer_ValidateVersionDataJSON(modList):
    #type: (List[installConfiguration.SubModConfig]) -> None

    onDiskVersionData, error = common.getJSON("versionData.json", isURL=False)

    # reformat versionData as mapping of { versionID : set(file.id) }
    reformattedVersionData = {}  # type: Dict[str, Set[str]]
    for versionData in onDiskVersionData:
        reformattedVersionData[versionData['id']] = set(
            file['id'] for file in versionData['files'])

    failureStrings = []
    for subMod in modList:
        # The ID in the versionData.json is of the format "game/mod_variant"
        versionID = subMod.modName + '/' + subMod.subModName

        # Check versionData has a listing for this submod
        if versionID not in reformattedVersionData:
            failureStrings.append(
                "DEVELOPER ERROR: versionData.json is missing the game/submod pair: {}"
                .format(versionID))
            continue

        # Check each file in the submod exists in the versionData.json
        for file in subMod.files:
            # Items with file.url = None are not downloaded/installed, so skip them
            if file.url is None:
                continue

            if file.name not in reformattedVersionData[versionID]:
                failureStrings.append(
                    "DEVELOPER ERROR: versionData.json is missing the file: [{}] from [{}]"
                    .format(file.name, versionID))

    if failureStrings:
        raise Exception('\n'.join(failureStrings))
Example #5
0
def getLocalVersion(localVersionFilePath):
    localVersionObject, localError = common.getJSON(localVersionFilePath,
                                                    isURL=False)
    return None if localVersionObject is None else SubModVersionInfo(
        localVersionObject)