fix: windows release build (#3168)

* refactor: build tool

* chore: update release.yml

* chore: skip creating release if already created
This commit is contained in:
Alex Wallen
2023-08-17 06:03:29 -07:00
committed by GitHub
parent 07cf7287d6
commit 103f56922f
3 changed files with 63 additions and 28 deletions

View File

@ -26,6 +26,7 @@ jobs:
cat CHANGELOG.md | sed -e '/./{H;$!d;}' -e "x;/##\ Version\ ${{ github.ref_name }}/"'!d;' >> ${{ env.RELEASE_NOTES_PATH }} cat CHANGELOG.md | sed -e '/./{H;$!d;}' -e "x;/##\ Version\ ${{ github.ref_name }}/"'!d;' >> ${{ env.RELEASE_NOTES_PATH }}
- name: Create release - name: Create release
if: github.run_number == 1
id: create_release id: create_release
uses: actions/create-release@v1 uses: actions/create-release@v1
env: env:
@ -82,9 +83,12 @@ jobs:
- name: Build Windows app - name: Build Windows app
working-directory: frontend working-directory: frontend
# the cargo make script has to be run separately because of file locking issues
run: | run: |
flutter config --enable-windows-desktop 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 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 - name: Archive Asset
uses: vimtor/action-zip@v1 uses: vimtor/action-zip@v1
@ -172,7 +176,7 @@ jobs:
working-directory: frontend working-directory: frontend
run: | run: |
flutter config --enable-macos-desktop 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 - name: Codesign AppFlowy
run: | run: |
@ -397,7 +401,7 @@ jobs:
working-directory: frontend working-directory: frontend
run: | run: |
flutter config --enable-linux-desktop 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 - name: Archive Assert
working-directory: ${{ env.LINUX_APP_RELEASE_PATH }} working-directory: ${{ env.LINUX_APP_RELEASE_PATH }}

View File

@ -9,25 +9,52 @@ Future<void> main(List<String> args) async {
const help = ''' const help = '''
A build script that modifies build assets before building the release version of AppFlowy. 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[0] (required): The subcommand to use (build, include-directives, exclude-directives, run).
args[1]: The appflowy version to be built (github ref_name). - 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, assert(args.length == numArgs,
'Expected ${numArgs}, got ${args.length}. Read the following for instructions about how to use this script.\n\n$help'); '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') { if (args[0] == '-h' || args[0] == '--help') {
stdout.write(help); stdout.write(help);
stdout.flush(); 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(), assert(await repositoryRoot.exists(),
'$repositoryRoot is an invalid directory. Please try again with a valid directory.\n\n$help'); '$repositoryRoot is an invalid directory. Please try again with a valid directory.\n\n$help');
final appVersion = args[1];
String? arch; // parse the command
if (args.length > 2) arch = args[2]; final command = args[0];
await _BuildTool( final tool =
repositoryRoot: repositoryRoot.path, BuildTool(repositoryRoot: repositoryRoot.path, appVersion: version);
appVersion: appVersion,
arch: arch, switch (command) {
).run(); 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');
}
} }

View File

@ -5,13 +5,13 @@ enum _ScanMode {
target, target,
} }
enum _ModifyMode { enum ModifyMode {
include, include,
exclude, exclude,
} }
class _BuildTool { class BuildTool {
const _BuildTool({ const BuildTool({
required this.repositoryRoot, required this.repositoryRoot,
required this.appVersion, required this.appVersion,
this.arch, this.arch,
@ -38,7 +38,7 @@ class _BuildTool {
// Determine the appropriate command based on the OS and architecture // Determine the appropriate command based on the OS and architecture
if (os == 'windows') { 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') { if (os == 'linux') {
@ -61,9 +61,9 @@ class _BuildTool {
/// Scans a file for lines between # BEGIN: EXCLUDE_IN_RELEASE and /// Scans a file for lines between # BEGIN: EXCLUDE_IN_RELEASE and
/// END: EXCLUDE_IN_RELEASE. Will add a comment to remove those assets /// END: EXCLUDE_IN_RELEASE. Will add a comment to remove those assets
/// from the build. /// from the build.
Future<void> _process_directives( Future<void> process_directives(
File file, { File file, {
required _ModifyMode mode, required ModifyMode mode,
}) async { }) async {
// Read the contents of the file into a list // Read the contents of the file into a list
var lines = await file.readAsLines(); var lines = await file.readAsLines();
@ -82,19 +82,19 @@ class _BuildTool {
} }
// Write the modified contents back to the file // 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) { switch (mode) {
case _ModifyMode.include: case ModifyMode.include:
return line.split('#').where((element) => element != '#').join(); return line.split('#').where((element) => element != '#').join();
case _ModifyMode.exclude: case ModifyMode.exclude:
return '#$line'; return '#$line';
} }
} }
Future<void> _build() async { Future<void> build() async {
final cwd = Directory.current; final cwd = Directory.current;
Directory.current = repositoryRoot; Directory.current = repositoryRoot;
@ -108,11 +108,15 @@ class _BuildTool {
Directory.current = cwd; Directory.current = cwd;
} }
Future<void> directives(ModifyMode mode) async {
await process_directives(pubspec, mode: mode);
}
Future<void> run() async { Future<void> run() async {
final pubspec = this.pubspec; final pubspec = this.pubspec;
await _process_directives(pubspec, mode: _ModifyMode.exclude); await process_directives(pubspec, mode: ModifyMode.exclude);
await _build(); await build();
await _process_directives(pubspec, mode: _ModifyMode.include); await process_directives(pubspec, mode: ModifyMode.include);
} }
} }