🎨 enhance code comments and improve variable naming for clarity i… #395
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Test | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| workflow_call: | |
| defaults: | |
| run: | |
| shell: bash | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: test-${{ github.ref }} | |
| cancel-in-progress: true | |
| env: | |
| MIN_COVERAGE: 90 | |
| PUB_ENVIRONMENT: bot.github | |
| jobs: | |
| analyze: | |
| name: "Analyze" | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Cache Pub hosted dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: "~/.pub-cache/hosted" | |
| key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test" | |
| restore-keys: | | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable | |
| os:ubuntu-latest;pub-cache-hosted | |
| os:ubuntu-latest | |
| - name: Setup Dart SDK | |
| uses: dart-lang/setup-dart@v1 | |
| with: | |
| sdk: stable | |
| - id: checkout | |
| name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - id: install | |
| name: Install dependencies | |
| run: dart pub get | |
| - name: Check the formatting of one or more Dart files | |
| run: dart format lib test --output=none --set-exit-if-changed . | |
| - name: Analyze the project's Dart code | |
| run: dart analyze lib test --fatal-infos | |
| minimum_dart_meta: | |
| name: "Read minimum Dart SDK" | |
| needs: analyze | |
| runs-on: ubuntu-latest | |
| outputs: | |
| min_dart: ${{ steps.read_min_dart.outputs.min_dart }} | |
| steps: | |
| - id: checkout | |
| name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - id: read_min_dart | |
| name: Read minimum Dart SDK from pubspec.yaml | |
| run: | | |
| set -euo pipefail | |
| min_dart="$(yq -r '.environment.sdk | capture("(?<min>[0-9]+\.[0-9]+\.[0-9]+)").min' pubspec.yaml)" | |
| if [[ -z "${min_dart}" ]]; then | |
| echo 'failed to read minimum Dart SDK from pubspec.yaml' >&2 | |
| exit 1 | |
| fi | |
| echo "min_dart=${min_dart}" >> "$GITHUB_OUTPUT" | |
| minimum_dart: | |
| name: "Minimum Dart (${{ needs.minimum_dart_meta.outputs.min_dart }}, ${{ matrix.platform }})" | |
| needs: minimum_dart_meta | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: chrome | |
| - platform: vm | |
| steps: | |
| - name: Cache Pub hosted dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: "~/.pub-cache/hosted" | |
| key: "os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }};packages:qs_dart;commands:codegen-test" | |
| restore-keys: | | |
| os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }};packages:qs_dart | |
| os:ubuntu-latest;pub-cache-hosted;sdk:${{ needs.minimum_dart_meta.outputs.min_dart }} | |
| os:ubuntu-latest;pub-cache-hosted | |
| os:ubuntu-latest | |
| - name: Setup Dart SDK | |
| uses: dart-lang/setup-dart@v1 | |
| with: | |
| sdk: ${{ needs.minimum_dart_meta.outputs.min_dart }} | |
| - id: checkout | |
| name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - id: install | |
| name: Install dependencies | |
| run: dart pub get | |
| - name: Analyze the project's Dart code | |
| if: ${{ matrix.platform == 'vm' }} | |
| run: dart analyze lib test | |
| - name: Run the project's tests in Chrome | |
| if: ${{ matrix.platform == 'chrome' }} | |
| run: dart test --platform chrome | |
| - name: Run the project's tests on the VM | |
| if: ${{ matrix.platform == 'vm' }} | |
| run: dart test --platform vm | |
| test: | |
| name: "Test" | |
| needs: analyze | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - platform: chrome | |
| - platform: vm | |
| steps: | |
| - name: Cache Pub hosted dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: "~/.pub-cache/hosted" | |
| key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test" | |
| restore-keys: | | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable | |
| os:ubuntu-latest;pub-cache-hosted | |
| os:ubuntu-latest | |
| - name: Setup Dart SDK | |
| uses: dart-lang/setup-dart@v1 | |
| with: | |
| sdk: stable | |
| - id: checkout | |
| name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - id: install | |
| name: Install dependencies | |
| run: dart pub get | |
| - name: Run the project's tests in Chrome | |
| if: ${{ matrix.platform == 'chrome' }} | |
| run: dart test --platform chrome | |
| - name: Install coverage dependencies | |
| if: ${{ matrix.platform == 'vm' }} | |
| run: | | |
| dart pub global activate coverage | |
| dart pub global activate remove_from_coverage | |
| - name: Collect and report coverage | |
| if: ${{ matrix.platform == 'vm' }} | |
| run: | | |
| dart pub global run coverage:test_with_coverage | |
| dart pub global run remove_from_coverage:remove_from_coverage -f coverage/lcov.info -r '\.g\.dart$' | |
| - name: Upload coverage to Codecov | |
| if: ${{ matrix.platform == 'vm' }} | |
| continue-on-error: true | |
| uses: codecov/codecov-action@v6 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| slug: techouse/qs | |
| files: ./coverage/lcov.info | |
| verbose: true | |
| - name: Check Code Coverage | |
| if: ${{ matrix.platform == 'vm' }} | |
| run: | | |
| set -euo pipefail | |
| awk -F: -v min="$MIN_COVERAGE" ' | |
| /^LF:/ { total += $2 } | |
| /^LH:/ { hit += $2 } | |
| END { | |
| if (total == 0) { | |
| print "::error::No executable lines found in coverage/lcov.info" | |
| exit 1 | |
| } | |
| coverage = (hit / total) * 100 | |
| printf("Line coverage: %.2f%% (%d/%d)\n", coverage, hit, total) | |
| if (coverage < min) { | |
| printf("::error::Coverage %.2f%% is below %.2f%%\n", coverage, min) | |
| exit 1 | |
| } | |
| } | |
| ' coverage/lcov.info | |
| - name: Upload coverage to Codacy | |
| if: ${{ matrix.platform == 'vm' }} | |
| continue-on-error: true | |
| uses: codacy/codacy-coverage-reporter-action@v1 | |
| with: | |
| project-token: ${{ secrets.CODACY_PROJECT_TOKEN }} | |
| coverage-reports: coverage/lcov.info | |
| ensure_compatibility: | |
| name: "Ensure compatibility with qs" | |
| needs: analyze | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Cache Pub hosted dependencies | |
| uses: actions/cache@v5 | |
| with: | |
| path: "~/.pub-cache/hosted" | |
| key: "os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart;commands:codegen-test" | |
| restore-keys: | | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable;packages:qs_dart | |
| os:ubuntu-latest;pub-cache-hosted;sdk:stable | |
| os:ubuntu-latest;pub-cache-hosted | |
| os:ubuntu-latest | |
| - name: Setup Dart SDK | |
| uses: dart-lang/setup-dart@v1 | |
| with: | |
| sdk: stable | |
| - id: checkout | |
| name: Checkout repository | |
| uses: actions/checkout@v6 | |
| - name: Setup Node | |
| uses: actions/setup-node@v6 | |
| with: | |
| node-version: 24 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v6 | |
| with: | |
| package_json_file: test/comparison/package.json | |
| run_install: false | |
| cache: true | |
| cache_dependency_path: test/comparison/pnpm-lock.yaml | |
| - id: install_dart_dependencies | |
| name: Install Dart dependencies | |
| run: dart pub get | |
| - id: install_node_dependencies | |
| name: Install Node dependencies | |
| working-directory: test/comparison | |
| run: pnpm install --frozen-lockfile | |
| - name: Run a comparison test between qs_dart and qs for JavaScript | |
| working-directory: test/comparison | |
| run: | | |
| set -e | |
| node_output=$(node qs.js) | |
| dart_output=$(dart run qs.dart) | |
| if [ "$node_output" == "$dart_output" ]; then | |
| echo "The outputs are identical." | |
| else | |
| echo "The outputs are different." | |
| exit 1 | |
| fi | |
| ci_required: | |
| name: "CI Required" | |
| if: ${{ always() }} | |
| needs: | |
| - analyze | |
| - minimum_dart | |
| - test | |
| - ensure_compatibility | |
| runs-on: ubuntu-latest | |
| env: | |
| ANALYZE_RESULT: ${{ needs.analyze.result }} | |
| MINIMUM_DART_RESULT: ${{ needs.minimum_dart.result }} | |
| TEST_RESULT: ${{ needs.test.result }} | |
| ENSURE_COMPATIBILITY_RESULT: ${{ needs.ensure_compatibility.result }} | |
| steps: | |
| - name: Verify required job results | |
| run: | | |
| set -euo pipefail | |
| results=( | |
| "analyze:${ANALYZE_RESULT}" | |
| "minimum_dart:${MINIMUM_DART_RESULT}" | |
| "test:${TEST_RESULT}" | |
| "ensure_compatibility:${ENSURE_COMPATIBILITY_RESULT}" | |
| ) | |
| failed=0 | |
| for entry in "${results[@]}"; do | |
| job="${entry%%:*}" | |
| result="${entry#*:}" | |
| echo "${job}: ${result}" | |
| if [[ "${result}" != "success" ]]; then | |
| echo "::error::${job} finished with result '${result}'" | |
| failed=1 | |
| fi | |
| done | |
| exit "${failed}" |