Add site environment for previews

This commit is contained in:
Simon Binder 2021-03-12 23:16:48 +01:00
parent cdb188dc5f
commit 0d378b0478
No known key found for this signature in database
GPG Key ID: 7891917E4147B8C0
5 changed files with 65 additions and 5 deletions

View File

@ -4,7 +4,7 @@ on:
pull_request:
jobs:
build:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: dart-lang/setup-dart@v1
@ -13,11 +13,10 @@ jobs:
run: dart pub get
working-directory: docs
- name: Run build
run: dart run build_runner build --release
working-directory: docs
- name: Output generated pages
env:
IS_RELEASE: ${{ github.event_name == 'push' && github.event.ref == 'refs/heads/master' }}
run: |
dart run build_runner build --release --output web:deploy
dart run tool/ci_build.dart
rm -rf deploy/packages deploy/build.manifest deploy/.dart_tool deploy/.packages
working-directory: docs
- name: Deploy to netlify

32
docs/build.deploy.yaml Normal file
View File

@ -0,0 +1,32 @@
targets:
# Preprocess css first, so that we can read generated assets in the main target (for subresource integrity)
css:
auto_apply_builders: false
builders:
sass_builder:
enabled: true
sources:
- "web/main.scss"
- "web/main.css"
$default:
dependencies: [":css"]
builders:
sass_builder:
enabled: false
build_web_compilers|entrypoint:
release_options:
# Turn of null assertions for release builds, it looks like this
# makes generated code slightly smaller.
native_null_assertions: false
dart2js_args:
- "-O4"
- "--csp"
sources:
- "lib/**"
- "pages/**"
- "templates/**"
- "web/**"
- "$package$"
- "pubspec.yaml"
- "website.yaml"

View File

@ -14,6 +14,9 @@ targets:
builders:
sass_builder:
enabled: false
built_site:
release_options:
environment: "preview"
build_web_compilers|entrypoint:
release_options:
# Turn of null assertions for release builds, it looks like this

23
docs/tool/ci_build.dart Normal file
View File

@ -0,0 +1,23 @@
import 'dart:io';
Future<void> main() async {
final isReleaseEnv = Platform.environment['IS_RELEASE'];
print('Is release build: $isReleaseEnv');
final isRelease = isReleaseEnv == '1';
final buildArgs = [
'run',
'build_runner',
'build',
'--release',
if (isRelease) '--config=deploy',
];
final build = await Process.start('dart', buildArgs,
mode: ProcessStartMode.inheritStdio);
await build.exitCode;
final generatePages = await Process.start(
'dart', [...buildArgs, '--output=web:deploy'],
mode: ProcessStartMode.inheritStdio);
await generatePages.exitCode;
}

View File

@ -37,6 +37,9 @@ environments:
dev:
minify: false
base_url: "http://localhost:8080/"
preview:
minify: true
base_url: "https://moor.simonbinder.eu/"
prod:
minify: true
base_url: "https://moor.simonbinder.eu/"