Skip to content

Commit

Permalink
Code coverage (#9)
Browse files Browse the repository at this point in the history
* feat: Verify versions in checkout workflow

This commit adds a new step in the checkout workflow to verify the versions of the project. It compares the version specified in the `pubspec.yaml` file with the version generated in the `pubspec.yaml.g.dart` file. If the versions match, it prints a success message. If the versions don't match, it prints an error message and exits with a non-zero status code.

* feat: Verify versions in checkout workflow

* feat: Update version verification in checkout workflow

This commit updates the `checkout.yml` workflow file to improve the version verification step. It modifies the commands to extract the version numbers from the `pubspec.yaml` and `pubspec.yaml.g.dart` files using the `grep` and `awk` commands. Additionally, it uses the `sed` command to remove any non-printable characters from the extracted version numbers. This ensures that the comparison between the two versions is accurate. The updated workflow now prints the version numbers and exits with a non-zero status code if they don't match.

* feat: Improve version verification in checkout workflow

* feat: Improve version verification in checkout workflow

* feat: Improve version verification in checkout workflow

* refactor: Simplify log entry addition in SpinifyLogBuffer

This commit simplifies the `add` method in the `SpinifyLogBuffer` class. It removes unnecessary conditional statements and reduces the number of lines of code. The logic for updating the buffer length and index has been condensed into a single line. This change improves the readability and maintainability of the code.

* refactor: Simplify log entry addition in SpinifyLogBuffer

* refactor: Simplify log entry addition in SpinifyLogBuffer

* refactor: Simplify log entry addition in SpinifyLogBuffer

* Fix JWT and add test

* chore: Update version to 0.0.1-pre.8 and SDK dependency to >=3.4.0 <4.0.0

* chore: Ignore file for code coverage in transport_fake.dart

* refactor: Simplify logger method in smoke_test.dart

This commit simplifies the `logger` method in the `smoke_test.dart` file. It removes the unnecessary `loggerPrint` function and consolidates the logic into a single `logger` function. The `enablePrint` flag is now used to control whether the log messages are printed or not. Additionally, the `logBuffer` is now initialized with a size of 100. These changes improve the readability and maintainability of the code.

* refactor: Simplify logger method in smoke_test.dart

* refactor: Override event property in SpinifyPush class

* refactor: Remove overridden event property in SpinifyPush class

* chore: Update version to 0.0.1-pre.8

* refactor: Remove unnecessary token check in SpinifyClientSubscriptionImpl

* refactor: Add message publication and subscription to smoke_test.dart

This commit adds the functionality for message publication and subscription to the `smoke_test.dart` file. It introduces a list of messages to be published and verifies that the messages are received in the correct order. This enhancement improves the testing capabilities of the code.

* 0.0.1-pre.9

* refactor: Update code coverage configuration in Makefile

This commit updates the code coverage configuration in the Makefile. It modifies the coverage command to include both the unit_test.dart and smoke_test.dart files. Additionally, it adjusts the lcov filtering to exclude specific files. These changes improve the accuracy and completeness of the code coverage report.

* refactor: Update lcov filtering in Makefile and SpinifyTransport$WS$PB$VM

This commit updates the lcov filtering in the Makefile and SpinifyTransport$WS$PB$VM files. It modifies the lcov command in the Makefile to exclude specific files related to protobuf and client code. In the SpinifyTransport$WS$PB$VM file, it adds coverage ignore comments to certain code blocks. These changes improve the accuracy of the code coverage report and ensure that the correct files are included/excluded.

* refactor: Ignore coverage for invalid connection expires and ping interval assertions

* refactor: Update Spinify import in spinify.dart

* refactor: Update lcov filtering in Makefile and SpinifyTransport$WS$PB$VM

* refactor: Update lcov filtering in Makefile and SpinifyTransport$WS$PB$VM

* refactor: Update Go echo server build process

* refactor: Update Go echo server build process

* refactor: Update Go echo server build process

* refactor: Update lcov filtering and coverage check

This commit updates the lcov filtering in the Makefile and SpinifyTransport$WS$PB$VM files. It modifies the lcov command in the Makefile to exclude specific files related to protobuf and client code. In the SpinifyTransport$WS$PB$VM file, it adds coverage ignore comments to certain code blocks. Additionally, it adds a new step to check the code coverage and ensure it meets the threshold of 50%. These changes improve the accuracy of the code coverage report and ensure that the correct files are included/excluded.

* refactor: Update PORT environment variable in tests.yml

This commit updates the PORT environment variable in the tests.yml file. It changes the value from 8080 to 8000 to align with the updated configuration. This modification ensures that the tests run on the correct port and reflects the recent changes made to the codebase.

* refactor: Update echo server build process and log handling

This commit updates the echo server build process in the tests.yml file. It modifies the command to redirect the server logs to a separate file called echo.log. Additionally, it saves the process ID of the echo server to echo_pid.txt for later use. This change improves the logging and ensures better management of the echo server process.

* refactor: Update tests.yml to install lcov and check code coverage

This commit updates the tests.yml file to install lcov and check the code coverage. It adds a new step to install lcov and jq dependencies using apt-get. It also modifies the check-coverage step to generate lcov.info, filter out specific files, and calculate the code coverage percentage. The threshold is set to 50%, and if the coverage is below the threshold, the step will exit with an error. This change improves the accuracy of the code coverage report and ensures that the correct files are included/excluded.

* refactor: Update tests.yml to install lcov and jq dependencies using apt-get

* refactor: Update tests.yml to install lcov and jq dependencies using apt-get

* refactor: Update tests.yml to download and cache Go echo server

This commit modifies the tests.yml file to download and cache the Go echo server artifact. It removes the previous step that uploaded the echo server artifact and replaces it with a new step that downloads and restores the cached artifact using the actions/cache/restore action. This change improves the efficiency of the workflow by avoiding unnecessary artifact uploads and ensures consistent usage of the echo server across different workflow runs.

* refactor: Update tests.yml to download and cache Go echo server

* refactor: Update tests.yml to download and cache Go echo server

* refactor: Update tests.yml to remove lcov filtering and update coverage check

This commit modifies the tests.yml file to remove the lcov filtering step and update the coverage check. It replaces the previous lcov command with a new one that includes all files in the coverage report. Additionally, it updates the coverage check step to calculate the coverage percentage based on the lcov.info file. This change simplifies the workflow and ensures accurate code coverage measurement.

* refactor: Update tests.yml to install lcov and jq dependencies using apt-get

* refactor: Update tests.yml to include threshold as an environment variable

This commit modifies the tests.yml file to include the threshold as an environment variable. It adds a new line to set the threshold value to 50. This change allows for easier customization of the coverage threshold without modifying the workflow file directly.

* refactor: Update tests.yml to include coverage percentage in logs

This commit modifies the tests.yml file to include the coverage percentage in the logs. It adds a new line to echo the coverage percentage after calculating it from the lcov.info file. This change provides visibility into the coverage results during the workflow execution.

* refactor: Update tests.yml to fix coverage calculation

This commit fixes the coverage calculation in the tests.yml file. The previous command used to extract the coverage percentage was incorrect, resulting in inaccurate coverage results. This change updates the command to correctly extract the coverage percentage from the lcov.info file, ensuring accurate reporting of code coverage during the workflow execution.

* refactor: Update tests.yml to fix timezone in dependabot.yaml

This commit updates the dependabot.yaml file to fix the timezone value in the schedule section. The previous value was set to "UTC", but it has been changed to "Etc/GMT" to accurately reflect the desired timezone. This change ensures that the schedule runs at the correct time according to the specified timezone.
  • Loading branch information
PlugFox authored Jul 19, 2024
1 parent 3962ef8 commit da52211
Show file tree
Hide file tree
Showing 26 changed files with 819 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ updates:
rebase-strategy: auto
schedule:
interval: "monthly"
timezone: "UTC"
timezone: "Etc/GMT"
85 changes: 52 additions & 33 deletions .github/workflows/checkout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
- "dev"
- "develop"
- "feature/**"
- "bugfix/**"
Expand All @@ -14,19 +16,7 @@ on:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- "pubspec.yaml"
pull_request:
branches:
- "master"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- .github/workflows/*.yml
- "pubspec.yaml"

jobs:
Expand All @@ -38,49 +28,78 @@ jobs:
working-directory: ./
container:
image: dart:stable
env:
pub-cache-name: pub
timeout-minutes: 10
steps:
- name: 🚂 Get latest code
uses: actions/checkout@v3
id: checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.github
pubspec.yaml
lib
test
analysis_options.yaml
CHANGELOG.md
- name: 🚃 Cache pub modules
uses: actions/cache@v2
env:
cache-name: cache-spinify-package
- name: 📤 Restore Pub modules
id: cache-pub-restore
uses: actions/cache/restore@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-spinify-${{ env.cache-name }}-${{ hashFiles('**/pubspec.yaml') }}
key: ${{ runner.os }}-spinify-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 🗄️ Export pub cache directory
- name: 🗄️ Export Pub cache directory
id: export-pub-cache
timeout-minutes: 1
run: |
export PUB_CACHE=$PWD/.pub_cache/
export PATH="$PATH":"$HOME/.pub-cache/bin"
- name: 👷 Install Dependencies
id: install-dependencies
timeout-minutes: 1
run: dart pub get --no-example

- name: 📥 Save Pub modules
id: cache-pub-save
uses: actions/cache/save@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-spinify-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 🔎 Check format
id: check-format
timeout-minutes: 1
run: dart format --set-exit-if-changed -l 80 -o none lib/

- name: 📈 Check analyzer
id: check-analyzer
timeout-minutes: 1
run: dart analyze --fatal-infos --fatal-warnings lib/

- name: 🧪 Run tests
timeout-minutes: 2
- name: 👀 Verify versions
id: verify-versions
timeout-minutes: 1
run: |
dart pub global activate coverage
dart pub global run coverage:test_with_coverage -fb -o coverage -- \
--platform vm --compiler=kernel --coverage=coverage \
--reporter=github --file-reporter=json:coverage/tests.json \
--timeout=30s --concurrency=12 --color \
test/unit_test.dart
test -f pubspec.yaml && test -f lib/src/model/pubspec.yaml.g.dart
version_pubspec=$(grep '^version:' pubspec.yaml | awk '{print $2}' | sed 's/[^[:print:]]//g')
version_dart=$(grep 'representation: r' lib/src/model/pubspec.yaml.g.dart | awk -F"'" '{print $2}' | sed 's/[^[:print:]]//g')
test -n "$version_pubspec" && test -n "$version_dart"
echo "Version from pubspec.yaml: '$version_pubspec'"
echo "Version from pubspec.yaml.g.dart: '$version_dart'"
echo "$version_pubspec" > /tmp/version_pubspec
echo "$version_dart" > /tmp/version_dart
diff /tmp/version_pubspec /tmp/version_dart
- name: 📥 Upload coverage to Codecov
timeout-minutes: 1
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
- name: 🧪 Run unit tests
id: run-unit-tests
timeout-minutes: 2
run: |
dart test --color --platform=vm --concurrency=12 \
--timeout=60s --reporter=github --file-reporter=json:coverage/tests.json \
--coverage=coverage -- test/unit_test.dart
223 changes: 223 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
name: Tests

on:
workflow_dispatch:
push:
branches:
- "main"
- "master"
#- "dev"
#- "develop"
#- "feature/**"
#- "bugfix/**"
#- "hotfix/**"
#- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- .github/workflows/*.yml
- "pubspec.yaml"
pull_request:
branches:
- "main"
- "master"
- "dev"
- "develop"
- "feature/**"
- "bugfix/**"
- "hotfix/**"
- "support/**"
paths:
- "lib/**.dart"
- "test/**.dart"
- "example/**.dart"
- .github/workflows/*.yml
- "pubspec.yaml"

jobs:
build-echo:
name: "Build Echo server"
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./
container:
image: golang:1.22
env:
echo-cache-name: echo
timeout-minutes: 5
steps:
- name: 🚂 Get latest code
id: checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.github
tool/echo
- name: 📤 Restore Go echo server
id: cache-echo-restore
uses: actions/cache/restore@v4
with:
path: |
~/build/bin/echo
key: ${{ runner.os }}-spinify-${{ env.echo-cache-name }}-${{ hashFiles('tool/echo/echo.go') }}

- name: 🦫 Build Go echo server
id: build-echo
if: steps.cache-echo-restore.outputs.cache-hit != 'true'
working-directory: ./tool/echo
run: |
mkdir -p ~/build/bin/
go get
go build -o ~/build/bin/echo echo.go
- name: 📥 Save Go echo server
id: cache-echo-save
if: steps.cache-echo-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: |
~/build/bin/echo
key: ${{ runner.os }}-spinify-${{ env.echo-cache-name }}-${{ hashFiles('tool/echo/echo.go') }}

- name: 💾 Upload Go echo server
id: upload-echo-server
uses: actions/upload-artifact@v4
with:
name: echo-server
path: ~/build/bin/echo
compression-level: 6
overwrite: true
retention-days: 1

tests:
name: "Tests"
runs-on: ubuntu-latest
needs: build-echo
defaults:
run:
working-directory: ./
container:
image: dart:stable
env:
pub-cache-name: pub
threshold: 50
timeout-minutes: 15
steps:
- name: 🚂 Get latest code
id: checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.github
pubspec.yaml
lib
test
analysis_options.yaml
- name: 📂 Download Echo server
id: download-echo-server
uses: actions/download-artifact@v4
with:
name: echo-server
path: ~/build/bin/

- name: 📤 Restore Pub modules
id: cache-pub-restore
uses: actions/cache/restore@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-spinify-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 🗄️ Export Pub cache directory
id: export-pub-cache
timeout-minutes: 1
run: |
export PUB_CACHE=$PWD/.pub_cache/
export PATH="$PATH":"$HOME/.pub-cache/bin"
- name: 👷 Install Dependencies
id: install-dependencies
timeout-minutes: 1
run: |
apt-get update && apt-get install -y lcov bc
dart pub get --no-example
- name: 📥 Save Pub modules
id: cache-pub-save
uses: actions/cache/save@v4
with:
path: |
$PWD/.pub_cache/
key: ${{ runner.os }}-spinify-${{ env.pub-cache-name }}-${{ hashFiles('**/pubspec.yaml') }}

- name: 📢 Run Echo server
id: run-echo-server
timeout-minutes: 1
run: |
test -f ~/build/bin/echo
chmod +x ~/build/bin/echo
nohup ~/build/bin/echo > echo.log 2>&1 &
echo $! > echo_pid.txt
env:
PORT: 8000

- name: 🧪 Run tests
id: run-tests
timeout-minutes: 10
run: |
dart pub global activate coverage
dart pub global run coverage:test_with_coverage -fb -o coverage -- \
--platform vm --compiler=kernel --coverage=coverage \
--reporter=github --file-reporter=json:coverage/tests.json \
--timeout=10m --concurrency=12 --color \
test/unit_test.dart test/smoke_test.dart
- name: 🧾 Upload echo logs
id: upload-echo-logs
if: always()
uses: actions/upload-artifact@v4
with:
name: server-logs
path: echo.log
compression-level: 9
overwrite: true
retention-days: 1

- name: ✋ Stop echo server
id: stop-echo-server
timeout-minutes: 1
if: always()
run: |
kill $(cat echo_pid.txt) || true
rm -f echo_pid.txt || true
rm -f echo.log || true
- name: 🔍 Check coverage
id: check-coverage
timeout-minutes: 2
run: |
mv coverage/lcov.info coverage/lcov.base.info
lcov --remove coverage/lcov.base.info '*/protobuf/client.*.dart' '*/model/*.g.dart' -o coverage/lcov.info
lcov --list coverage/lcov.info
THRESHOLD=${{ env.threshold }}
COVERAGE=$(lcov --summary coverage/lcov.info | grep -i 'lines\|Total:' | tail -n 1 | awk '{print $2}' | sed 's/%//')
echo "Coverage is $COVERAGE%"
echo $COVERAGE | awk '{if ($1 < 50) exit 1}'
- name: 🧹 Cleanup artifacts
id: cleanup-artifacts
if: always()
timeout-minutes: 2
run: |
rm -rf ~/build
- name: ✨ Upload coverage to Codecov
id: upload-coverage
timeout-minutes: 2
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
"--concurrency=12"
],
"args": [],
"preLaunchTask": "echo:start",
"postDebugTask": "echo:stop"
/* "preLaunchTask": "echo:start",
"postDebugTask": "echo:stop" */
},
{
"name": "[Dart] Smoke Test (dart2js)",
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## 0.0.1-pre.7
## 0.0.1-pre.9

- **ADDED**: Initial release
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ coverage: get
@dart pub global run coverage:test_with_coverage -fb -o coverage -- \
--platform vm --compiler=kernel --coverage=coverage \
--reporter=expanded --file-reporter=json:coverage/tests.json \
--timeout=30s --concurrency=12 --color \
test/unit_test.dart
--timeout=10m --concurrency=12 --color \
test/unit_test.dart test/smoke_test.dart
# @dart test --concurrency=6 --platform vm --coverage=coverage test/
# @dart run coverage:format_coverage --lcov --in=coverage --out=coverage/lcov.info --report-on=lib
# @mv coverage/lcov.info coverage/lcov.base.info
# @lcov -r coverage/lcov.base.info -o coverage/lcov.base.info "lib/**.freezed.dart" "lib/**.g.dart"
# @mv coverage/lcov.base.info coverage/lcov.info
@mv coverage/lcov.info coverage/lcov.base.info
@lcov -r coverage/lcov.base.info -o coverage/lcov.base.info "lib/src/protobuf/client.*.dart" "lib/**/*.g.dart"
@mv coverage/lcov.base.info coverage/lcov.info
@lcov --list coverage/lcov.info
@genhtml -o coverage coverage/lcov.info

Expand Down
Loading

0 comments on commit da52211

Please sign in to comment.