diff --git a/.github/workflows/unsafe_website_ci.yml b/.github/workflows/unsafe_website_ci.yml index cdeac3449..fba464b75 100644 --- a/.github/workflows/unsafe_website_ci.yml +++ b/.github/workflows/unsafe_website_ci.yml @@ -151,12 +151,13 @@ jobs: flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }} channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} - - name: Build website - working-directory: website + - name: Install Sharezone CLI run: | - flutter build web \ - --web-renderer canvaskit \ - --pwa-strategy none + flutter pub global activate --source path "$CI_CD_DART_SCRIPTS_PACKAGE_PATH" + echo $(pwd)/bin >> $GITHUB_PATH + + - name: Build + run: sz build website --flavor dev - name: Deploy to Firebase Hosting (sharezone-debug) uses: FirebaseExtended/action-hosting-deploy@120e124148ab7016bec2374e5050f15051255ba2 diff --git a/.github/workflows/website_cd.yml b/.github/workflows/website_cd.yml index 3e0ccb000..b1065cea6 100644 --- a/.github/workflows/website_cd.yml +++ b/.github/workflows/website_cd.yml @@ -51,15 +51,13 @@ jobs: flutter-version: ${{ steps.fvm-config-action.outputs.FLUTTER_VERSION }} channel: ${{ steps.fvm-config-action.outputs.FLUTTER_CHANNEL }} - - name: Build - working-directory: website + - name: Install Sharezone CLI run: | - # We use the canvaskit renderer because the html renderer is a bit - # buggy. - flutter build web \ - --web-renderer canvaskit \ - --dart-define=FLAVOR=${{ matrix.environment.flavor }} \ - --pwa-strategy none + flutter pub global activate --source path "$CI_CD_DART_SCRIPTS_PACKAGE_PATH" + echo $(pwd)/bin >> $GITHUB_PATH + + - name: Build + run: sz build website --flavor ${{ matrix.environment.flavor }} - uses: FirebaseExtended/action-hosting-deploy@v0 with: diff --git a/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart b/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart new file mode 100644 index 000000000..88418d3d8 --- /dev/null +++ b/tools/sz_repo_cli/lib/src/commands/src/build_website_command.dart @@ -0,0 +1,70 @@ +// Copyright (c) 2022 Sharezone UG (haftungsbeschränkt) +// Licensed under the EUPL-1.2-or-later. +// +// You may obtain a copy of the Licence at: +// https://joinup.ec.europa.eu/software/page/eupl +// +// SPDX-License-Identifier: EUPL-1.2 + +import 'dart:io'; + +import 'package:sz_repo_cli/src/common/common.dart'; + +/// The different flavors of the website. +final _websiteFlavors = [ + 'prod', + 'dev', +]; + +class BuildWebsiteCommand extends CommandBase { + BuildWebsiteCommand(super.context) { + argParser.addOption( + flavorOptionName, + allowed: _websiteFlavors, + help: 'The flavor to build for.', + defaultsTo: 'prod', + ); + } + + static const flavorOptionName = 'flavor'; + + @override + String get description => 'Build the Sharezone website in release mode.'; + + @override + String get name => 'website'; + + @override + Future run() async { + // Is used so that runProcess commands print the command that was run. Right + // now this can't be done via an argument. + // + // This workaround should be addressed in the future. + isVerbose = true; + + await _buildWebsite(); + stdout.writeln('Build finished 🎉 '); + } + + Future _buildWebsite() async { + try { + final flavor = argResults![flavorOptionName] as String; + await processRunner.runCommand( + [ + 'fvm', + 'flutter', + 'build', + 'web', + '--release', + '--dart-define', + 'FLAVOR=$flavor', + '--pwa-strategy', + 'none', + ], + workingDirectory: repo.sharezoneWebsite.location, + ); + } catch (e) { + throw Exception('Failed to build website: $e'); + } + } +} diff --git a/tools/sz_repo_cli/lib/src/main.dart b/tools/sz_repo_cli/lib/src/main.dart index 7dbc0c411..7c18cd82e 100644 --- a/tools/sz_repo_cli/lib/src/main.dart +++ b/tools/sz_repo_cli/lib/src/main.dart @@ -20,6 +20,7 @@ import 'package:sz_repo_cli/src/commands/src/build_macos_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_runner_build_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_runner_command.dart'; import 'package:sz_repo_cli/src/commands/src/build_web_command.dart'; +import 'package:sz_repo_cli/src/commands/src/build_website_command.dart'; import 'package:sz_repo_cli/src/commands/src/check_license_headers_command.dart'; import 'package:sz_repo_cli/src/commands/src/deploy_android_command.dart'; import 'package:sz_repo_cli/src/commands/src/deploy_ios_command.dart'; @@ -71,7 +72,8 @@ Future main(List args) async { ..addSubcommand(BuildAndroidCommand(context)) ..addSubcommand(BuildMacOsCommand(context)) ..addSubcommand(BuildWebCommand(context)) - ..addSubcommand(BuildIosCommand(context))) + ..addSubcommand(BuildIosCommand(context)) + ..addSubcommand(BuildWebsiteCommand(context))) ..addCommand( BuildRunnerCommand()..addSubcommand(BuildRunnerBuild(context)));