Skip to content

Commit

Permalink
Use env variable for workflow output (#85)
Browse files Browse the repository at this point in the history
* Add setOutput method

* Use setOutput method for save value

* removed unused import
  • Loading branch information
M97Chahboun authored Oct 16, 2022
1 parent 90ef5e1 commit 263a70a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
14 changes: 14 additions & 0 deletions workflows_utils/add_to_output.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dart:io';

Future<void> setOutput(String item) async {
Map<String, String> envVars = Platform.environment;
String? envPath = envVars["GITHUB_OUTPUT"];
File ghEnv = File(envPath!);
String currentContent = await ghEnv.readAsString();
if (currentContent.isNotEmpty) {
currentContent += "\n" "$item";
} else {
currentContent = item;
}
ghEnv.writeAsString(currentContent);
}
7 changes: 4 additions & 3 deletions workflows_utils/get_project_version.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import 'dart:io';

import 'add_to_output.dart';

main() async {
final data = File('./pubspec.yaml');
String text = data.readAsStringSync();
String currentVersion = text.substring(text.indexOf("version: ") + 9,
text.indexOf("\n", text.indexOf("version: ")));
await Process.run(
'echo "project_version=v${currentVersion.trim()}" >> \$GITHUB_OUTPUT', [],
runInShell: true);
String versionEnvVar = "project_version=v${currentVersion.trim()}";
await setOutput(versionEnvVar);
}
9 changes: 4 additions & 5 deletions workflows_utils/labels_to_track.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import 'dart:io';
import 'add_to_output.dart';

const List<String> options = ["alpha", "beta", "internal"];
Future<void> main(List<String> labels) async {
List<String> trackLabels = List.from(labels);
trackLabels.removeWhere((e) => !options.contains(e));
String track = "alpha";
String track = "track=alpha";
if (trackLabels.isNotEmpty) {
track = trackLabels.first;
track = "track=${trackLabels.first}";
}
await Process.run('echo "track=$track" >> \$GITHUB_OUTPUT', [],
runInShell: true);
await setOutput(track);
}
7 changes: 3 additions & 4 deletions workflows_utils/labels_to_version_parts.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'dart:io';
import 'add_to_output.dart';

const List<String> options = ["major", "minor", "patch"];
Future<void> main(List<String> labels) async {
Expand All @@ -7,8 +7,7 @@ Future<void> main(List<String> labels) async {
String parts = "";
if (versionParts.isNotEmpty) {
parts = versionParts.join(",");
parts = "bump:$parts";
parts = "parts=bump:$parts";
}
await Process.run('echo "parts=$parts" >> \$GITHUB_OUTPUT', [],
runInShell: true);
await setOutput(parts);
}
Empty file added workflows_utils/tst.txt
Empty file.

0 comments on commit 263a70a

Please sign in to comment.