Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6afae9d

Browse files
authoredMay 6, 2025··
Revert deletion of deploy command to fix dev build (#8155)
I think this should fix the dev build, which stopped uploading back in February. It uses the command `./bin/plugin deploy --channel=dev` (see `tool/kokoro/deploy.sh`). The deletion happened in #7929. I can't test it from an internal command until these changes are in the main branch though. It could be we no longer need the dev build, but this seems like an easy enough change.
1 parent cbd0607 commit 6afae9d

File tree

3 files changed

+197
-4
lines changed

3 files changed

+197
-4
lines changed
 

‎tool/plugin/lib/plugin.dart

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Future<int> main(List<String> args) async {
2424
runner.addCommand(LintCommand(runner));
2525
runner.addCommand(GradleBuildCommand(runner));
2626
runner.addCommand(TestCommand(runner));
27+
runner.addCommand(DeployCommand(runner));
2728
runner.addCommand(GenerateCommand(runner));
2829
runner.addCommand(VerifyCommand(runner));
2930
runner.addCommand(RunIdeCommand(runner));
@@ -475,6 +476,89 @@ class GradleBuildCommand extends ProductCommand {
475476
}
476477
}
477478

479+
/// Either the --release or --channel options must be provided.
480+
/// The permanent token is read from the file specified by Kokoro.
481+
class DeployCommand extends ProductCommand {
482+
@override
483+
final BuildCommandRunner runner;
484+
485+
DeployCommand(this.runner) : super('deploy');
486+
487+
@override
488+
String get description => 'Upload the Flutter plugin to the JetBrains site.';
489+
490+
@override
491+
Future<int> doit() async {
492+
if (isReleaseMode) {
493+
if (!await performReleaseChecks(this)) {
494+
return 1;
495+
}
496+
} else if (!isDevChannel) {
497+
log('Deploy must have a --release or --channel=dev argument');
498+
return 1;
499+
}
500+
501+
var token = readTokenFromKeystore('FLUTTER_KEYSTORE_NAME');
502+
var value = 0;
503+
var originalDir = Directory.current;
504+
for (var spec in specs) {
505+
if (spec.channel != channel) continue;
506+
var filePath = releasesFilePath(spec);
507+
log("uploading $filePath");
508+
var file = File(filePath);
509+
changeDirectory(file.parent);
510+
var pluginNumber = pluginRegistryIds[spec.pluginId];
511+
value = await upload(
512+
p.basename(file.path),
513+
pluginNumber!,
514+
token,
515+
spec.channel,
516+
);
517+
if (value != 0) {
518+
return value;
519+
}
520+
}
521+
changeDirectory(originalDir);
522+
return value;
523+
}
524+
525+
void changeDirectory(Directory dir) {
526+
Directory.current = dir.path;
527+
}
528+
529+
Future<int> upload(
530+
String filePath,
531+
String pluginNumber,
532+
String token,
533+
String channel,
534+
) async {
535+
if (!File(filePath).existsSync()) {
536+
throw 'File not found: $filePath';
537+
}
538+
// See https://plugins.jetbrains.com/docs/marketplace/plugin-upload.html#PluginUploadAPI-POST
539+
// Trying to run curl directly doesn't work; something odd happens to the quotes.
540+
var cmd = '''
541+
curl
542+
-i
543+
--header "Authorization: Bearer $token"
544+
-F pluginId=$pluginNumber
545+
-F file=@$filePath
546+
-F channel=$channel
547+
https://plugins.jetbrains.com/plugin/uploadPlugin
548+
''';
549+
550+
var args = ['-c', cmd.split('\n').join(' ')];
551+
final processResult = await Process.run('sh', args);
552+
if (processResult.exitCode != 0) {
553+
log('Upload failed: ${processResult.stderr} for file: $filePath');
554+
}
555+
final out = processResult.stdout as String;
556+
var message = out.trim().split('\n').last.trim();
557+
log(message);
558+
return processResult.exitCode;
559+
}
560+
}
561+
478562
/// Generate the plugin.xml from the plugin.xml.template file. If the --release
479563
/// argument is given, create a git branch and commit the new file to it,
480564
/// assuming the release checks pass.

‎tool/plugin/lib/runner.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class BuildCommandRunner extends CommandRunner<int> {
1414
BuildCommandRunner()
1515
: super(
1616
'plugin',
17-
'A script to build and test the Flutter IntelliJ plugin.',
17+
'A script to build, test, and deploy the Flutter IntelliJ plugin.',
1818
) {
1919
argParser.addOption(
2020
'release',
@@ -79,9 +79,8 @@ org.gradle.parallel=true
7979
org.gradle.jvmargs=-Xms1024m -Xmx4048m
8080
''';
8181
final propertiesFile = File("$rootPath/gradle.properties");
82-
final source = propertiesFile.existsSync()
83-
? propertiesFile.readAsStringSync()
84-
: null;
82+
final source =
83+
propertiesFile.existsSync() ? propertiesFile.readAsStringSync() : null;
8584
propertiesFile.writeAsStringSync(contents);
8685
int result;
8786
// Using the Gradle daemon causes a strange problem.

‎tool/plugin/test/plugin_test.dart

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ void main() {
2121
expect(TestCommand(BuildCommandRunner()).name, "test");
2222
});
2323

24+
test('deploy', () {
25+
expect(DeployCommand(BuildCommandRunner()).name, "deploy");
26+
});
27+
2428
test('generate', () {
2529
expect(GenerateCommand(BuildCommandRunner()).name, "generate");
2630
});
@@ -83,6 +87,13 @@ void main() {
8387
});
8488
});
8589

90+
test('deploy', () async {
91+
var runner = makeTestRunner();
92+
await runner.run(["-r19", "-d../..", "deploy"]).whenComplete(() {
93+
buildSpecAssertions(runner, "deploy");
94+
});
95+
});
96+
8697
test('verify', () async {
8798
var runner = makeTestRunner();
8899
await runner.run(["-r19", "-d../..", "verify"]).whenComplete(() {
@@ -91,6 +102,75 @@ void main() {
91102
});
92103
});
93104

105+
group('release', () {
106+
test('simple', () async {
107+
var runner = makeTestRunner();
108+
late TestDeployCommand cmd;
109+
await runner.run(["-r19", "-d../..", "deploy"]).whenComplete(() {
110+
cmd = (runner.commands['deploy'] as TestDeployCommand);
111+
});
112+
expect(cmd.isReleaseValid, true);
113+
});
114+
115+
test('minor', () async {
116+
var runner = makeTestRunner();
117+
late TestDeployCommand cmd;
118+
await runner.run(["-r19.2", "-d../..", "deploy"]).whenComplete(() {
119+
cmd = (runner.commands['deploy'] as TestDeployCommand);
120+
});
121+
expect(cmd.isReleaseValid, true);
122+
});
123+
124+
test('patch invalid', () async {
125+
var runner = makeTestRunner();
126+
late TestDeployCommand cmd;
127+
await runner.run(["-r19.2.1", "-d../..", "deploy"]).whenComplete(() {
128+
cmd = (runner.commands['deploy'] as TestDeployCommand);
129+
});
130+
expect(cmd.isReleaseValid, false);
131+
});
132+
133+
test('non-numeric', () async {
134+
var runner = makeTestRunner();
135+
late TestDeployCommand cmd;
136+
await runner.run(["-rx19.2", "-d../..", "deploy"]).whenComplete(() {
137+
cmd = (runner.commands['deploy'] as TestDeployCommand);
138+
});
139+
expect(cmd.isReleaseValid, false);
140+
});
141+
});
142+
143+
group('deploy', () {
144+
test('clean', () async {
145+
var dir = Directory.current;
146+
var runner = makeTestRunner();
147+
await runner
148+
.run(["-r=19", "-d../..", "deploy", "--no-as", "--no-ij"])
149+
.whenComplete(() {
150+
expect(Directory.current.path, equals(dir.path));
151+
});
152+
});
153+
154+
test('without --release', () async {
155+
var runner = makeTestRunner();
156+
late TestDeployCommand cmd;
157+
await runner.run(["-d../..", "deploy"]).whenComplete(() {
158+
cmd = (runner.commands['deploy'] as TestDeployCommand);
159+
});
160+
expect(cmd.paths, orderedEquals([]));
161+
});
162+
163+
test('release paths', () async {
164+
var runner = makeTestRunner();
165+
late TestDeployCommand cmd;
166+
await runner.run(["--release=19", "-d../..", "deploy"]).whenComplete(() {
167+
cmd = (runner.commands['deploy'] as TestDeployCommand);
168+
});
169+
var specs = cmd.specs.where((s) => s.isStableChannel).toList();
170+
expect(cmd.paths.length, specs.length);
171+
});
172+
});
173+
94174
group('build', () {
95175
test('plugin.xml', () async {
96176
var runner = makeTestRunner();
@@ -175,11 +255,41 @@ BuildCommandRunner makeTestRunner() {
175255
var runner = BuildCommandRunner();
176256
runner.addCommand(TestMakeCommand(runner));
177257
runner.addCommand(TestTestCommand(runner));
258+
runner.addCommand(TestDeployCommand(runner));
178259
runner.addCommand(TestGenCommand(runner));
179260
runner.addCommand(TestVerifyCommand(runner));
180261
return runner;
181262
}
182263

264+
class TestDeployCommand extends DeployCommand {
265+
List<String> paths = <String>[];
266+
List<String> plugins = <String>[];
267+
268+
TestDeployCommand(super.runner);
269+
270+
@override
271+
bool get isTesting => true;
272+
273+
@override
274+
void changeDirectory(Directory dir) {}
275+
276+
String readTokenFile() {
277+
return "token";
278+
}
279+
280+
@override
281+
Future<int> upload(
282+
String filePath,
283+
String pluginNumber,
284+
String token,
285+
String channel,
286+
) {
287+
paths.add(filePath);
288+
plugins.add(pluginNumber);
289+
return Future(() => 0);
290+
}
291+
}
292+
183293
class TestGenCommand extends GenerateCommand {
184294
TestGenCommand(super.runner);
185295

0 commit comments

Comments
 (0)
Please sign in to comment.