Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sz build website command to Sharezone Repo CLI #1350

Merged
merged 2 commits into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .github/workflows/unsafe_website_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/website_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> 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<void> _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');
}
}
}
4 changes: 3 additions & 1 deletion tools/sz_repo_cli/lib/src/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -71,7 +72,8 @@ Future<void> main(List<String> 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)));

Expand Down
Loading