Skip to content

Commit a76eb8d

Browse files
author
serverpod_cloud
committed
fix(scloud): 4323cf7d36059125d66446ee1b6e843f8c2f6b88
1 parent 83575d6 commit a76eb8d

4 files changed

Lines changed: 167 additions & 52 deletions

File tree

serverpod_cloud_cli/lib/commands/deploy/script_runner.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,25 @@ abstract class ScriptRunner {
2424
newParagraph: i == 0,
2525
);
2626

27+
int exitCode;
2728
try {
28-
await execute(
29+
exitCode = await execute(
2930
command,
3031
stderr: stderr,
3132
stdout: stdout,
3233
workingDirectory: Directory(workingDirectory),
3334
);
3435
} on Exception catch (e, stackTrace) {
35-
throw ErrorExitException('$scriptType script failed', e, stackTrace);
36+
throw ErrorExitException(
37+
'$scriptType script failed: "$command"',
38+
e,
39+
stackTrace,
40+
);
41+
}
42+
if (exitCode != 0) {
43+
throw ErrorExitException(
44+
'$scriptType script failed with exit code $exitCode: "$command"',
45+
);
3646
}
3747
}
3848
}

serverpod_cloud_cli/lib/commands/launch/launch.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ The default API domain will be: <project-id>.api.serverpod.space
418418
if (existingPreDeploy.contains(codeGenerationHook)) return;
419419

420420
final shouldAdd = await logger.confirm(
421-
'Would you like to run code generation (`serverpod generate`) before deploy?',
422-
defaultValue: true,
421+
'Add code generation (`serverpod generate`) as a pre-deploy hook?',
422+
defaultValue: false,
423423
);
424424

425425
if (!shouldAdd) return;

serverpod_cloud_cli/test_integration/commands/deploy_command_test.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,107 @@ project:
11541154
});
11551155
});
11561156

1157+
group('and scloud.yaml with failing pre-deploy script', () {
1158+
setUp(() async {
1159+
await d
1160+
.file('scloud.yaml', '''
1161+
project:
1162+
projectId: ${BucketUploadDescription.projectId}
1163+
scripts:
1164+
pre_deploy:
1165+
- echo "pre-deploy-1" > pre_deploy_output.txt
1166+
- exit 1
1167+
- echo "pre-deploy-2" > pre_deploy_output.txt
1168+
post_deploy:
1169+
- echo "post-deploy-1" > post_deploy_output.txt
1170+
''')
1171+
.create(testProjectDir);
1172+
});
1173+
1174+
group('when deploying through CLI', () {
1175+
late Future cliCommandFuture;
1176+
setUp(() async {
1177+
cliCommandFuture = cli.run([
1178+
'deploy',
1179+
'--project',
1180+
BucketUploadDescription.projectId,
1181+
'--project-dir',
1182+
testProjectDir,
1183+
]);
1184+
});
1185+
1186+
test('then command fails with ErrorExitException.', () async {
1187+
await expectLater(
1188+
cliCommandFuture,
1189+
throwsA(isA<ErrorExitException>()),
1190+
);
1191+
});
1192+
1193+
test('then subsequent pre-deploy scripts are not executed', () async {
1194+
await cliCommandFuture.catchError((final _) {});
1195+
1196+
final preDeployFile = d.dir(testProjectDir, [
1197+
d.file('pre_deploy_output.txt', contains('pre-deploy-1')),
1198+
]);
1199+
await expectLater(preDeployFile.validate(), completes);
1200+
});
1201+
1202+
test('then post-deploy scripts are not executed', () async {
1203+
await cliCommandFuture.catchError((final _) {});
1204+
1205+
final postDeployFile = d.dir(testProjectDir, [
1206+
d.nothing('post_deploy_output.txt'),
1207+
]);
1208+
await expectLater(postDeployFile.validate(), completes);
1209+
});
1210+
});
1211+
});
1212+
1213+
group('and scloud.yaml with failing post-deploy script', () {
1214+
setUp(() async {
1215+
await d
1216+
.file('scloud.yaml', '''
1217+
project:
1218+
projectId: ${BucketUploadDescription.projectId}
1219+
scripts:
1220+
post_deploy:
1221+
- echo "post-deploy-1" > post_deploy_output.txt
1222+
- exit 1
1223+
- echo "post-deploy-2" > post_deploy_output.txt
1224+
''')
1225+
.create(testProjectDir);
1226+
});
1227+
1228+
group('when deploying through CLI', () {
1229+
late Future cliCommandFuture;
1230+
setUp(() async {
1231+
cliCommandFuture = cli.run([
1232+
'deploy',
1233+
'--project',
1234+
BucketUploadDescription.projectId,
1235+
'--project-dir',
1236+
testProjectDir,
1237+
]);
1238+
});
1239+
1240+
test('then command fails with ErrorExitException.', () async {
1241+
await expectLater(
1242+
cliCommandFuture,
1243+
throwsA(isA<ErrorExitException>()),
1244+
);
1245+
});
1246+
1247+
test('then subsequent post-deploy scripts are not executed', () async {
1248+
await cliCommandFuture.catchError((final _) {});
1249+
1250+
final postDeployFile = d.dir(testProjectDir, [
1251+
d.file('post_deploy_output.txt', contains('post-deploy-1')),
1252+
]);
1253+
await expectLater(postDeployFile.validate(), completes);
1254+
});
1255+
});
1256+
});
1257+
11571258
group('and scloud.yaml with single string pre-deploy script', () {
11581259
setUp(() async {
11591260
await d

0 commit comments

Comments
 (0)