Skip to content

Commit

Permalink
Merge pull request #21 from Workiva/dart_dev_less_checks
Browse files Browse the repository at this point in the history
FEA-4583: Support packages that don't utilize dart_dev
  • Loading branch information
rmconsole5-wk authored Sep 4, 2024
2 parents 1b2f4fb + 28bbf65 commit bd229c1
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 40 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/_test:checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ on:

jobs:
checks:
name: ${{ matrix.fixture }}
strategy:
matrix:
fixture: [dart-dev, dart-basic]
uses: ./.github/workflows/checks.yaml
with:
package-path: __tests__/fixtures/checks
package-path: __tests__/fixtures/checks/${{ matrix.fixture }}


checks-with-additional:
uses: ./.github/workflows/checks.yaml
with:
package-path: __tests__/fixtures/checks
package-path: __tests__/fixtures/checks/dart-dev
additional-checks: |
echo "all good!"
dart format
12 changes: 6 additions & 6 deletions .github/workflows/_test:test-unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ on:
- .github/workflows/_test:test-unit.yaml

jobs:
test-unit-without-chrome:
uses: ./.github/workflows/test-unit.yaml
with:
package-path: __tests__/fixtures/test-unit/without-chrome
test-unit:
name: ${{ matrix.fixture }}
strategy:
matrix:
fixture: [with-chrome, without-chrome, dart-basic, dart-dev, build-runner]

test-unit-with-chrome:
uses: ./.github/workflows/test-unit.yaml
with:
package-path: __tests__/fixtures/test-unit/with-chrome
package-path: __tests__/fixtures/test-unit/${{ matrix.fixture }}
14 changes: 12 additions & 2 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ jobs:
with:
sdk: ${{ inputs.sdk }}
- working-directory: ${{ inputs.package-path }}
run: dart run dart_dev analyze
run: |
if (grep -q "^ dart_dev:" pubspec.yaml); then
dart run dart_dev analyze
else
dart analyze .
fi
format:
runs-on: ubuntu-latest
Expand All @@ -38,7 +43,12 @@ jobs:
sdk: ${{ inputs.sdk }}
- name: Run format
working-directory: ${{ inputs.package-path }}
run: dart run dart_dev format --check
run: |
if (grep -q "^ dart_dev:" pubspec.yaml); then
dart run dart_dev format --check
else
dart format --output=none --set-exit-if-changed .
fi
dependency-validator:
runs-on: ubuntu-latest
Expand Down
97 changes: 72 additions & 25 deletions .github/workflows/test-unit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@ on:
documentation on presets for more information.
type: string

browser-aggregation:
description: >
Whether or not to run the test with the --browser-aggregation flag. See test_html_builder's
readme for more information: https://github.com/Workiva/test_html_builder#aggregating-browser-tests
default: false
type: boolean

test-inputs:
description: Optional path(s) to a specific test file(s) passed to the dart test command
type: string

test-args:
description: Arguments passed directly to the dart test command
type: string
Expand All @@ -41,69 +30,127 @@ jobs:
pre:
runs-on: ubuntu-latest
outputs:
has-chrome-platform: ${{ steps.analyze.outputs.HAS_CHROME_PLATFORM }}
chrome-platform: ${{ steps.analyze-dart-test.outputs.chrome-platform }}
dart-dev: ${{ steps.analyze-pubspec.outputs.dart-dev }}
build-runner: ${{ steps.analyze-pubspec.outputs.build-runner }}
build-test: ${{ steps.analyze-pubspec.outputs.build-test }}
steps:
- uses: actions/checkout@v4
- working-directory: ${{ inputs.package-path }}
id: analyze
- name: Analyze dart_test.yaml
working-directory: ${{ inputs.package-path }}
id: analyze-dart-test
run: |
if [[ -f 'dart_test.yaml' ]]; then
platforms=$(yq '.platforms[], .presets.*.platforms[]' dart_test.yaml)
if [[ "$platforms" == *"chrome"* ]]; then
echo "Project has chrome platform config"
echo "HAS_CHROME_PLATFORM=true" >> $GITHUB_OUTPUT
echo "chrome-platform=true" >> $GITHUB_OUTPUT
exit 0
fi
fi
echo "Project does not have chrome platform config"
echo "HAS_CHROME_PLATFORM=false" >> $GITHUB_OUTPUT
echo "chrome-platform=false" >> $GITHUB_OUTPUT
- name: Analyze pubspec.yaml
working-directory: ${{ inputs.package-path }}
id: analyze-pubspec
run: |
echo "dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_OUTPUT
echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_OUTPUT
echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_OUTPUT
- name: Print outputs
run: |
echo "chrome-platform: ${{ steps.analyze-dart-test.outputs.chrome-platform }}"
echo "dart-dev: ${{ steps.analyze-pubspec.outputs.dart-dev }}"
echo "build-runner: ${{ steps.analyze-pubspec.outputs.build-runner }}"
echo "build-test: ${{ steps.analyze-pubspec.outputs.build-test }}"
unit:
runs-on: ubuntu-latest
needs: pre
name: ${{ matrix.release-mode && 'dev' || 'release' }}
name: ${{ matrix.release-mode && 'release' || 'dev' }}
strategy:
fail-fast: false
matrix:
release-mode: ${{ fromJson(needs.pre.outputs.has-chrome-platform == 'true' && '[true, false]' || '[false]') }}
release-mode: ${{ fromJson(needs.pre.outputs.chrome-platform == 'true' && '[true, false]' || '[false]') }}
steps:
- uses: actions/checkout@v4
- uses: dart-lang/setup-dart@v1
with:
sdk: ${{ inputs.sdk }}

- name: Setup Chrome
if: needs.pre.outputs.has-chrome-platform == 'true'
if: needs.pre.outputs.chrome-platform == 'true'
uses: browser-actions/setup-chrome@v1
with:
chrome-version: stable

- name: Setup Chrome Alias
if: needs.pre.outputs.has-chrome-platform == 'true'
if: needs.pre.outputs.chrome-platform == 'true'
run: alias google-chrome="/opt/hostedtoolcache/chromium/stable/x64/chrome"

- name: Pub get
working-directory: ${{ inputs.package-path }}
run: dart pub get

- name: Run dart_dev unit tests
- name: Run tests with dart_dev
working-directory: ${{ inputs.package-path }}
if: needs.pre.outputs.dart-dev == 'true'
run: |
args=()
if [[ "${{ matrix.release-mode }}" == "true" ]]; then
args+=(--release)
fi
if [[ "${{ inputs.browser-aggregation }}" == "true" ]]; then
args+=(--browser-aggregation)
if [[ "${{ inputs.preset }}" != "" ]]; then
args+=(-P ${{ inputs.preset }})
fi
if [[ "${{ inputs.test-args }}" != "" ]]; then
args+=(--test-args="${{ inputs.test-args }}")
fi
echo "timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}""
timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}"
- name: Run tests with build_runner
working-directory: ${{ inputs.package-path }}
if: needs.pre.outputs.dart-dev == 'false' && needs.pre.outputs.build-runner == 'true' && needs.pre.outputs.build-test == 'true'
run: |
args=()
if [[ "${{ matrix.release-mode }}" == "true" ]]; then
args+=(--release)
fi
if [[ "${{ inputs.preset }}" != "" ]]; then
args+=(-P ${{ inputs.preset }})
fi
if [[ "${{ inputs.test-args }}" != "" ]]; then
args+=(--test-args="${{ inputs.test-args }}")
args+=(-- "${{ inputs.test-args }}")
fi
echo "timeout ${{ inputs.timeout }}m dart run build_runner test "${args[@]}""
timeout ${{ inputs.timeout }}m dart run build_runner test "${args[@]}"
- name: Run tests with dart test
working-directory: ${{ inputs.package-path }}
if: needs.pre.outputs.dart-dev == 'false' && needs.pre.outputs.build-runner == 'false' && needs.pre.outputs.build-test == 'false'
run: |
args=()
if [[ "${{ matrix.release-mode }}" == "true" ]]; then
echo "::error:: release-mode is only supported with dart_dev or build_runner"
exit 1
fi
if [[ "${{ inputs.preset }}" != "" ]]; then
args+=(-P ${{ inputs.preset }})
fi
if [[ "${{ inputs.test-args }}" != "" ]]; then
args+=("${{ inputs.test-args }}")
fi
timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}" ${{ inputs.test-inputs }}
echo "timeout ${{ inputs.timeout }}m dart test "${args[@]}""
timeout ${{ inputs.timeout }}m dart test "${args[@]}"
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Workflows for use with [Workiva's](https://github.com/Workiva) OpenSource Dart projects.

The majority of workflows assume [dart_dev](https://github.com/Workiva/dart_dev) is installed and being used within the repo
Workflows support configuration with [`dart_dev`](https://github.com/Workiva/dart_dev), [`build_runner`](https://pub.dev/packages/build_runner), and basic dart packages.


## Basic Dart CI Setup
Expand All @@ -26,7 +26,8 @@ jobs:
build:
uses: Workiva/gha-dart-oss/.github/workflows/[email protected]

# Runs unit tests in both d2js and ddc
# Runs unit tests in dev mode (vm/ddc), and optionally `--release` if executing
# against a webdev configured repo
unit-tests:
uses: Workiva/gha-dart-oss/.github/workflows/[email protected]
```
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions __tests__/fixtures/checks/dart-basic/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.10.0 <3.0.0'
9 changes: 9 additions & 0 deletions __tests__/fixtures/checks/dart-dev/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
final newVar = 'asdf';

String foo(int inp) {
return inp.toString();
}

void main() {
print(foo(4));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: checks_test
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.10.0 <3.0.0'
Expand Down
9 changes: 9 additions & 0 deletions __tests__/fixtures/test-unit/build-runner/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.11.0 <3.0.0'

dependencies:
test: ^1.21.1
build_runner: ^2.0.0
build_test: ^2.2.1
7 changes: 7 additions & 0 deletions __tests__/fixtures/test-unit/build-runner/test/main_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:test/test.dart';

void main() {
test('some test', () {
expect(1, 1);
});
}
7 changes: 7 additions & 0 deletions __tests__/fixtures/test-unit/dart-basic/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.11.0 <3.0.0'

dependencies:
test: ^1.21.1
7 changes: 7 additions & 0 deletions __tests__/fixtures/test-unit/dart-basic/test/main_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:test/test.dart';

void main() {
test('some test', () {
expect(1, 1);
});
}
8 changes: 8 additions & 0 deletions __tests__/fixtures/test-unit/dart-dev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.11.0 <3.0.0'

dependencies:
test: ^1.21.1
dart_dev: ^4.0.2
7 changes: 7 additions & 0 deletions __tests__/fixtures/test-unit/dart-dev/test/main_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import 'package:test/test.dart';

void main() {
test('some test', () {
expect(1, 1);
});
}
2 changes: 1 addition & 1 deletion __tests__/fixtures/test-unit/with-chrome/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unit_test_with_chrome
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.11.0 <3.0.0'
Expand Down
2 changes: 1 addition & 1 deletion __tests__/fixtures/test-unit/without-chrome/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unit_test
name: test_pubspec
publish_to: none
environment:
sdk: '>=2.11.0 <3.0.0'
Expand Down

0 comments on commit bd229c1

Please sign in to comment.