Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: windows release build (#3168)

Alex Wallen103f56922f13
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 8fbfcc8a7b..78ed6c7d5d 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -26,6 +26,7 @@ jobs:
cat CHANGELOG.md | sed -e '/./{H;$!d;}' -e "x;/##\ Version\ ${{ github.ref_name }}/"'!d;' >> ${{ env.RELEASE_NOTES_PATH }}
- name: Create release
+ if: github.run_number == 1
id: create_release
uses: actions/create-release@v1
env:
@@ -82,9 +83,12 @@ jobs:
- name: Build Windows app
working-directory: frontend
+ # the cargo make script has to be run separately because of file locking issues
run: |
flutter config --enable-windows-desktop
+ dart ./scripts/flutter_release_build/build_flowy.dart exclude-directives . ${{ github.ref_name }}
cargo make --env APP_VERSION=${{ github.ref_name }} --profile production-windows-x86 appflowy
+ dart ./scripts/flutter_release_build/build_flowy.dart include-directives . ${{ github.ref_name }}
- name: Archive Asset
uses: vimtor/action-zip@v1
@@ -172,7 +176,7 @@ jobs:
working-directory: frontend
run: |
flutter config --enable-macos-desktop
- dart ./scripts/flutter_release_build/build_flowy.dart . ${{ github.ref_name }}
+ dart ./scripts/flutter_release_build/build_flowy.dart run . ${{ github.ref_name }}
- name: Codesign AppFlowy
run: |
@@ -397,7 +401,7 @@ jobs:
working-directory: frontend
run: |
flutter config --enable-linux-desktop
- dart ./scripts/flutter_release_build/build_flowy.dart . ${{ github.ref_name }}
+ dart ./scripts/flutter_release_build/build_flowy.dart run . ${{ github.ref_name }}
- name: Archive Assert
working-directory: ${{ env.LINUX_APP_RELEASE_PATH }}
diff --git a/frontend/scripts/flutter_release_build/build_flowy.dart b/frontend/scripts/flutter_release_build/build_flowy.dart
index 5094745e0b..4990f5cc77 100644
--- a/frontend/scripts/flutter_release_build/build_flowy.dart
+++ b/frontend/scripts/flutter_release_build/build_flowy.dart
@@ -9,25 +9,52 @@ Future<void> main(List<String> args) async {
const help = '''
A build script that modifies build assets before building the release version of AppFlowy.
-args[0]: The directory that contains the AppFlowy git repository. Should be the parent to appflowy_flutter. (absolute path)
-args[1]: The appflowy version to be built (github ref_name).
+args[0] (required): The subcommand to use (build, include-directives, exclude-directives, run).
+ - run: calls exclude-directives, build, include-directives.
+ - build: builds the release version of AppFlowy.
+ - include-directives: adds the directives from pubspec.yaml.
+ - exclude-directives: removes the directives from pubspec.yaml.
+
+args[1] (required): The repository root for appflowy (the directory containing pubspec.yaml).
+
+args[2] (required): version (only relevant for build). The version of the app to build.
+
''';
- const numArgs = 2;
+ const numArgs = 3;
assert(args.length == numArgs,
'Expected ${numArgs}, got ${args.length}. Read the following for instructions about how to use this script.\n\n$help');
if (args[0] == '-h' || args[0] == '--help') {
stdout.write(help);
stdout.flush();
}
- final repositoryRoot = Directory(args[0]);
+
+ // parse the vesrion
+ final version = args[2];
+
+ // parse the first required argument
+ final repositoryRoot = Directory(args[1]);
assert(await repositoryRoot.exists(),
'$repositoryRoot is an invalid directory. Please try again with a valid directory.\n\n$help');
- final appVersion = args[1];
- String? arch;
- if (args.length > 2) arch = args[2];
- await _BuildTool(
- repositoryRoot: repositoryRoot.path,
- appVersion: appVersion,
- arch: arch,
- ).run();
+
+ // parse the command
+ final command = args[0];
+ final tool =
+ BuildTool(repositoryRoot: repositoryRoot.path, appVersion: version);
+
+ switch (command) {
+ case 'run':
+ await tool.run();
+ break;
+ case 'build':
+ await tool.build();
+ break;
+ case 'include-directives':
+ await tool.directives(ModifyMode.include);
+ break;
+ case 'exclude-directives':
+ await tool.directives(ModifyMode.exclude);
+ break;
+ default:
+ throw StateError('Invalid command: $command');
+ }
}
diff --git a/frontend/scripts/flutter_release_build/tool.dart b/frontend/scripts/flutter_release_build/tool.dart
index 533850c77d..3872308645 100644
--- a/frontend/scripts/flutter_release_build/tool.dart
+++ b/frontend/scripts/flutter_release_build/tool.dart
@@ -5,13 +5,13 @@ enum _ScanMode {
target,
}
-enum _ModifyMode {
+enum ModifyMode {
include,
exclude,
}
-class _BuildTool {
- const _BuildTool({
+class BuildTool {
+ const BuildTool({
required this.repositoryRoot,
required this.appVersion,
this.arch,
@@ -38,7 +38,7 @@ class _BuildTool {
// Determine the appropriate command based on the OS and architecture
if (os == 'windows') {
- return 'cargo make --env APP_VERSION=$appVersion --profile production-windows-x86 appflowy';
+ return 'cargo make --env APP_VERSION=$appVersion --profile production-windows-x86 appflowy --verbose';
}
if (os == 'linux') {
@@ -61,9 +61,9 @@ class _BuildTool {
/// Scans a file for lines between # BEGIN: EXCLUDE_IN_RELEASE and
/// END: EXCLUDE_IN_RELEASE. Will add a comment to remove those assets
/// from the build.
- Future<void> _process_directives(
+ Future<void> process_directives(
File file, {
- required _ModifyMode mode,
+ required ModifyMode mode,
}) async {
// Read the contents of the file into a list
var lines = await file.readAsLines();
@@ -82,19 +82,19 @@ class _BuildTool {
}
// Write the modified contents back to the file
- await file.writeAsString(lines.join('\n'));
+ await file.writeAsString(lines.join('\n'), flush: true);
}
- String _modify(String line, {required _ModifyMode mode}) {
+ String _modify(String line, {required ModifyMode mode}) {
switch (mode) {
- case _ModifyMode.include:
+ case ModifyMode.include:
return line.split('#').where((element) => element != '#').join();
- case _ModifyMode.exclude:
+ case ModifyMode.exclude:
return '#$line';
}
}
- Future<void> _build() async {
+ Future<void> build() async {
final cwd = Directory.current;
Directory.current = repositoryRoot;
@@ -108,11 +108,15 @@ class _BuildTool {
Directory.current = cwd;
}
+ Future<void> directives(ModifyMode mode) async {
+ await process_directives(pubspec, mode: mode);
+ }
+
Future<void> run() async {
final pubspec = this.pubspec;
- await _process_directives(pubspec, mode: _ModifyMode.exclude);
- await _build();
- await _process_directives(pubspec, mode: _ModifyMode.include);
+ await process_directives(pubspec, mode: ModifyMode.exclude);
+ await build();
+ await process_directives(pubspec, mode: ModifyMode.include);
}
}