Correctly error out on failed remote builds

The push command was relying on the output from the builder to indicate
the build status, but this isn't helpful for CI. This commit makes the
remote build module respect the `isError` flag which the builder sends
in any errors. Any errors which come from the builder indicate the
release will not be deployed.

Change-type: patch
Signed-off-by: Cameron Diver <cameron@resin.io>
This commit is contained in:
Cameron Diver 2018-08-17 01:33:12 +01:00 committed by Tim Perry
parent f65e777d1b
commit ec589c2639
2 changed files with 20 additions and 2 deletions

View File

@ -156,6 +156,8 @@ export const push: CommandDefinition<
return remote.startRemoteBuild(args);
},
).nodeify(done);
)
.catch(remote.RemoteBuildFailedError, exitWithExpectedError)
.nodeify(done);
},
};

View File

@ -18,6 +18,7 @@ import * as JSONStream from 'JSONStream';
import * as request from 'request';
import { ResinSDK } from 'resin-sdk';
import * as Stream from 'stream';
import { TypedError } from 'typed-error';
import { tarDirectory } from './compose';
@ -43,17 +44,25 @@ export interface RemoteBuild {
// For internal use
releaseId?: number;
hadError?: boolean;
}
interface BuilderMessage {
message: string;
type?: string;
replace?: boolean;
isError?: boolean;
// These will be set when the type === 'metadata'
resource?: string;
value?: string;
}
export class RemoteBuildFailedError extends TypedError {
public constructor() {
super('Remote build failed');
}
}
async function getBuilderEndpoint(
baseUrl: string,
owner: string,
@ -105,7 +114,11 @@ export async function startRemoteBuild(build: RemoteBuild): Promise<void> {
stream.on('data', getBuilderMessageHandler(build));
stream.on('end', resolve);
stream.on('error', reject);
}).return();
}).then(() => {
if (build.hadError) {
throw new RemoteBuildFailedError();
}
});
}
async function handleBuilderMetadata(obj: BuilderMessage, build: RemoteBuild) {
@ -178,6 +191,9 @@ function getBuilderMessageHandler(
process.stdout.write(`\r${message}\n`);
}
}
if (obj.isError) {
build.hadError = true;
}
};
}