From 16f9528cd20159765fecd018ae87d20cee03fcac Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 14:47:52 -0600 Subject: [PATCH 01/17] dart_dev-less checks action --- .github/workflows/checks.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index f633f30..792a861 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -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 @@ -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 From a54fd25a8b0a7b9f6355a5bc21c13cf704e39b0f Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 14:49:26 -0600 Subject: [PATCH 02/17] added unit test --- .github/workflows/_test:checks.yaml | 11 ++++++++--- .../fixtures/checks/{ => with_dart_dev}/lib/main.dart | 0 .../fixtures/checks/{ => with_dart_dev}/pubspec.yaml | 2 +- .../fixtures/checks/without_dart_dev/lib/main.dart | 9 +++++++++ .../fixtures/checks/without_dart_dev/pubspec.yaml | 4 ++++ 5 files changed, 22 insertions(+), 4 deletions(-) rename __tests__/fixtures/checks/{ => with_dart_dev}/lib/main.dart (100%) rename __tests__/fixtures/checks/{ => with_dart_dev}/pubspec.yaml (74%) create mode 100644 __tests__/fixtures/checks/without_dart_dev/lib/main.dart create mode 100644 __tests__/fixtures/checks/without_dart_dev/pubspec.yaml diff --git a/.github/workflows/_test:checks.yaml b/.github/workflows/_test:checks.yaml index c4b268b..5d04471 100644 --- a/.github/workflows/_test:checks.yaml +++ b/.github/workflows/_test:checks.yaml @@ -11,15 +11,20 @@ on: - .github/workflows/_test:checks.yaml jobs: - checks: + checks-with-dart-dev: uses: ./.github/workflows/checks.yaml with: - package-path: __tests__/fixtures/checks + package-path: __tests__/fixtures/checks/with_dart_dev + + checks-without-dart-dev: + uses: ./.github/workflows/checks.yaml + with: + package-path: __tests__/fixtures/checks/without_dart_dev checks-with-additional: uses: ./.github/workflows/checks.yaml with: - package-path: __tests__/fixtures/checks + package-path: __tests__/fixtures/checks/with_dart_dev additional-checks: | echo "all good!" dart format diff --git a/__tests__/fixtures/checks/lib/main.dart b/__tests__/fixtures/checks/with_dart_dev/lib/main.dart similarity index 100% rename from __tests__/fixtures/checks/lib/main.dart rename to __tests__/fixtures/checks/with_dart_dev/lib/main.dart diff --git a/__tests__/fixtures/checks/pubspec.yaml b/__tests__/fixtures/checks/with_dart_dev/pubspec.yaml similarity index 74% rename from __tests__/fixtures/checks/pubspec.yaml rename to __tests__/fixtures/checks/with_dart_dev/pubspec.yaml index 1408ba0..745a77e 100644 --- a/__tests__/fixtures/checks/pubspec.yaml +++ b/__tests__/fixtures/checks/with_dart_dev/pubspec.yaml @@ -1,4 +1,4 @@ -name: checks_test +name: checks_test_with_dart_dev publish_to: none environment: sdk: '>=2.10.0 <3.0.0' diff --git a/__tests__/fixtures/checks/without_dart_dev/lib/main.dart b/__tests__/fixtures/checks/without_dart_dev/lib/main.dart new file mode 100644 index 0000000..d254ccd --- /dev/null +++ b/__tests__/fixtures/checks/without_dart_dev/lib/main.dart @@ -0,0 +1,9 @@ +final newVar = 'asdf'; + +String foo(int inp) { + return inp.toString(); +} + +void main() { + print(foo(4)); +} diff --git a/__tests__/fixtures/checks/without_dart_dev/pubspec.yaml b/__tests__/fixtures/checks/without_dart_dev/pubspec.yaml new file mode 100644 index 0000000..4913db1 --- /dev/null +++ b/__tests__/fixtures/checks/without_dart_dev/pubspec.yaml @@ -0,0 +1,4 @@ +name: checks_test_without_dart_dev +publish_to: none +environment: + sdk: '>=2.10.0 <3.0.0' \ No newline at end of file From 0b55d790154221321e5e7c6e3b486f48e685933c Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 15:57:31 -0600 Subject: [PATCH 03/17] support dart_dev less test --- .github/workflows/test-unit.yaml | 60 +++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index e76f2f7..f24531e 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -86,8 +86,17 @@ jobs: working-directory: ${{ inputs.package-path }} run: dart pub get + - name: Analyze Pubspec + id: analyze-pubspec + working-directory: ${{ inputs.package-path }} + run: | + echo "has-dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "has-build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "has-build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + - name: Run dart_dev unit tests working-directory: ${{ inputs.package-path }} + if: steps.analyze-pubspec.outputs.has-dart-dev == 'true' run: | args=() if [[ "${{ matrix.release-mode }}" == "true" ]]; then @@ -106,4 +115,53 @@ jobs: args+=(--test-args="${{ inputs.test-args }}") fi - timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}" ${{ inputs.test-inputs }} \ No newline at end of file + timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}" ${{ inputs.test-inputs }} + + - name: Run build_runner tests + working-directory: ${{ inputs.package-path }} + if: steps.analyze-pubspec.outputs.has-dart-dev == 'false' && steps.analyze-pubspec.outputs.has-build-runner == 'true' && steps.analyze-pubspec.outputs.has-build-test == 'true' + run: | + args=() + if [[ "${{ matrix.release-mode }}" == "true" ]]; then + args+=(--release) + fi + + if [[ "${{ inputs.browser-aggregation }}" == "true" ]]; then + echo "::error:: browser-aggregation is only supported when using dart_dev" + 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 build_runner test "${args[@]}" ${{ inputs.test-inputs }} + + - name: Run dart tests + working-directory: ${{ inputs.package-path }} + if: steps.analyze-pubspec.outputs.has-dart-dev == 'false' && steps.analyze-pubspec.outputs.has-build-runner == 'false' && steps.analyze-pubspec.outputs.has-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.browser-aggregation }}" == "true" ]]; then + echo "::error:: browser-aggregation is only supported when using dart_dev" + exit 1 + fi + + if [[ "${{ inputs.preset }}" != "" ]]; then + args+=(--platform ${{ inputs.preset }}) + fi + + if [[ "${{ inputs.test-args }}" != "" ]]; then + args+=("${{ inputs.test-args }}") + fi + + timeout ${{ inputs.timeout }}m dart test "${args[@]}" ${{ inputs.test-inputs }} \ No newline at end of file From 5c342a58687d004c081cefc2a9a515c75f4daafc Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 20:46:40 -0600 Subject: [PATCH 04/17] added unit tests and updated readme --- .github/workflows/_test:checks.yaml | 13 ++++++------- .github/workflows/_test:test-unit.yaml | 12 +++++------- README.md | 5 +++-- .../{with_dart_dev => dart-basic}/lib/main.dart | 0 .../{without_dart_dev => dart-basic}/pubspec.yaml | 2 +- .../{without_dart_dev => dart-dev}/lib/main.dart | 0 .../checks/{with_dart_dev => dart-dev}/pubspec.yaml | 2 +- .../fixtures/test-unit/build-runner/pubspec.yaml | 9 +++++++++ .../test-unit/build-runner/test/main_test.dart | 7 +++++++ .../fixtures/test-unit/dart-basic/pubspec.yaml | 7 +++++++ .../test-unit/dart-basic/test/main_test.dart | 7 +++++++ __tests__/fixtures/test-unit/dart-dev/pubspec.yaml | 8 ++++++++ .../fixtures/test-unit/dart-dev/test/main_test.dart | 7 +++++++ .../fixtures/test-unit/with-chrome/pubspec.yaml | 2 +- .../fixtures/test-unit/without-chrome/pubspec.yaml | 2 +- 15 files changed, 63 insertions(+), 20 deletions(-) rename __tests__/fixtures/checks/{with_dart_dev => dart-basic}/lib/main.dart (100%) rename __tests__/fixtures/checks/{without_dart_dev => dart-basic}/pubspec.yaml (60%) rename __tests__/fixtures/checks/{without_dart_dev => dart-dev}/lib/main.dart (100%) rename __tests__/fixtures/checks/{with_dart_dev => dart-dev}/pubspec.yaml (74%) create mode 100644 __tests__/fixtures/test-unit/build-runner/pubspec.yaml create mode 100644 __tests__/fixtures/test-unit/build-runner/test/main_test.dart create mode 100644 __tests__/fixtures/test-unit/dart-basic/pubspec.yaml create mode 100644 __tests__/fixtures/test-unit/dart-basic/test/main_test.dart create mode 100644 __tests__/fixtures/test-unit/dart-dev/pubspec.yaml create mode 100644 __tests__/fixtures/test-unit/dart-dev/test/main_test.dart diff --git a/.github/workflows/_test:checks.yaml b/.github/workflows/_test:checks.yaml index 5d04471..e68525a 100644 --- a/.github/workflows/_test:checks.yaml +++ b/.github/workflows/_test:checks.yaml @@ -11,20 +11,19 @@ on: - .github/workflows/_test:checks.yaml jobs: - checks-with-dart-dev: + checks: + strategy: + matrix: + fixture: [dart-dev, dart-basic] uses: ./.github/workflows/checks.yaml with: - package-path: __tests__/fixtures/checks/with_dart_dev + package-path: __tests__/fixtures/checks/${{ matrix.fixture }} - checks-without-dart-dev: - uses: ./.github/workflows/checks.yaml - with: - package-path: __tests__/fixtures/checks/without_dart_dev checks-with-additional: uses: ./.github/workflows/checks.yaml with: - package-path: __tests__/fixtures/checks/with_dart_dev + package-path: __tests__/fixtures/checks/dart-dev additional-checks: | echo "all good!" dart format diff --git a/.github/workflows/_test:test-unit.yaml b/.github/workflows/_test:test-unit.yaml index c353209..735dbfa 100644 --- a/.github/workflows/_test:test-unit.yaml +++ b/.github/workflows/_test:test-unit.yaml @@ -11,12 +11,10 @@ on: - .github/workflows/_test:test-unit.yaml jobs: - test-unit-without-chrome: + test-unit: + strategy: + matrix: + fixture: [with-chrome, without-chrome, dart-basic, dart-dev, build-runner] uses: ./.github/workflows/test-unit.yaml with: - package-path: __tests__/fixtures/test-unit/without-chrome - - test-unit-with-chrome: - uses: ./.github/workflows/test-unit.yaml - with: - package-path: __tests__/fixtures/test-unit/with-chrome \ No newline at end of file + package-path: __tests/fixtures/test-unit/${{ matrix.fixture }} \ No newline at end of file diff --git a/README.md b/README.md index 6453212..a582e64 100644 --- a/README.md +++ b/README.md @@ -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 @@ -26,7 +26,8 @@ jobs: build: uses: Workiva/gha-dart-oss/.github/workflows/build.yaml@v1.0.0 - # 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/test-unit.yaml@v1.0.0 ``` diff --git a/__tests__/fixtures/checks/with_dart_dev/lib/main.dart b/__tests__/fixtures/checks/dart-basic/lib/main.dart similarity index 100% rename from __tests__/fixtures/checks/with_dart_dev/lib/main.dart rename to __tests__/fixtures/checks/dart-basic/lib/main.dart diff --git a/__tests__/fixtures/checks/without_dart_dev/pubspec.yaml b/__tests__/fixtures/checks/dart-basic/pubspec.yaml similarity index 60% rename from __tests__/fixtures/checks/without_dart_dev/pubspec.yaml rename to __tests__/fixtures/checks/dart-basic/pubspec.yaml index 4913db1..5dcbb99 100644 --- a/__tests__/fixtures/checks/without_dart_dev/pubspec.yaml +++ b/__tests__/fixtures/checks/dart-basic/pubspec.yaml @@ -1,4 +1,4 @@ -name: checks_test_without_dart_dev +name: test_pubspec publish_to: none environment: sdk: '>=2.10.0 <3.0.0' \ No newline at end of file diff --git a/__tests__/fixtures/checks/without_dart_dev/lib/main.dart b/__tests__/fixtures/checks/dart-dev/lib/main.dart similarity index 100% rename from __tests__/fixtures/checks/without_dart_dev/lib/main.dart rename to __tests__/fixtures/checks/dart-dev/lib/main.dart diff --git a/__tests__/fixtures/checks/with_dart_dev/pubspec.yaml b/__tests__/fixtures/checks/dart-dev/pubspec.yaml similarity index 74% rename from __tests__/fixtures/checks/with_dart_dev/pubspec.yaml rename to __tests__/fixtures/checks/dart-dev/pubspec.yaml index 745a77e..d576078 100644 --- a/__tests__/fixtures/checks/with_dart_dev/pubspec.yaml +++ b/__tests__/fixtures/checks/dart-dev/pubspec.yaml @@ -1,4 +1,4 @@ -name: checks_test_with_dart_dev +name: test_pubspec publish_to: none environment: sdk: '>=2.10.0 <3.0.0' diff --git a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml new file mode 100644 index 0000000..9d33c6c --- /dev/null +++ b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml @@ -0,0 +1,9 @@ +name: test_pubspec +publish_to: none +environment: + sdk: '>=2.11.0 <3.0.0' + +dependencies: + test: ^1.21.1 + dart_dev: ^4.0.2 + build_runner: ^2.0.0 diff --git a/__tests__/fixtures/test-unit/build-runner/test/main_test.dart b/__tests__/fixtures/test-unit/build-runner/test/main_test.dart new file mode 100644 index 0000000..45fa263 --- /dev/null +++ b/__tests__/fixtures/test-unit/build-runner/test/main_test.dart @@ -0,0 +1,7 @@ +import 'package:test/test.dart'; + +void main() { + test('some test', () { + expect(1, 1); + }); +} \ No newline at end of file diff --git a/__tests__/fixtures/test-unit/dart-basic/pubspec.yaml b/__tests__/fixtures/test-unit/dart-basic/pubspec.yaml new file mode 100644 index 0000000..8b16af7 --- /dev/null +++ b/__tests__/fixtures/test-unit/dart-basic/pubspec.yaml @@ -0,0 +1,7 @@ +name: test_pubspec +publish_to: none +environment: + sdk: '>=2.11.0 <3.0.0' + +dependencies: + test: ^1.21.1 diff --git a/__tests__/fixtures/test-unit/dart-basic/test/main_test.dart b/__tests__/fixtures/test-unit/dart-basic/test/main_test.dart new file mode 100644 index 0000000..45fa263 --- /dev/null +++ b/__tests__/fixtures/test-unit/dart-basic/test/main_test.dart @@ -0,0 +1,7 @@ +import 'package:test/test.dart'; + +void main() { + test('some test', () { + expect(1, 1); + }); +} \ No newline at end of file diff --git a/__tests__/fixtures/test-unit/dart-dev/pubspec.yaml b/__tests__/fixtures/test-unit/dart-dev/pubspec.yaml new file mode 100644 index 0000000..3a1fa8a --- /dev/null +++ b/__tests__/fixtures/test-unit/dart-dev/pubspec.yaml @@ -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 diff --git a/__tests__/fixtures/test-unit/dart-dev/test/main_test.dart b/__tests__/fixtures/test-unit/dart-dev/test/main_test.dart new file mode 100644 index 0000000..45fa263 --- /dev/null +++ b/__tests__/fixtures/test-unit/dart-dev/test/main_test.dart @@ -0,0 +1,7 @@ +import 'package:test/test.dart'; + +void main() { + test('some test', () { + expect(1, 1); + }); +} \ No newline at end of file diff --git a/__tests__/fixtures/test-unit/with-chrome/pubspec.yaml b/__tests__/fixtures/test-unit/with-chrome/pubspec.yaml index 439b36e..7f9fd4c 100644 --- a/__tests__/fixtures/test-unit/with-chrome/pubspec.yaml +++ b/__tests__/fixtures/test-unit/with-chrome/pubspec.yaml @@ -1,4 +1,4 @@ -name: unit_test_with_chrome +name: test_pubspec publish_to: none environment: sdk: '>=2.11.0 <3.0.0' diff --git a/__tests__/fixtures/test-unit/without-chrome/pubspec.yaml b/__tests__/fixtures/test-unit/without-chrome/pubspec.yaml index a25a0ed..3a1fa8a 100644 --- a/__tests__/fixtures/test-unit/without-chrome/pubspec.yaml +++ b/__tests__/fixtures/test-unit/without-chrome/pubspec.yaml @@ -1,4 +1,4 @@ -name: unit_test +name: test_pubspec publish_to: none environment: sdk: '>=2.11.0 <3.0.0' From bb200fb076bb93b0988011f1d774fdfc625f5af2 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 20:49:19 -0600 Subject: [PATCH 05/17] fixed broken tests --- .github/workflows/_test:test-unit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/_test:test-unit.yaml b/.github/workflows/_test:test-unit.yaml index 735dbfa..00ac695 100644 --- a/.github/workflows/_test:test-unit.yaml +++ b/.github/workflows/_test:test-unit.yaml @@ -17,4 +17,4 @@ jobs: fixture: [with-chrome, without-chrome, dart-basic, dart-dev, build-runner] uses: ./.github/workflows/test-unit.yaml with: - package-path: __tests/fixtures/test-unit/${{ matrix.fixture }} \ No newline at end of file + package-path: __tests__/fixtures/test-unit/${{ matrix.fixture }} \ No newline at end of file From afbfe6f1a13ed30ea67cd3b34b06bbddcf71235a Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 20:50:38 -0600 Subject: [PATCH 06/17] updated test names --- .github/workflows/_test:checks.yaml | 1 + .github/workflows/_test:test-unit.yaml | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/_test:checks.yaml b/.github/workflows/_test:checks.yaml index e68525a..74b2a78 100644 --- a/.github/workflows/_test:checks.yaml +++ b/.github/workflows/_test:checks.yaml @@ -12,6 +12,7 @@ on: jobs: checks: + name: ${{ matrix.fixture }} strategy: matrix: fixture: [dart-dev, dart-basic] diff --git a/.github/workflows/_test:test-unit.yaml b/.github/workflows/_test:test-unit.yaml index 00ac695..5688f00 100644 --- a/.github/workflows/_test:test-unit.yaml +++ b/.github/workflows/_test:test-unit.yaml @@ -12,6 +12,7 @@ on: jobs: test-unit: + name: ${{ matrix.fixture }} strategy: matrix: fixture: [with-chrome, without-chrome, dart-basic, dart-dev, build-runner] From 27303b5e6eaa8619669dae2fe6ad325b1cc0c3d0 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Wed, 28 Aug 2024 20:53:18 -0600 Subject: [PATCH 07/17] more concice action --- .github/workflows/test-unit.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index f24531e..037ae4f 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -87,16 +87,16 @@ jobs: run: dart pub get - name: Analyze Pubspec - id: analyze-pubspec + id: pubspec working-directory: ${{ inputs.package-path }} run: | - echo "has-dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "has-build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "has-build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - name: Run dart_dev unit tests working-directory: ${{ inputs.package-path }} - if: steps.analyze-pubspec.outputs.has-dart-dev == 'true' + if: steps.pubspec.outputs.dart-dev == 'true' run: | args=() if [[ "${{ matrix.release-mode }}" == "true" ]]; then @@ -119,7 +119,7 @@ jobs: - name: Run build_runner tests working-directory: ${{ inputs.package-path }} - if: steps.analyze-pubspec.outputs.has-dart-dev == 'false' && steps.analyze-pubspec.outputs.has-build-runner == 'true' && steps.analyze-pubspec.outputs.has-build-test == 'true' + if: steps.pubspec.outputs.dart-dev == 'false' && steps.pubspec.outputs.build-runner == 'true' && steps.pubspec.outputs.build-test == 'true' run: | args=() if [[ "${{ matrix.release-mode }}" == "true" ]]; then @@ -143,7 +143,7 @@ jobs: - name: Run dart tests working-directory: ${{ inputs.package-path }} - if: steps.analyze-pubspec.outputs.has-dart-dev == 'false' && steps.analyze-pubspec.outputs.has-build-runner == 'false' && steps.analyze-pubspec.outputs.has-build-test == 'false' + if: steps.pubspec.outputs.dart-dev == 'false' && steps.pubspec.outputs.build-runner == 'false' && steps.pubspec.outputs.build-test == 'false' run: | args=() if [[ "${{ matrix.release-mode }}" == "true" ]]; then From bc4034758c9ec76c5a962ce11d8c1b65175f0fd2 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:04:37 -0700 Subject: [PATCH 08/17] simplified inputs --- .github/workflows/_test:test-unit.yaml | 1 + .github/workflows/test-unit.yaml | 77 +++++++++----------------- 2 files changed, 28 insertions(+), 50 deletions(-) diff --git a/.github/workflows/_test:test-unit.yaml b/.github/workflows/_test:test-unit.yaml index 5688f00..e345451 100644 --- a/.github/workflows/_test:test-unit.yaml +++ b/.github/workflows/_test:test-unit.yaml @@ -16,6 +16,7 @@ jobs: strategy: matrix: fixture: [with-chrome, without-chrome, dart-basic, dart-dev, build-runner] + uses: ./.github/workflows/test-unit.yaml with: package-path: __tests__/fixtures/test-unit/${{ matrix.fixture }} \ No newline at end of file diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 037ae4f..2fd9fd4 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -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 @@ -41,23 +30,32 @@ 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 + 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 + - working-directory: ${{ inputs.package-path }} + id: analyze-pubspec + run: | + echo "dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV unit: runs-on: ubuntu-latest @@ -66,7 +64,7 @@ jobs: 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 @@ -74,39 +72,28 @@ jobs: 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: Analyze Pubspec - id: pubspec + - name: Run tests with dart_dev working-directory: ${{ inputs.package-path }} - run: | - echo "dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - - - name: Run dart_dev unit tests - working-directory: ${{ inputs.package-path }} - if: steps.pubspec.outputs.dart-dev == 'true' + 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) - fi - if [[ "${{ inputs.preset }}" != "" ]]; then args+=(-P ${{ inputs.preset }}) fi @@ -115,22 +102,17 @@ jobs: args+=(--test-args="${{ inputs.test-args }}") fi - timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}" ${{ inputs.test-inputs }} + timeout ${{ inputs.timeout }}m dart run dart_dev test "${args[@]}" - - name: Run build_runner tests + - name: Run tests with build_runner working-directory: ${{ inputs.package-path }} - if: steps.pubspec.outputs.dart-dev == 'false' && steps.pubspec.outputs.build-runner == 'true' && steps.pubspec.outputs.build-test == 'true' + 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.browser-aggregation }}" == "true" ]]; then - echo "::error:: browser-aggregation is only supported when using dart_dev" - exit 1 - fi - if [[ "${{ inputs.preset }}" != "" ]]; then args+=(-P ${{ inputs.preset }}) fi @@ -139,11 +121,11 @@ jobs: args+=(-- "${{ inputs.test-args }}") fi - timeout ${{ inputs.timeout }}m dart run build_runner test "${args[@]}" ${{ inputs.test-inputs }} + timeout ${{ inputs.timeout }}m dart run build_runner test "${args[@]}" - - name: Run dart tests + - name: Run tests with dart test working-directory: ${{ inputs.package-path }} - if: steps.pubspec.outputs.dart-dev == 'false' && steps.pubspec.outputs.build-runner == 'false' && steps.pubspec.outputs.build-test == 'false' + 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 @@ -151,17 +133,12 @@ jobs: exit 1 fi - if [[ "${{ inputs.browser-aggregation }}" == "true" ]]; then - echo "::error:: browser-aggregation is only supported when using dart_dev" - exit 1 - fi - if [[ "${{ inputs.preset }}" != "" ]]; then - args+=(--platform ${{ inputs.preset }}) + args+=(-P ${{ inputs.preset }}) fi if [[ "${{ inputs.test-args }}" != "" ]]; then args+=("${{ inputs.test-args }}") fi - timeout ${{ inputs.timeout }}m dart test "${args[@]}" ${{ inputs.test-inputs }} \ No newline at end of file + timeout ${{ inputs.timeout }}m dart test "${args[@]}" \ No newline at end of file From 366df701a63a63de3df64809ff8fc6d11e440b45 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:11:32 -0700 Subject: [PATCH 09/17] added deubg --- .github/workflows/test-unit.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 2fd9fd4..00cfb56 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -57,6 +57,17 @@ jobs: echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + debug: + needs: pre + runs-on: ubuntu-latest + steps: + - name: Print outputs + run: | + echo "chrome-platform: ${{ needs.pre.outputs.chrome-platform }}" + echo "dart-dev: ${{ needs.pre.outputs.dart-dev }}" + echo "build-runner: ${{ needs.pre.outputs.build-runner }}" + echo "build-test: ${{ needs.pre.outputs.build-test }}" + unit: runs-on: ubuntu-latest needs: pre From 7c4b3e8e0edb739580f4c4313c15de3c14b6edf4 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:14:13 -0700 Subject: [PATCH 10/17] fixed broken output --- .github/workflows/test-unit.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 00cfb56..3020e9f 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -53,9 +53,9 @@ jobs: - working-directory: ${{ inputs.package-path }} id: analyze-pubspec run: | - echo "dart-dev=$(grep -q "^ dart_dev:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "build-runner=$(grep -q "^ build_runner:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV - echo "build-test=$(grep -q "^ build_test:" pubspec.yaml && echo "true" || echo "false")" >> $GITHUB_ENV + 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 debug: needs: pre From ff0eeed1188bb5b1e787398c6c9bfac6ec28acda Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:17:40 -0700 Subject: [PATCH 11/17] with command logging --- .github/workflows/test-unit.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 3020e9f..03abcee 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -113,6 +113,7 @@ jobs: 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 @@ -132,6 +133,7 @@ jobs: 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 @@ -152,4 +154,5 @@ jobs: args+=("${{ inputs.test-args }}") fi + echo "timeout ${{ inputs.timeout }}m dart test "${args[@]}"" timeout ${{ inputs.timeout }}m dart test "${args[@]}" \ No newline at end of file From 492a48eff4732e7d5f36c9204086fadbd1ed7a6c Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:19:35 -0700 Subject: [PATCH 12/17] fixed job name --- .github/workflows/test-unit.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 03abcee..7b513fa 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -71,7 +71,7 @@ jobs: unit: runs-on: ubuntu-latest needs: pre - name: ${{ matrix.release-mode && 'dev' || 'release' }} + name: ${{ matrix.release-mode && 'release' || 'dev' }} strategy: fail-fast: false matrix: From d83fdde67ae0c65b049b0194cfd671ab520e0096 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:22:04 -0700 Subject: [PATCH 13/17] fixed br fixture --- __tests__/fixtures/test-unit/build-runner/pubspec.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml index 9d33c6c..71edc07 100644 --- a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml +++ b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml @@ -5,5 +5,4 @@ environment: dependencies: test: ^1.21.1 - dart_dev: ^4.0.2 build_runner: ^2.0.0 From c399637845d4e1390970c99ccac4b28eb8790a1b Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:24:13 -0700 Subject: [PATCH 14/17] with build test --- __tests__/fixtures/test-unit/build-runner/pubspec.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml index 71edc07..f86b6dc 100644 --- a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml +++ b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml @@ -6,3 +6,4 @@ environment: dependencies: test: ^1.21.1 build_runner: ^2.0.0 + build_test: ^2.2.2 From 3d7db95fb91999c03e225736f38484635c795f95 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:25:40 -0700 Subject: [PATCH 15/17] new version --- __tests__/fixtures/test-unit/build-runner/pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml index f86b6dc..bacbef4 100644 --- a/__tests__/fixtures/test-unit/build-runner/pubspec.yaml +++ b/__tests__/fixtures/test-unit/build-runner/pubspec.yaml @@ -6,4 +6,4 @@ environment: dependencies: test: ^1.21.1 build_runner: ^2.0.0 - build_test: ^2.2.2 + build_test: ^2.2.1 From d51b7ea0d24e119b9ddc79923e0ff0fed2a64107 Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 10:28:49 -0700 Subject: [PATCH 16/17] cleaned up debug logging --- .github/workflows/test-unit.yaml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index 7b513fa..c1acd82 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -57,16 +57,12 @@ jobs: 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 - debug: - needs: pre - runs-on: ubuntu-latest - steps: - name: Print outputs run: | - echo "chrome-platform: ${{ needs.pre.outputs.chrome-platform }}" - echo "dart-dev: ${{ needs.pre.outputs.dart-dev }}" - echo "build-runner: ${{ needs.pre.outputs.build-runner }}" - echo "build-test: ${{ needs.pre.outputs.build-test }}" + 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 From 28bbf656839f7235d16606c47ed4b2dde802cc5a Mon Sep 17 00:00:00 2001 From: Matthew Nitschke Date: Fri, 30 Aug 2024 16:58:21 -0700 Subject: [PATCH 17/17] specify names --- .github/workflows/test-unit.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-unit.yaml b/.github/workflows/test-unit.yaml index c1acd82..2e37747 100644 --- a/.github/workflows/test-unit.yaml +++ b/.github/workflows/test-unit.yaml @@ -36,7 +36,8 @@ jobs: build-test: ${{ steps.analyze-pubspec.outputs.build-test }} steps: - uses: actions/checkout@v4 - - working-directory: ${{ inputs.package-path }} + - name: Analyze dart_test.yaml + working-directory: ${{ inputs.package-path }} id: analyze-dart-test run: | if [[ -f 'dart_test.yaml' ]]; then @@ -50,7 +51,8 @@ jobs: fi echo "Project does not have chrome platform config" echo "chrome-platform=false" >> $GITHUB_OUTPUT - - working-directory: ${{ inputs.package-path }} + - 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