Skip to content

Commit

Permalink
[tool] Use new pub cache location for the publish command (flutter-ti…
Browse files Browse the repository at this point in the history
  • Loading branch information
swift-kim authored May 30, 2023
1 parent 604e478 commit a03e396
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
verbose: false
- name: Publish packages
if: ${{ github.event_name == 'push' }}
timeout-minutes: 5
env:
PUB_CREDENTIALS: ${{ secrets.PUB_CREDENTIALS }}
run: |
Expand Down
7 changes: 4 additions & 3 deletions tools/lib/src/build_examples_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ class BuildExamplesCommand extends PackageLoopingCommand {
BuildExamplesCommand(super.packagesDir);

@override
String get description => 'Builds all example apps.\n\n'
'This command requires "flutter-tizen" to be in your path.';
final String name = 'build-examples';

@override
String get name => 'build-examples';
final String description = 'Builds all example apps.\n\n'
'This command requires "flutter-tizen" to be in your path.';

@override
Future<PackageResult> runForPackage(RepositoryPackage package) async {
final List<String> errors = <String>[];

bool builtSomething = false;
for (final RepositoryPackage example in package.getExamples()) {
int exitCode = await processRunner.runAndStream(
Expand Down
8 changes: 4 additions & 4 deletions tools/lib/src/integration_test_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ class IntegrationTestCommand extends PackageLoopingCommand {
Recipe? _recipe;

@override
String get description =>
'Runs integration tests for plugin example apps.\n\n'
'This command requires "flutter-tizen" to be in your path.';
final String name = 'integration-test';

@override
String get name => 'integration-test';
final String description =
'Runs integration tests for plugin example apps.\n\n'
'This command requires "flutter-tizen" to be in your path.';

@override
Future<void> initializeRun() async {
Expand Down
47 changes: 24 additions & 23 deletions tools/lib/src/publish_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class PublishCommand extends PackageLoopingCommand {
static const String _pubCredentialName = 'PUB_CREDENTIALS';

@override
String get name => 'publish';
final String name = 'publish';

@override
String get description => 'Attempts to publish the given packages to pub.\n'
final String description = 'Attempts to publish the given packages to pub.\n'
'If running this on CI, an environment variable named $_pubCredentialName must be set to a String that represents the pub credential JSON.\n'
'WARNING: Do not check in the content of pub credential JSON, it should only come from secure sources.';

Expand Down Expand Up @@ -256,51 +256,52 @@ Safe to ignore if the package is deleted in this commit.
}

void _ensureValidPubCredential() {
final String credentialsPath = _credentialsPath;
final String credentialsPath =
_getCredentialsPath(platform: platform, path: path);
final File credentialFile = packagesDir.fileSystem.file(credentialsPath);
if (credentialFile.existsSync() &&
credentialFile.readAsStringSync().isNotEmpty) {
return;
}
final String? credential = io.Platform.environment[_pubCredentialName];
final String? credential = platform.environment[_pubCredentialName];
if (credential == null) {
printError('''
No pub credential available. Please check if `$credentialsPath` is valid.
If running this command on CI, you can set the pub credential content in the $_pubCredentialName environment variable.
''');
throw ToolExit(1);
}
credentialFile.createSync(recursive: true);
credentialFile.openSync(mode: FileMode.writeOnlyAppend)
..writeStringSync(credential)
..closeSync();
}
}

final String _credentialsPath = () {
String? cacheDir;
final String? pubCache = io.Platform.environment['PUB_CACHE'];
if (pubCache != null) {
cacheDir = pubCache;
} else if (io.Platform.isWindows) {
final String? appData = io.Platform.environment['APPDATA'];
if (appData == null) {
printError('"APPDATA" environment variable is not set.');
} else {
cacheDir = p.join(appData, 'Pub', 'Cache');
}
} else {
final String? home = io.Platform.environment['HOME'];
/// The path in which pub expects to find its credentials file.
String _getCredentialsPath({
required Platform platform,
required p.Context path,
}) {
// See https://github.com/dart-lang/pub/blob/master/doc/cache_layout.md#layout
String? configDir;
String? configHome = platform.environment['XDG_CONFIG_HOME'];
if (configHome == null) {
final String? home = platform.environment['HOME'];
if (home == null) {
printError('"HOME" environment variable is not set.');
} else {
cacheDir = p.join(home, '.pub-cache');
configHome = path.join(home, '.config');
}
}
if (configHome != null) {
configDir = path.join(configHome, 'dart');
}

if (cacheDir == null) {
printError('Unable to determine pub cache location');
if (configDir == null) {
printError('Unable to determine pub con location');
throw ToolExit(1);
}

return p.join(cacheDir, 'credentials.json');
}();
return path.join(configDir, 'pub-credentials.json');
}
4 changes: 2 additions & 2 deletions tools/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: flutter_tizen_plugin_tools
description: Productivity utils for flutter-tizen/plugins.
repository: https://github.com/flutter-tizen/plugins/tree/master/tools
publish_to: none
publish_to: "none"

environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=2.18.0 <4.0.0"

dependencies:
args: ^2.1.0
Expand Down

0 comments on commit a03e396

Please sign in to comment.