Skip to content

Commit

Permalink
[tool] Ensure that publish credential path is available (flutter#3970)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stuartmorgan authored and nploi committed Jul 16, 2023
1 parent ae79945 commit 39324c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions script/tool/lib/src/publish_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
19 changes: 19 additions & 0 deletions script/tool/test/publish_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,25 @@ void main() {
]));
});

test('creates credential file from envirnoment variable if necessary',
() async {
createFakePlugin('foo', packagesDir, examples: <String>[]);
const String credentials = 'some credential';
platform.environment['PUB_CREDENTIALS'] = credentials;

await runCapturingPrint(commandRunner, <String>[
'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: <String>[]);

Expand Down

0 comments on commit 39324c3

Please sign in to comment.