Skip to content

Commit aa229a8

Browse files
author
serverpod_cloud
committed
fix: 52ea68e9dfa24bf2836b7b4010a25a40508e7029
1 parent 9e344ef commit aa229a8

5 files changed

Lines changed: 153 additions & 51 deletions

File tree

serverpod_cloud_cli/lib/commands/deploy/prepare_workspace.dart

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ abstract class WorkspaceProject {
110110
_writeScloudRootPubspec(workspaceRootDir, includedPackagePaths);
111111
_writeProjectServerDirFile(workspaceRootDir, projectPackage.dir);
112112

113-
final serverDirPath = p.join(
114-
workspaceRootDir.path,
115-
projectPackage.dir.path,
116-
);
117-
ScloudIgnore.writeTemplateIfNotExists(rootFolder: serverDirPath);
113+
ScloudIgnore.writeTemplateIfNotExists(rootFolder: workspaceRootDir.path);
118114
}
119115

120116
static String _getPackageName(final Directory packageDirectory) {

serverpod_cloud_cli/lib/util/project_files_writer.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract final class ProjectFilesWriter {
1717
required final String projectDirectory,
1818
}) {
1919
_upsertConfigFile(projectId, preDeployScripts, configFilePath);
20-
_upsertGitIgnoreFile(projectDirectory);
20+
_upsertScloudIgnoreFile(projectDirectory);
2121
}
2222

2323
static void _upsertConfigFile(
@@ -59,11 +59,13 @@ abstract final class ProjectFilesWriter {
5959
ScloudConfigIO.writeToFile(newConfig, configFilePath);
6060
}
6161

62-
static void _upsertGitIgnoreFile(final String projectDirectory) {
62+
static void _upsertScloudIgnoreFile(final String projectDirectory) {
6363
final workspaceRootDir = _findWorkspaceRootDir(Directory(projectDirectory));
6464

6565
try {
66-
ScloudIgnore.writeTemplateIfNotExists(rootFolder: projectDirectory);
66+
ScloudIgnore.writeTemplateIfNotExists(
67+
rootFolder: workspaceRootDir?.path ?? projectDirectory,
68+
);
6769
} on Exception catch (e, s) {
6870
throw FailureException.nested(
6971
e,
@@ -74,7 +76,7 @@ abstract final class ProjectFilesWriter {
7476

7577
if (workspaceRootDir != null) {
7678
try {
77-
_updateGitIgnore(workspaceRootDir);
79+
_updateScloudIgnore(workspaceRootDir);
7880
} on Exception catch (e, s) {
7981
throw FailureException.nested(
8082
e,
@@ -97,7 +99,7 @@ abstract final class ProjectFilesWriter {
9799
return null;
98100
}
99101

100-
static bool _updateGitIgnore(final Directory workspaceRootDir) {
102+
static bool _updateScloudIgnore(final Directory workspaceRootDir) {
101103
const scloudIgnoreTemplate =
102104
'''
103105
# scloud deployment generated files should not be committed to git

serverpod_cloud_cli/test_integration/commands/deploy_command_test.dart

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -806,42 +806,47 @@ dependencies:
806806
),
807807
);
808808
});
809+
},
810+
);
809811

810-
test(
811-
'then .scloudignore is created in the server directory, not in workspace root',
812-
() async {
813-
await cliCommandFuture;
812+
group('when deploying through CLI without explicit project dir', () {
813+
late Future cliCommandFuture;
814+
setUp(() async {
815+
pushCurrentDirectory(p.join(d.sandbox, 'monorepo', 'project'));
814816

815-
final workspaceRootDir = p.join(d.sandbox, 'monorepo');
816-
final serverDir = p.join(
817-
workspaceRootDir,
818-
'project',
819-
'project_server',
820-
);
821-
final scloudIgnoreInWorkspaceRoot = p.join(
822-
workspaceRootDir,
823-
'.scloudignore',
824-
);
825-
final scloudIgnoreInServerDir = p.join(serverDir, '.scloudignore');
817+
cliCommandFuture = cli.run([
818+
'deploy',
819+
'--project',
820+
BucketUploadDescription.projectId,
821+
]);
822+
});
826823

827-
expect(
828-
File(scloudIgnoreInServerDir).existsSync(),
829-
isTrue,
830-
reason:
831-
'.scloudignore should be created in the server directory: $serverDir',
832-
);
824+
test('then command completes successfully.', () async {
825+
await expectLater(cliCommandFuture, completes);
826+
});
833827

834-
expect(
835-
File(scloudIgnoreInWorkspaceRoot).existsSync(),
836-
isFalse,
837-
reason:
838-
'.scloudignore should NOT be created in the workspace root. '
839-
'It should be in the server directory instead.',
840-
);
841-
},
842-
);
843-
},
844-
);
828+
test(
829+
'then .scloud/scloud_ws_pubspec.yaml is included in the zip archive',
830+
() async {
831+
await cliCommandFuture;
832+
833+
expect(mockFileUploader.uploadedData, isNotEmpty);
834+
835+
final archive = ZipDecoder().decodeBytes(
836+
mockFileUploader.uploadedData,
837+
);
838+
final wsPubspecFile = archive.findFile(
839+
'.scloud/scloud_ws_pubspec.yaml',
840+
);
841+
expect(
842+
wsPubspecFile,
843+
isNotNull,
844+
reason:
845+
'.scloud/scloud_ws_pubspec.yaml should be included in the deployment zip',
846+
);
847+
},
848+
);
849+
});
845850
});
846851

847852
group(

serverpod_cloud_cli/test_integration/commands/launch_command_test.dart

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ project:
278278
await expectLater(expected.validate(), completes);
279279
});
280280

281+
test('then .scloudignore is created in the project dir', () async {
282+
final expected = d.dir(testProjectDir, [
283+
d.file(
284+
'.scloudignore',
285+
contains(
286+
'This file specifies which files and directories should be ignored',
287+
),
288+
),
289+
]);
290+
await expectLater(expected.validate(), completes);
291+
});
292+
281293
test('then zipped project is accessible in bucket.', () async {
282294
await expectLater(mockFileUploader.uploadedData, isNotEmpty);
283295
});
@@ -1790,5 +1802,94 @@ dependencies:
17901802
await expectLater(expected.validate(), completes);
17911803
});
17921804
});
1805+
1806+
group(
1807+
'and a Dart workspace directory structure containing a serverpod directory',
1808+
() {
1809+
late String testProjectDir;
1810+
1811+
setUp(() async {
1812+
await d.dir('workspace_dir', [
1813+
d.file('pubspec.yaml', '''
1814+
name: workspace_package
1815+
environment:
1816+
sdk: ${ProjectFactory.validSdkVersion}
1817+
workspace:
1818+
- project_server
1819+
- project_client
1820+
'''),
1821+
d.dir('project_server', [
1822+
ProjectFactory.serverpodServerPubspec(
1823+
withResolution: 'workspace',
1824+
),
1825+
]),
1826+
d.dir('project_client', [
1827+
d.file('pubspec.yaml', '''
1828+
name: my_project_client
1829+
environment:
1830+
sdk: ${ProjectFactory.validSdkVersion}
1831+
resolution: workspace
1832+
'''),
1833+
]),
1834+
]).create();
1835+
testProjectDir = p.join(d.sandbox, 'workspace_dir', 'project_server');
1836+
});
1837+
1838+
group('when executing launch with all settings provided via args '
1839+
'and approving confirmation', () {
1840+
late Future commandResult;
1841+
setUp(() async {
1842+
logger.answerNextConfirmsWith([true, true]);
1843+
1844+
commandResult = cli.run([
1845+
'launch',
1846+
'--new-project',
1847+
projectId,
1848+
'--project-dir',
1849+
testProjectDir,
1850+
'--enable-db',
1851+
'--deploy',
1852+
]);
1853+
1854+
await commandResult;
1855+
});
1856+
1857+
test('then writes scloud.yaml file', () async {
1858+
final expected = d.dir('workspace_dir', [
1859+
d.dir('project_server', [
1860+
d.file(
1861+
'scloud.yaml',
1862+
contains('''
1863+
project:
1864+
projectId: "$projectId"
1865+
'''),
1866+
),
1867+
]),
1868+
]);
1869+
await expectLater(expected.validate(p.join(d.sandbox)), completes);
1870+
});
1871+
1872+
test(
1873+
'then .scloudignore is created in the workspace root to cover all packages',
1874+
() async {
1875+
final expected = d.dir('workspace_dir', [
1876+
d.file(
1877+
'.scloudignore',
1878+
contains(
1879+
'This file specifies which files and directories should be ignored',
1880+
),
1881+
),
1882+
d.dir('project_server', [d.nothing('.scloudignore')]),
1883+
d.dir('project_client', [d.nothing('.scloudignore')]),
1884+
]);
1885+
await expectLater(
1886+
expected.validate(p.join(d.sandbox)),
1887+
completes,
1888+
);
1889+
},
1890+
);
1891+
});
1892+
},
1893+
);
17931894
});
17941895
}

serverpod_cloud_cli/test_integration/commands/project_command/link_command_test.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -971,20 +971,18 @@ project:
971971
});
972972

973973
test(
974-
'then .scloudignore is created in the project server directory, not in workspace root',
974+
'then .scloudignore is created in the workspace root to cover all packages',
975975
() async {
976976
await commandResult;
977977
final expected = d.dir('topdir', [
978978
d.dir('workspace_dir', [
979-
d.nothing('.scloudignore'),
980-
d.dir('project_server', [
981-
d.file(
982-
'.scloudignore',
983-
contains(
984-
'This file specifies which files and directories should be ignored',
985-
),
979+
d.file(
980+
'.scloudignore',
981+
contains(
982+
'This file specifies which files and directories should be ignored',
986983
),
987-
]),
984+
),
985+
d.dir('project_server', [d.nothing('.scloudignore')]),
988986
d.dir('project_client', [d.nothing('.scloudignore')]),
989987
]),
990988
]);

0 commit comments

Comments
 (0)