Skip to content

Commit 1015be0

Browse files
[tool] Ensure that publish credential path is available (flutter#3970)
When writing pub credentials, ensure that the target paths exists before trying to write the file. In the past this would have worked because the credentials were in the pub cache, and the pub cache would exist by the time the repo tooling code was running. The new location, however, is a configuration directory that is unlikely to exist before anything involving `pub` credentials has run. Should fix the latest `release` failure: https://github.com/flutter/packages/actions/runs/4949005383/jobs/8854219784
1 parent 07055aa commit 1015be0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

script/tool/lib/src/publish_command.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ If running this command on CI, you can set the pub credential content in the $_p
415415
''');
416416
throw ToolExit(1);
417417
}
418+
credentialFile.createSync(recursive: true);
418419
credentialFile.openSync(mode: FileMode.writeOnlyAppend)
419420
..writeStringSync(credential)
420421
..closeSync();

script/tool/test/publish_command_test.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,25 @@ void main() {
263263
]));
264264
});
265265

266+
test('creates credential file from envirnoment variable if necessary',
267+
() async {
268+
createFakePlugin('foo', packagesDir, examples: <String>[]);
269+
const String credentials = 'some credential';
270+
platform.environment['PUB_CREDENTIALS'] = credentials;
271+
272+
await runCapturingPrint(commandRunner, <String>[
273+
'publish',
274+
'--packages=foo',
275+
'--skip-confirmation',
276+
'--pub-publish-flags',
277+
'--server=bar'
278+
]);
279+
280+
final File credentialFile = fileSystem.file(command.credentialsPath);
281+
expect(credentialFile.existsSync(), true);
282+
expect(credentialFile.readAsStringSync(), credentials);
283+
});
284+
266285
test('throws if pub publish fails', () async {
267286
createFakePlugin('foo', packagesDir, examples: <String>[]);
268287

0 commit comments

Comments
 (0)