Skip to content

Commit

Permalink
Introduce build and serve commands to standardized CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
parlough committed Jan 21, 2024
1 parent 3d828d2 commit 4ccda7e
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 23 deletions.
37 changes: 27 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
- uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b
with:
sdk: ${{ matrix.sdk }}
- name: Fetch packages
- name: Fetch Dart packages
run: dart pub get
- name: Check Dart code formatting
run: dart run dart_site format-dart --check
Expand All @@ -57,25 +57,42 @@ jobs:
linkcheck:
name: Build site and check links
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
submodules: recursive
- run: make build
- uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b
with:
sdk: stable
- name: Fetch packages
- name: Fetch Dart packages
run: dart pub get
- name: Check for broken Markdown links
run: dart run dart_site check-link-references
- name: Validate the firebase.json file
run: dart run dart_site verify-firebase-json
- uses: pnpm/action-setup@ebcfd6995dade4b0104ac774445cef8b3b4635b0
with:
version: 8
- uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8
with:
node-version: ${{ env.NODE_VERSION }}
- run: npm install -g [email protected]
cache: 'pnpm'
- name: Install node dependencies
run: pnpm install
- name: Build site
run: dart run dart_site build
- name: Check for broken Markdown links
run: dart run dart_site check-link-references
- name: Check internal site links are functional
run: dart run dart_site check-links

firebase-check:
name: Check firebase declaration
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
submodules: recursive
- uses: dart-lang/setup-dart@ca7e6fee45ffbd82b555a7ebfc236d2c86439f5b
with:
sdk: stable
- name: Fetch Dart packages
run: dart pub get
- name: Validate the firebase.json file
run: dart run dart_site verify-firebase-json
14 changes: 5 additions & 9 deletions cloud_build/deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
steps:
- name: gcr.io/cloud-builders/git
args: ['submodule', 'update', '--init', '--recursive']
- name: gcr.io/cloud-builders/docker
entrypoint: '/bin/bash'
args:
- '-c'
- |-
set -e
echo "Building the website using a makefile..."
make build
make write-prod-robots
- name: gcr.io/flutter-dev-230821/firebase-ghcli
entrypoint: '/bin/bash'
args:
- '-c'
- |-
set -e
npm install
npm run prod
firebase deploy --project=dart-dev --only=hosting
options:
logging: CLOUD_LOGGING_ONLY
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
},
"scripts": {
"serve": "PRODUCTION=false eleventy --serve --incremental",
"build": "PRODUCTION=true eleventy"
"build": "PRODUCTION=false eleventy",
"prod": "PRODUCTION=true eleventy"
},
"engines": {
"node": ">=20.10.0",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tool/dart_site/lib/dart_site.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import 'package:args/command_runner.dart';

import 'src/commands/analyze_dart.dart';
import 'src/commands/build.dart';
import 'src/commands/check_all.dart';
import 'src/commands/check_link_references.dart';
import 'src/commands/check_links.dart';
import 'src/commands/format_dart.dart';
import 'src/commands/generate_effective_dart_toc.dart';
import 'src/commands/refresh_excerpts.dart';
import 'src/commands/serve.dart';
import 'src/commands/test_dart.dart';
import 'src/commands/verify_firebase_json.dart';

Expand All @@ -29,5 +31,7 @@ final class DartSiteCommandRunner extends CommandRunner<int> {
addCommand(AnalyzeDartCommand());
addCommand(TestDartCommand());
addCommand(CheckAllCommand());
addCommand(BuildSiteCommand());
addCommand(ServeSiteCommand());
}
}
42 changes: 42 additions & 0 deletions tool/dart_site/lib/src/commands/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'dart:io';

import 'package:args/command_runner.dart';

import '../utils.dart';

final class BuildSiteCommand extends Command<int> {
static const String _releaseFlag = 'release';

BuildSiteCommand() {
argParser.addFlag(
_releaseFlag,
defaultsTo: false,
help: 'Build a release build for dart.dev.',
);
}

@override
String get description => 'Build the site.';

@override
String get name => 'build';

@override
Future<int> run() async {
final productionRelease = argResults.get<bool>(_releaseFlag, false);

final process = await Process.start(
'npx',
const ['eleventy'],
environment: {
'PRODUCTION': '$productionRelease',
},
);

await stdout.addStream(process.stdout);
await stderr.addStream(process.stderr);

final processExitCode = await process.exitCode;
return processExitCode;
}
}
27 changes: 27 additions & 0 deletions tool/dart_site/lib/src/commands/serve.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'dart:io';

import 'package:args/command_runner.dart';

final class ServeSiteCommand extends Command<int> {
@override
String get description => 'Serve the site locally.';

@override
String get name => 'serve';

@override
Future<int> run() async {
final process = await Process.start(
'npx',
const ['eleventy', '--serve', '--incremental'],
environment: const {
'PRODUCTION': 'false',
},
runInShell: true,
mode: ProcessStartMode.inheritStdio,
);

final processExitCode = await process.exitCode;
return processExitCode;
}
}

0 comments on commit 4ccda7e

Please sign in to comment.