From 778da818d9630f64c53d6628af9c913d4d61806d Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Wed, 27 Mar 2024 12:20:53 -0700 Subject: [PATCH 1/2] Speed up / organize CI --- .github/workflows/dart_ci.yml | 173 +++------------- .github/workflows/install.yml | 49 +++++ .github/workflows/lib_ci.yml | 193 ++++++++++++++++++ .github/workflows/plugin_ci.yml | 50 +++++ .github/workflows/source-check.yml | 36 ++++ .github/workflows/validate.yml | 52 +++++ README.md | 2 +- codecov.yml | 4 + .../over_react_flux.over_react.g.dart | 2 + 9 files changed, 414 insertions(+), 147 deletions(-) create mode 100644 .github/workflows/install.yml create mode 100644 .github/workflows/lib_ci.yml create mode 100644 .github/workflows/plugin_ci.yml create mode 100644 .github/workflows/source-check.yml create mode 100644 .github/workflows/validate.yml diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 9cc4b1f88d..3cc690a80e 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -1,4 +1,4 @@ -name: Dart CI +name: CI on: push: @@ -9,159 +9,40 @@ on: branches: - '**' +permissions: + contents: read + checks: write + deployments: write + id-token: write + pull-requests: write + statuses: read + jobs: - build: - runs-on: ubuntu-latest + source-check: + uses: ./.github/workflows/source-check.yml + lib: + needs: [ source-check ] strategy: fail-fast: false matrix: # Can't run on `dev` (Dart 3) until we're fully null-safe. sdk: [ 2.18.7, 2.19.6 ] - steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.2 - with: - sdk: ${{ matrix.sdk }} - - - name: Print Dart SDK version - run: dart --version - - - id: install - name: Install dependencies - run: dart pub get - - - name: Validate dependencies - run: dart run dependency_validator - if: always() && steps.install.outcome == 'success' - - - name: Verify formatting - run: dart run dart_dev format --check - # Only run on one sdk version in case there are conflicts - if: always() && matrix.sdk != '2.18.7' && steps.install.outcome == 'success' - - # Analyze before generated files are created to verify that component boilerplate analysis is "clean" without the need for building - - name: Analyze example source (pre-build) - run: | - # Analyze lib to ensure public APIs don't depend on build-to-cache files, - # which could cause analysis issues for consumers who haven't run a build yet. - dart analyze lib - dart analyze example/boilerplate_versions - if: always() && steps.install.outcome == 'success' - - - id: build - timeout-minutes: 6 - name: Build generated files / precompile DDC assets - run: | - dart run build_runner build --delete-conflicting-outputs -o ddc_precompiled - if: always() && steps.install.outcome == 'success' - - - name: Verify that generated files are up-to-date - run: | - if [ ${{ matrix.sdk }} = '2.18.7' ]; then - git diff --exit-code - else - # Don't check these generated files for other SDKs, since they may generate differently - # due to different resolved dependencies. - git diff --exit-code -- ":(exclude)test/mockito.mocks.dart" ":(exclude)test/over_react/component_declaration/redux_component_test/test_reducer.g.dart" - fi - if: always() && steps.install.outcome == 'success' && steps.install.build == 'success' - - # Analyze again after generated files are created to verify that those generated classes don't cause analysis errors - - name: Analyze project source (post-build) - run: dart analyze - if: always() && steps.install.outcome == 'success' && steps.build.outcome == 'success' - - - name: Run tests (VM) - # Can't use build_runner (which dart_dev uses if you depend on it) to run VM tests, since we get the error: - # Unable to spawn isolate: /…/build_runner_testRU6M77/.packages: Error: Problem in packages configuration file: Unexpected character - run: dart test -P vm - if: always() && steps.install.outcome == 'success' && steps.build.outcome == 'success' - - - name: Run tests (DDC) - run: dart test --precompiled ddc_precompiled -P dartdevc - if: always() && steps.install.outcome == 'success' && steps.build.outcome == 'success' - - - name: Run tests (dart2js) - run: dart run dart_dev test --build-args="-r" -P dart2js - if: always() && steps.install.outcome == 'success' && steps.build.outcome == 'success' - - validate_analyzer: - runs-on: ubuntu-latest + uses: ./.github/workflows/lib_ci.yml + with: + sdk: ${{ matrix.sdk }} + # Only generate coverage for the latest SDK we support + gen_coverage: ${{ matrix.sdk == '2.19.6' }} + run_dart_checks: ${{ needs.source-check.outputs.run_dart_checks == 'true' }} + is_tag_build: ${{ needs.source-check.outputs.is_tag_build == 'true' }} + + analyzer-plugin: + needs: [ source-check ] + if: ${{ needs.source-check.outputs.is_tag_build == 'false' && needs.source-check.outputs.run_dart_checks == 'true' }} strategy: fail-fast: false matrix: # Can't run on `dev` (Dart 3) until we're fully null-safe. - sdk: [ 2.18.7, 2.19.6 ] - analyzer: - # We only have one version currently, but we'll leave this CI step in place - # for the next time we need to support multiple analyzer versions. - - ^5.1.0 - steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.2 - with: - sdk: ${{ matrix.sdk }} - - - name: Print Dart SDK version - run: dart --version - - - name: Update analyzer constraint to ${{ matrix.analyzer }} and validate `dart pub get` can resolve - id: resolve - run: | - dart tool/set_analyzer_constraint.dart "${{ matrix.analyzer }}" - # Show the updated version constraint - git diff pubspec.yaml - dart pub get - - - name: Analyze package source - run: dart analyze . - - - name: Verify builder runs without errors - run: dart run build_runner build --build-filter='**.dart' --delete-conflicting-outputs - - - name: Run builder tests - run: dart test -p vm -- test/vm_tests/builder - - analyzer_plugin: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ./tools/analyzer_plugin - strategy: - fail-fast: false - matrix: - # Can't run on `stable` (Dart 3) until we're fully null-safe. sdk: [ 2.19.6 ] - steps: - - uses: actions/checkout@v2 - - uses: dart-lang/setup-dart@v0.2 - with: - sdk: ${{ matrix.sdk }} - - - name: Print Dart SDK version - run: dart --version - - - id: link - name: Override over_react dependency with local path - run: cd ../.. && dart pub get && dart tool/travis_link_plugin_deps.dart - - - id: install - name: Install dependencies - run: dart pub get - if: always() && steps.link.outcome == 'success' - - - name: Validate dependencies - run: dart run dependency_validator - if: always() && steps.install.outcome == 'success' - - - name: Analyze - run: dart run dart_dev analyze - if: always() && steps.install.outcome == 'success' - - - name: Verify formatting - run: dart run dart_dev format --check - if: always() && matrix.sdk == '2.7.2' && steps.install.outcome == 'success' - - - name: Run tests - run: dart run dart_dev test - if: always() && steps.install.outcome == 'success' + uses: ./.github/workflows/plugin_ci.yml + with: + sdk: ${{ matrix.sdk }} \ No newline at end of file diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml new file mode 100644 index 0000000000..1f6ec29fb6 --- /dev/null +++ b/.github/workflows/install.yml @@ -0,0 +1,49 @@ +name: Shared install / pub cache job + +on: + workflow_call: + inputs: + sdk: + required: true + type: string + gen_coverage: + required: true + type: boolean + store_lockfile: + required: true + type: boolean + +jobs: + pub-get: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Check pub cache + id: cache + uses: actions/cache@v4 + with: + path: .dart_tool + key: ${{ runner.os }};${{ hashFiles('**/pubspec.yaml','**/pubspec.lock') || 'none' }}@${{ inputs.sdk }} + + - id: install + name: Install dependencies + run: dart pub get + + - name: Upload pubspec.lock + if: ${{ inputs.store_lockfile }} + uses: actions/upload-artifact@v4 + with: + name: pubspec.lock@${{ inputs.sdk }} + path: pubspec.lock + + - name: Upload Package Config + if: ${{ inputs.gen_coverage }} + uses: actions/upload-artifact@v4 + with: + name: package_config@${{ inputs.sdk }} + path: .dart_tool/package_config.json + retention-days: 1 \ No newline at end of file diff --git a/.github/workflows/lib_ci.yml b/.github/workflows/lib_ci.yml new file mode 100644 index 0000000000..58123c6d7c --- /dev/null +++ b/.github/workflows/lib_ci.yml @@ -0,0 +1,193 @@ +name: Jobs pertaining to the over_react library + +on: + workflow_call: + inputs: + sdk: + required: true + type: string + gen_coverage: + required: true + type: boolean + run_dart_checks: + required: true + type: boolean + is_tag_build: + required: true + type: boolean + +permissions: + contents: read + checks: write + deployments: write + id-token: write + pull-requests: write + statuses: read + +jobs: + install: + uses: ./.github/workflows/install.yml + with: + sdk: ${{ inputs.sdk }} + gen_coverage: ${{ inputs.gen_coverage }} + store_lockfile: true + + validate: + uses: ./.github/workflows/validate.yml + needs: [ install ] + with: + sdk: ${{ inputs.sdk }} + + build-ddc: + needs: [ install ] + if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - id: build + timeout-minutes: 6 + name: Build generated files / precompile DDC assets + run: | + dart run build_runner build --delete-conflicting-outputs + + - name: Verify that generated files are up-to-date + run: | + if [ ${{ inputs.sdk }} = '2.18.7' ]; then + git diff --exit-code + else + # Don't check these generated files for other SDKs, since they may generate differently + # due to different resolved dependencies. + git diff --exit-code -- ":(exclude)test/mockito.mocks.dart" ":(exclude)test/over_react/component_declaration/redux_component_test/test_reducer.g.dart" + fi + if: steps.build.outcome == 'success' + + # Analyze again after generated files are created to verify that those generated classes don't cause analysis errors + - name: Analyze project source (post-build) + run: dart analyze + if: steps.build.outcome == 'success' + + test-dart2js: + needs: [ install ] + if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Run tests (dart2js) + run: dart run dart_dev test --build-args="-r" -P dart2js + + test-vm: + needs: [ install ] + if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Run tests (VM) + # Can't use build_runner (which dart_dev uses if you depend on it) to run VM tests, since we get the error: + # Unable to spawn isolate: /…/build_runner_testRU6M77/.packages: Error: Problem in packages configuration file: Unexpected character + run: dart test -P vm + + test-ddc: + runs-on: ubuntu-latest + needs: [ install ] + # Run on a tag build no matter what so that coverage is generated for that commit + if: ${{ (inputs.is_tag_build && inputs.gen_coverage) || inputs.run_dart_checks }} + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Run tests (DDC) + if: ${{ !inputs.gen_coverage }} + run: dart run dart_dev test -P dartdevc + + - name: Run tests (DDC + coverage) + if: ${{ inputs.gen_coverage }} + run: dart run dart_dev test --test-args="--coverage=reports/coverage" -P dartdevc + + - name: Upload Coverage Data + if: ${{ inputs.gen_coverage }} + uses: actions/upload-artifact@v4 + with: + name: coverage + path: reports/coverage + + generate-coverage: + runs-on: ubuntu-latest + needs: [ install, test-ddc ] + if: ${{ inputs.gen_coverage }} + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + - name: Download Package Config + uses: actions/download-artifact@v4 + with: + name: package_config@${{ inputs.sdk }} + path: .dart_tool + - name: Download Coverage Data + uses: actions/download-artifact@v4 + with: + name: coverage + path: reports/coverage + - name: Activate Coverage Package + run: dart pub global activate coverage + - name: Format Coverage + run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o reports/coverage/lcov.info -i reports/coverage + - name: Upload Formatted Coverage as Artifact + uses: actions/upload-artifact@v4 + with: + name: lcov.info + path: reports/coverage/lcov.info + - name: Upload Coverage to codecov.io + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: reports/coverage/lcov.info + + validate_analyzer: + needs: [ install ] + if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + analyzer: + # We only have one version currently, but we'll leave this CI step in place + # for the next time we need to support multiple analyzer versions. + - ^5.1.0 + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Update analyzer constraint to ${{ matrix.analyzer }} and validate `dart pub get` can resolve + id: resolve + run: | + dart tool/set_analyzer_constraint.dart "${{ matrix.analyzer }}" + # Show the updated version constraint + git diff pubspec.yaml + dart pub get + + - name: Analyze package source + run: dart analyze . + + - name: Verify builder runs without errors + run: dart run build_runner build --build-filter='**.dart' --delete-conflicting-outputs + + - name: Run builder tests + run: dart test -p vm -- test/vm_tests/builder \ No newline at end of file diff --git a/.github/workflows/plugin_ci.yml b/.github/workflows/plugin_ci.yml new file mode 100644 index 0000000000..4ac66548f7 --- /dev/null +++ b/.github/workflows/plugin_ci.yml @@ -0,0 +1,50 @@ +name: Jobs pertaining to the analyzer plugin + +on: + workflow_call: + inputs: + sdk: + required: true + type: string + +permissions: + contents: read + checks: write + deployments: write + id-token: write + pull-requests: write + statuses: read + +jobs: + test: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./tools/analyzer_plugin + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - id: link + name: Override over_react dependency with local path + run: cd ../.. && dart pub get && dart tool/travis_link_plugin_deps.dart + + - id: install + name: Install dependencies + run: dart pub get + if: steps.link.outcome == 'success' + + - name: Validate dependencies + run: dart run dependency_validator + if: steps.install.outcome == 'success' + + - name: Verify formatting + run: dart run dart_dev format --check + # Skip this for now as it seems this has not been run in CI for some time (lots of unformatted files) + if: false && steps.install.outcome == 'success' + + - name: Run tests + run: dart run dart_dev test --test-args="--concurrency=4" + if: steps.install.outcome == 'success' diff --git a/.github/workflows/source-check.yml b/.github/workflows/source-check.yml new file mode 100644 index 0000000000..a7f6bfdc07 --- /dev/null +++ b/.github/workflows/source-check.yml @@ -0,0 +1,36 @@ +name: Source check + +on: + workflow_call: + outputs: + is_tag_build: + description: "Whether the build is the result of a tagged release commit" + value: ${{ jobs.git-diff.outputs.is_tag_build }} + run_dart_checks: + description: "Whether to run checks designed for when dart source files are changed" + value: ${{ jobs.git-diff.outputs.run_dart_checks }} + +jobs: + git-diff: + runs-on: ubuntu-latest + outputs: + run_dart_checks: ${{ steps.check_files.outputs.run_dart_checks }} + is_tag_build: ${{ steps.check_gh_ref.outputs.is_tag_build }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + - name: Check Github Ref + id: check_gh_ref + run: | + echo "is_tag_build=${{ contains(github.head_ref, 'refs/tags') }}" >> "$GITHUB_OUTPUT" + - name: Check Modified Files + id: check_files + run: | + if ! [ -z "$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | grep -E ".*\.(dart|yaml|lock)")" ]; then + echo "Dart/Yaml/Lock File(s) Were Modified. Run Dart Checks." + echo "run_dart_checks=true" >> "$GITHUB_OUTPUT" + else + echo "No Dart/Yaml/Lock File(s) Were Modified. Skip Dart Checks." + echo "run_dart_checks=false" >> "$GITHUB_OUTPUT" + fi \ No newline at end of file diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000000..ab72e0da1f --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,52 @@ +name: Dependency / formatting validation + +on: + workflow_call: + inputs: + sdk: + required: true + type: string + +jobs: + validate-dependencies: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Validate dependencies + run: dart run dependency_validator + + validate-formatting: + runs-on: ubuntu-latest + # Only run on one sdk version in case there are conflicts + if: inputs.sdk != '2.18.7' + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Verify formatting + run: dart run dart_dev format --check + + analysis-pre-build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + - id: install + name: Install dependencies + run: dart pub get + + # Analyze before generated files are created to verify that component boilerplate analysis is "clean" without the need for building + - name: Analyze example source (pre-build) + run: | + # Analyze lib to ensure public APIs don't depend on build-to-cache files, + # which could cause analysis issues for consumers who haven't run a build yet. + dart analyze lib + dart analyze example/boilerplate_versions \ No newline at end of file diff --git a/README.md b/README.md index 7ecc24ab20..39c884616e 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This library also exposes _OverReact Redux_, which has [its own documentation](d [![OverReact Analyzer Plugin (beta)](https://img.shields.io/badge/docs-analyzer_plugin_(beta)-ff69b4.svg)](https://workiva.github.io/over_react/analyzer_plugin/) [![Join the gitter chat](https://badges.gitter.im/over_react/Lobby.svg)][gitter-chat] -[![Dart CI](https://github.com/Workiva/over_react/workflows/Dart%20CI/badge.svg?branch=master)](https://github.com/Workiva/over_react/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster) +[![Dart CI](https://github.com/Workiva/over_react/workflows/CI/badge.svg?branch=master)](https://github.com/Workiva/over_react/actions?query=workflow%3A%22Dart+CI%22+branch%3Amaster) --- diff --git a/codecov.yml b/codecov.yml index 8078d6cd3b..fdf5804036 100644 --- a/codecov.yml +++ b/codecov.yml @@ -4,3 +4,7 @@ coverage: round: up ignore: - web/.* + - "**/*.over_react.g.dart" + - "**/*dummy*" + - "**/devtools" + - "lib/src/component_declaration/annotations.dart" diff --git a/lib/src/over_react_redux/over_react_flux.over_react.g.dart b/lib/src/over_react_redux/over_react_flux.over_react.g.dart index afd92756da..f3887e9e70 100644 --- a/lib/src/over_react_redux/over_react_flux.over_react.g.dart +++ b/lib/src/over_react_redux/over_react_flux.over_react.g.dart @@ -16,11 +16,13 @@ abstract class ConnectFluxPropsMixin /// @override + @disableRequiredPropValidation TActions get actions => (props[_$key__actions___$ConnectFluxPropsMixin] ?? null) as TActions; /// @override + @disableRequiredPropValidation set actions(TActions value) => props[_$key__actions___$ConnectFluxPropsMixin] = value; /* GENERATED CONSTANTS */ From 8ff5d8c7d426c8fb17e0b378e1a60078e28c58f5 Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Mon, 1 Apr 2024 17:16:58 -0700 Subject: [PATCH 2/2] Try caching coverage --- .github/workflows/coverage.yml | 82 ++++++++++++++++++++++ .github/workflows/dart_ci.yml | 9 +-- .github/workflows/install.yml | 7 +- .github/workflows/lib_ci.yml | 107 +++++------------------------ .github/workflows/plugin_ci.yml | 8 --- .github/workflows/source-check.yml | 9 +++ .github/workflows/validate.yml | 38 +++++++++- 7 files changed, 148 insertions(+), 112 deletions(-) create mode 100644 .github/workflows/coverage.yml diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000000..4fdac407de --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,82 @@ +name: Unit test coverage + +on: + workflow_call: + inputs: + sdk: + required: true + type: string + previous_commit_sha: + required: true + type: string + use_cached_coverage: + required: true + type: boolean + +jobs: + test-ddc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - name: Run Tests (DDC + coverage) + if: ${{ !inputs.use_cached_coverage }} + run: dart run dart_dev test --test-args="--coverage=reports/coverage" -P dartdevc + + - name: Upload New Coverage Data + if: ${{ !inputs.use_cached_coverage }} + uses: actions/upload-artifact@v4 + with: + name: coverage + path: reports/coverage + + generate-coverage: + runs-on: ubuntu-latest + needs: [ test-ddc ] + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + - name: Download Package Config + uses: actions/download-artifact@v4 + with: + name: package_config@${{ inputs.sdk }} + path: .dart_tool + + - name: Download New Coverage Data + if: ${{ !inputs.use_cached_coverage }} + uses: actions/download-artifact@v4 + with: + name: coverage + path: reports/coverage + + - name: Download Cached Coverage Data + if: ${{ inputs.use_cached_coverage }} + uses: actions/cache/restore@v4 + with: + path: | + reports/coverage + key: coverage@${{ inputs.previous_commit_sha }} + + - name: Activate Coverage Package + run: dart pub global activate coverage + + - name: Format Coverage + run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o reports/coverage/lcov.info -i reports/coverage + + - name: Cache Coverage Data + uses: actions/cache/save@v4 + with: + path: | + reports/coverage + key: coverage@${{ github.sha }} + + - name: Report Coverage + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: reports/coverage/lcov.info \ No newline at end of file diff --git a/.github/workflows/dart_ci.yml b/.github/workflows/dart_ci.yml index 3cc690a80e..90605ed6ed 100644 --- a/.github/workflows/dart_ci.yml +++ b/.github/workflows/dart_ci.yml @@ -9,14 +9,6 @@ on: branches: - '**' -permissions: - contents: read - checks: write - deployments: write - id-token: write - pull-requests: write - statuses: read - jobs: source-check: uses: ./.github/workflows/source-check.yml @@ -34,6 +26,7 @@ jobs: gen_coverage: ${{ matrix.sdk == '2.19.6' }} run_dart_checks: ${{ needs.source-check.outputs.run_dart_checks == 'true' }} is_tag_build: ${{ needs.source-check.outputs.is_tag_build == 'true' }} + previous_commit_sha: ${{ needs.source-check.outputs.previous_commit_sha }} analyzer-plugin: needs: [ source-check ] diff --git a/.github/workflows/install.yml b/.github/workflows/install.yml index 1f6ec29fb6..379c3438b6 100644 --- a/.github/workflows/install.yml +++ b/.github/workflows/install.yml @@ -6,8 +6,9 @@ on: sdk: required: true type: string - gen_coverage: - required: true + store_package_config: + required: false + default: false type: boolean store_lockfile: required: true @@ -41,7 +42,7 @@ jobs: path: pubspec.lock - name: Upload Package Config - if: ${{ inputs.gen_coverage }} + if: ${{ inputs.store_package_config }} uses: actions/upload-artifact@v4 with: name: package_config@${{ inputs.sdk }} diff --git a/.github/workflows/lib_ci.yml b/.github/workflows/lib_ci.yml index 58123c6d7c..425755c65f 100644 --- a/.github/workflows/lib_ci.yml +++ b/.github/workflows/lib_ci.yml @@ -15,21 +15,16 @@ on: is_tag_build: required: true type: boolean - -permissions: - contents: read - checks: write - deployments: write - id-token: write - pull-requests: write - statuses: read + previous_commit_sha: + required: true + type: string jobs: install: uses: ./.github/workflows/install.yml with: sdk: ${{ inputs.sdk }} - gen_coverage: ${{ inputs.gen_coverage }} + store_package_config: ${{ inputs.gen_coverage }} store_lockfile: true validate: @@ -37,38 +32,7 @@ jobs: needs: [ install ] with: sdk: ${{ inputs.sdk }} - - build-ddc: - needs: [ install ] - if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: dart-lang/setup-dart@v1 - with: - sdk: ${{ inputs.sdk }} - - - id: build - timeout-minutes: 6 - name: Build generated files / precompile DDC assets - run: | - dart run build_runner build --delete-conflicting-outputs - - - name: Verify that generated files are up-to-date - run: | - if [ ${{ inputs.sdk }} = '2.18.7' ]; then - git diff --exit-code - else - # Don't check these generated files for other SDKs, since they may generate differently - # due to different resolved dependencies. - git diff --exit-code -- ":(exclude)test/mockito.mocks.dart" ":(exclude)test/over_react/component_declaration/redux_component_test/test_reducer.g.dart" - fi - if: steps.build.outcome == 'success' - - # Analyze again after generated files are created to verify that those generated classes don't cause analysis errors - - name: Analyze project source (post-build) - run: dart analyze - if: steps.build.outcome == 'success' + run_ddc_build: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} test-dart2js: needs: [ install ] @@ -99,66 +63,27 @@ jobs: run: dart test -P vm test-ddc: - runs-on: ubuntu-latest needs: [ install ] - # Run on a tag build no matter what so that coverage is generated for that commit - if: ${{ (inputs.is_tag_build && inputs.gen_coverage) || inputs.run_dart_checks }} + if: ${{ !inputs.gen_coverage && !inputs.is_tag_build && inputs.run_dart_checks }} + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: dart-lang/setup-dart@v1 with: sdk: ${{ inputs.sdk }} - - - name: Run tests (DDC) - if: ${{ !inputs.gen_coverage }} + - name: Run run: dart run dart_dev test -P dartdevc - - name: Run tests (DDC + coverage) - if: ${{ inputs.gen_coverage }} - run: dart run dart_dev test --test-args="--coverage=reports/coverage" -P dartdevc - - - name: Upload Coverage Data - if: ${{ inputs.gen_coverage }} - uses: actions/upload-artifact@v4 - with: - name: coverage - path: reports/coverage - - generate-coverage: - runs-on: ubuntu-latest - needs: [ install, test-ddc ] + test-coverage: + needs: [ install ] if: ${{ inputs.gen_coverage }} - steps: - - uses: actions/checkout@v4 - - uses: dart-lang/setup-dart@v1 - with: - sdk: ${{ inputs.sdk }} - - name: Download Package Config - uses: actions/download-artifact@v4 - with: - name: package_config@${{ inputs.sdk }} - path: .dart_tool - - name: Download Coverage Data - uses: actions/download-artifact@v4 - with: - name: coverage - path: reports/coverage - - name: Activate Coverage Package - run: dart pub global activate coverage - - name: Format Coverage - run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -o reports/coverage/lcov.info -i reports/coverage - - name: Upload Formatted Coverage as Artifact - uses: actions/upload-artifact@v4 - with: - name: lcov.info - path: reports/coverage/lcov.info - - name: Upload Coverage to codecov.io - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} - files: reports/coverage/lcov.info + uses: ./.github/workflows/coverage + with: + sdk: ${{ inputs.sdk }} + previous_commit_sha: ${{ inputs.previous_commit_sha }} + use_cached_coverage: ${{ inputs.is_tag_build && inputs.gen_coverage }} - validate_analyzer: + validate-analyzer-5: needs: [ install ] if: ${{ !inputs.is_tag_build && inputs.run_dart_checks }} runs-on: ubuntu-latest diff --git a/.github/workflows/plugin_ci.yml b/.github/workflows/plugin_ci.yml index 4ac66548f7..15e2a554e2 100644 --- a/.github/workflows/plugin_ci.yml +++ b/.github/workflows/plugin_ci.yml @@ -7,14 +7,6 @@ on: required: true type: string -permissions: - contents: read - checks: write - deployments: write - id-token: write - pull-requests: write - statuses: read - jobs: test: runs-on: ubuntu-latest diff --git a/.github/workflows/source-check.yml b/.github/workflows/source-check.yml index a7f6bfdc07..d433cc746e 100644 --- a/.github/workflows/source-check.yml +++ b/.github/workflows/source-check.yml @@ -3,6 +3,9 @@ name: Source check on: workflow_call: outputs: + previous_commit_sha: + description: "git rev-parse HEAD~ (so we can retrieve a cached copy of code coverage on tag commits)" + value: ${{ jobs.git-diff.outputs.previous_commit_sha }} is_tag_build: description: "Whether the build is the result of a tagged release commit" value: ${{ jobs.git-diff.outputs.is_tag_build }} @@ -14,6 +17,7 @@ jobs: git-diff: runs-on: ubuntu-latest outputs: + previous_commit_sha: ${{ steps.rev-parse.outputs.previous_commit_sha }} run_dart_checks: ${{ steps.check_files.outputs.run_dart_checks }} is_tag_build: ${{ steps.check_gh_ref.outputs.is_tag_build }} steps: @@ -24,6 +28,11 @@ jobs: id: check_gh_ref run: | echo "is_tag_build=${{ contains(github.head_ref, 'refs/tags') }}" >> "$GITHUB_OUTPUT" + - name: Get Previous Commit Sha + id: rev-parse + shell: bash + run: | + echo "previous_commit_sha=$(git rev-parse HEAD~)" >> "$GITHUB_OUTPUT" - name: Check Modified Files id: check_files run: | diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index ab72e0da1f..b0bae3b0ce 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -1,4 +1,4 @@ -name: Dependency / formatting validation +name: Dependency / formatting / source gen validation on: workflow_call: @@ -6,6 +6,9 @@ on: sdk: required: true type: string + run_ddc_build: + required: true + type: boolean jobs: validate-dependencies: @@ -49,4 +52,35 @@ jobs: # Analyze lib to ensure public APIs don't depend on build-to-cache files, # which could cause analysis issues for consumers who haven't run a build yet. dart analyze lib - dart analyze example/boilerplate_versions \ No newline at end of file + dart analyze example/boilerplate_versions + + validate-generated-sources: + if: ${{ inputs.run_ddc_build }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dart-lang/setup-dart@v1 + with: + sdk: ${{ inputs.sdk }} + + - id: build + timeout-minutes: 6 + name: Build generated files / precompile DDC assets + run: | + dart run build_runner build --delete-conflicting-outputs + + - name: Verify that generated files are up-to-date + run: | + if [ ${{ inputs.sdk }} = '2.18.7' ]; then + git diff --exit-code + else + # Don't check these generated files for other SDKs, since they may generate differently + # due to different resolved dependencies. + git diff --exit-code -- ":(exclude)test/mockito.mocks.dart" ":(exclude)test/over_react/component_declaration/redux_component_test/test_reducer.g.dart" + fi + if: steps.build.outcome == 'success' + + # Analyze again after generated files are created to verify that those generated classes don't cause analysis errors + - name: Analyze project source (post-build) + run: dart analyze + if: steps.build.outcome == 'success' \ No newline at end of file