diff --git a/script/tool/lib/src/publish_command.dart b/script/tool/lib/src/publish_command.dart index 717fb3b53733..eb042fb6faa5 100644 --- a/script/tool/lib/src/publish_command.dart +++ b/script/tool/lib/src/publish_command.dart @@ -415,6 +415,7 @@ If running this command on CI, you can set the pub credential content in the $_p '''); throw ToolExit(1); } + credentialFile.createSync(recursive: true); credentialFile.openSync(mode: FileMode.writeOnlyAppend) ..writeStringSync(credential) ..closeSync(); diff --git a/script/tool/test/publish_command_test.dart b/script/tool/test/publish_command_test.dart index bbee7f94a530..78daf4527d11 100644 --- a/script/tool/test/publish_command_test.dart +++ b/script/tool/test/publish_command_test.dart @@ -263,6 +263,25 @@ void main() { ])); }); + test('creates credential file from envirnoment variable if necessary', + () async { + createFakePlugin('foo', packagesDir, examples: []); + const String credentials = 'some credential'; + platform.environment['PUB_CREDENTIALS'] = credentials; + + await runCapturingPrint(commandRunner, [ + 'publish', + '--packages=foo', + '--skip-confirmation', + '--pub-publish-flags', + '--server=bar' + ]); + + final File credentialFile = fileSystem.file(command.credentialsPath); + expect(credentialFile.existsSync(), true); + expect(credentialFile.readAsStringSync(), credentials); + }); + test('throws if pub publish fails', () async { createFakePlugin('foo', packagesDir, examples: []);