[tool] Ensure that publish credential path is available (#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
This commit is contained in:
stuartmorgan
2023-05-11 12:50:00 -07:00
committed by GitHub
parent 07055aaa90
commit 1015be0916
2 changed files with 20 additions and 0 deletions

View File

@ -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>[]);