From 6520b7d6911034065a89619b26656df1abb1468d Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 29 Jun 2023 18:08:23 +0200 Subject: [PATCH 1/4] fix indentation and deduplicate stuff --- .github/workflows/rust.yml | 400 +++++++++++++++++++------------------ 1 file changed, 201 insertions(+), 199 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a910a4ce..1377c425 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -7,202 +7,204 @@ on: pull_request: jobs: - readmecheck: - name: README Format Check - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@nightly - - run: bash ./auxiliary/update_cargo-readme.sh - - run: bash ./auxiliary/check_readme_consistency.sh - - style: - name: Style Checks (stable/ubuntu-latest) - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@nightly - with: - components: rustfmt - - name: Check code formatting - run: cargo fmt --all -- --check - - uses: dtolnay/rust-toolchain@1.63.0 - with: - components: clippy - - name: Check Clippy lints (reqwest) - run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,reqwest-client -- -D warnings - - name: Check Clippy lints (surf) - run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,hyper-client -- -D warnings - - compile: - name: Compile (${{ matrix.rust_release }}/${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - matrix: - rust_release: ["1.60", stable, nightly] - os: [ubuntu-latest, windows-latest, macOS-latest] - - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust_release }} - - name: Build - run: cargo build --verbose - - unit_test: - name: Unit test (${{ matrix.rust_release }}/${{ matrix.os }}) - runs-on: ${{ matrix.os }} - strategy: - matrix: - rust_release: ["1.60", stable, nightly] - os: [ubuntu-latest, windows-latest, macOS-latest] - - steps: - - uses: actions/checkout@v1 - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust_release }} - - name: test - run: cargo test --lib - - integration_test: - name: Integration Tests for Influxdb 1.x (stable/ubuntu-latest) - runs-on: ubuntu-latest - strategy: - matrix: - http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client, reqwest-client, reqwest-client-rustls] - services: - influxdb: - image: influxdb:1.8 - ports: - - 8086:8086 - authed_influxdb: - image: influxdb:1.8 - ports: - - 9086:8086 - env: - INFLUXDB_HTTP_AUTH_ENABLED: true - INFLUXDB_ADMIN_USER: admin - INFLUXDB_ADMIN_PASSWORD: password - INFLUXDB_USER: nopriv_user - INFLUXDB_USER_PASSWORD: password - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - run: cargo test --manifest-path=./influxdb/Cargo.toml --no-default-features --features 'use-serde derive ${{ matrix.http-backend }}' --no-fail-fast --test integration_tests - - integration_test_v2: - name: Integration Tests for Influxdb 2.0 (stable/ubuntu-latest) - runs-on: ubuntu-latest - strategy: - matrix: - http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client] - services: - influxdbv2: - image: influxdb:2.6 - ports: - - 9086:8086 - env: - DOCKER_INFLUXDB_INIT_MODE: setup - DOCKER_INFLUXDB_INIT_USERNAME: admin - DOCKER_INFLUXDB_INIT_PASSWORD: password - DOCKER_INFLUXDB_INIT_ORG: testing - DOCKER_INFLUXDB_INIT_BUCKET: mydb - DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: admintoken - steps: - - uses: actions/checkout@v1 - - uses: dtolnay/rust-toolchain@stable - - run: cargo test --manifest-path=./influxdb/Cargo.toml --no-default-features --features 'use-serde derive ${{ matrix.http-backend }}' --no-fail-fast --test integration_tests_v2 - - coverage: - name: Code Coverage (stable/ubuntu-latest) - runs-on: ubuntu-latest - services: - influxdb: - image: influxdb:1.8 - ports: - - 8086:8086 - authed_influxdb: - image: influxdb:1.8 - ports: - - 9086:8086 - env: - INFLUXDB_HTTP_AUTH_ENABLED: true - INFLUXDB_ADMIN_USER: admin - INFLUXDB_ADMIN_PASSWORD: password - INFLUXDB_USER: nopriv_user - INFLUXDB_USER_PASSWORD: password - - steps: - - uses: actions/checkout@v3 - - uses: dtolnay/rust-toolchain@stable - - - name: Get Rust Version - id: rust-version - run: echo "::set-output name=VERSION::$(cargo -V | head -n1 | awk '{print $2}')" - - - name: Get Tarpaulin Version - id: tarpaulin-version - run: echo "::set-output name=VERSION::$(wget -qO- 'https://crates.io/api/v1/crates/cargo-tarpaulin' | jq -r '.crate.max_stable_version')" - - - uses: actions/cache@v3 - with: - path: | - ~/.cargo/bin/cargo-tarpaulin - ~/.cargo/git - ~/.cargo/registry - target - key: ${{ runner.os }}-cargo-${{ steps.rust-version.outputs.VERSION }}-tarpaulin-${{ steps.tarpaulin-version.outputs.VERSION }} }} - - - name: Install Tarpaulin - run: | - ls -lh ~/.cargo/bin - test -e ~/.cargo/bin/cargo-tarpaulin || cargo install cargo-tarpaulin --version ${{ steps.tarpaulin-version.outputs.VERSION }} - - - name: Run Tarpaulin coverage tests - run: | - cargo tarpaulin -v \ - --target-dir target/tarpaulin \ - --workspace \ - --features use-serde,derive \ - --exclude-files 'derive/*' \ - --exclude-files 'target/*' \ - --ignore-panics --ignore-tests \ - --out Html --out Json - env: - RUST_BACKTRACE: 1 - RUST_LOG: info - - - uses: actions/upload-artifact@v3 - with: - name: tarpaulin-report - path: | - tarpaulin-report.json - tarpaulin-report.html - - pages: - runs-on: ubuntu-latest - needs: - - coverage - if: github.ref == 'refs/heads/main' - steps: - - uses: actions/checkout@v3 - with: - ref: gh-pages - - - uses: actions/download-artifact@v3 - with: - name: tarpaulin-report - - - run: | - coverage=$(jq '.files | { covered: map(.covered) | add, coverable: map(.coverable) | add } | .covered / .coverable * 10000 | round | . / 100' tarpaulin-report.json) - color=$([[ $coverage < 80 ]] && printf yellow || printf brightgreen) - wget -qO coverage.svg "https://img.shields.io/badge/coverage-$coverage%25-$color" - - git add coverage.svg tarpaulin-report.html - git status - - - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "GitHub Pages for ${{ github.sha }}" + # this checks that the readme created from rustdoc is up to date + readmecheck: + name: README Format Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + - run: bash ./auxiliary/update_cargo-readme.sh + - run: bash ./auxiliary/check_readme_consistency.sh + + # this checks that there are no clippy lints + clippy: + name: Style Check (clippy) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@1.63.0 + with: + components: clippy + - name: Check Clippy lints (reqwest) + run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,reqwest-client -- -D warnings + - name: Check Clippy lints (surf) + run: cargo clippy --manifest-path influxdb/Cargo.toml --all-targets --no-default-features --features use-serde,derive,hyper-client -- -D warnings + + # this checks that the code is formatted with rustfmt + rustfmt: + name: Style Checks (rustfmt) + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@nightly + with: + components: rustfmt + - name: Check code formatting + run: cargo fmt --all -- --check + + unit_tests: + name: Unit Tests (Rust ${{matrix.rust.name}} on ${{matrix.os}}) + runs-on: ${{matrix.os}} + continue-on-error: ${{matrix.rust.nightly}} + strategy: + matrix: + rust: + - name: MSRV + toolchain: "1.60" + nightly: false + - name: Stable + toolchain: stable + nightly: false + - name: Beta + toolchain: beta + nightly: false + - name: Nightly + toolchain: nightly + nightly: true + os: [ubuntu-latest, windows-latest, macOS-latest] + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{matrix.rust.toolchain}} + - run: cargo test --lib + + integration_tests: + name: Integration Tests (Rust ${{matrix.rust.name}}) + runs-on: ubuntu-latest + continue-on-error: ${{matrix.rust.nightly}} + strategy: + matrix: + rust: + - name: Stable + toolchain: stable + nightly: false + http-backend: [curl-client, h1-client, h1-client-rustls, hyper-client, reqwest-client, reqwest-client-rustls] + services: + influxdb: + image: influxdb:1.8 + ports: + - 8086:8086 + authed_influxdb: + image: influxdb:1.8 + ports: + - 9086:8086 + env: + INFLUXDB_HTTP_AUTH_ENABLED: true + INFLUXDB_ADMIN_USER: admin + INFLUXDB_ADMIN_PASSWORD: password + INFLUXDB_USER: nopriv_user + INFLUXDB_USER_PASSWORD: password + influxdbv2: + image: influxdb:2.6 + ports: + - 9086:8086 + env: + DOCKER_INFLUXDB_INIT_MODE: setup + DOCKER_INFLUXDB_INIT_USERNAME: admin + DOCKER_INFLUXDB_INIT_PASSWORD: password + DOCKER_INFLUXDB_INIT_ORG: testing + DOCKER_INFLUXDB_INIT_BUCKET: mydb + DOCKER_INFLUXDB_INIT_ADMIN_TOKEN: admintoken + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Run tests + run: | + for test in integration_tests{,_v2} + do + cargo test -p influxdb --no-default-features --features 'use-serde derive ${{matrix.http-backend}}' --no-fail-fast --test integration_tests + done + + coverage: + name: Code Coverage (stable/ubuntu-latest) + runs-on: ubuntu-latest + services: + influxdb: + image: influxdb:1.8 + ports: + - 8086:8086 + authed_influxdb: + image: influxdb:1.8 + ports: + - 9086:8086 + env: + INFLUXDB_HTTP_AUTH_ENABLED: true + INFLUXDB_ADMIN_USER: admin + INFLUXDB_ADMIN_PASSWORD: password + INFLUXDB_USER: nopriv_user + INFLUXDB_USER_PASSWORD: password + + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + + - name: Get Rust Version + id: rust-version + run: echo "::set-output name=VERSION::$(cargo -V | head -n1 | awk '{print $2}')" + + - name: Get Tarpaulin Version + id: tarpaulin-version + run: echo "::set-output name=VERSION::$(wget -qO- 'https://crates.io/api/v1/crates/cargo-tarpaulin' | jq -r '.crate.max_stable_version')" + + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/cargo-tarpaulin + ~/.cargo/git + ~/.cargo/registry + target + key: ${{ runner.os }}-cargo-${{ steps.rust-version.outputs.VERSION }}-tarpaulin-${{ steps.tarpaulin-version.outputs.VERSION }} }} + + - name: Install Tarpaulin + run: | + ls -lh ~/.cargo/bin + test -e ~/.cargo/bin/cargo-tarpaulin || cargo install cargo-tarpaulin --version ${{ steps.tarpaulin-version.outputs.VERSION }} + + - name: Run Tarpaulin coverage tests + run: | + cargo tarpaulin -v \ + --target-dir target/tarpaulin \ + --workspace \ + --features use-serde,derive \ + --exclude-files 'derive/*' \ + --exclude-files 'target/*' \ + --ignore-panics --ignore-tests \ + --out Html --out Json + env: + RUST_BACKTRACE: 1 + RUST_LOG: info + + - uses: actions/upload-artifact@v3 + with: + name: tarpaulin-report + path: | + tarpaulin-report.json + tarpaulin-report.html + + pages: + runs-on: ubuntu-latest + needs: + - coverage + if: github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v3 + with: + ref: gh-pages + + - uses: actions/download-artifact@v3 + with: + name: tarpaulin-report + + - run: | + coverage=$(jq '.files | { covered: map(.covered) | add, coverable: map(.coverable) | add } | .covered / .coverable * 10000 | round | . / 100' tarpaulin-report.json) + color=$([[ $coverage < 80 ]] && printf yellow || printf brightgreen) + wget -qO coverage.svg "https://img.shields.io/badge/coverage-$coverage%25-$color" + + git add coverage.svg tarpaulin-report.html + git status + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "GitHub Pages for ${{ github.sha }}" From 0b1626911ff75ef2282cda7f80970b0e6bc06a4f Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 29 Jun 2023 18:18:02 +0200 Subject: [PATCH 2/4] enable caching everywhere --- .github/workflows/rust.yml | 46 ++++++++++++++++---------- influxdb/tests/integration_tests_v2.rs | 8 ++--- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1377c425..496fdbd8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -43,8 +43,9 @@ jobs: - name: Check code formatting run: cargo fmt --all -- --check + # this tests that all unit and doc tests are successful unit_tests: - name: Unit Tests (Rust ${{matrix.rust.name}} on ${{matrix.os}}) + name: Unit and Doc Tests (Rust ${{matrix.rust.name}} on ${{matrix.os}}) runs-on: ${{matrix.os}} continue-on-error: ${{matrix.rust.nightly}} strategy: @@ -68,8 +69,18 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust.toolchain}} + id: rust-toolchain + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/git + ~/.cargo/registry + target + key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}}" - run: cargo test --lib + - run: cargo test --doc + # this tests that all integration tests are successful integration_tests: name: Integration Tests (Rust ${{matrix.rust.name}}) runs-on: ubuntu-latest @@ -99,7 +110,7 @@ jobs: influxdbv2: image: influxdb:2.6 ports: - - 9086:8086 + - 2086:8086 env: DOCKER_INFLUXDB_INIT_MODE: setup DOCKER_INFLUXDB_INIT_USERNAME: admin @@ -110,13 +121,22 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable + id: rust-toolchain + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/git + ~/.cargo/registry + target + key: "${{runner.os}} Rust ${{steps.rust-toolchain.outputs.cachekey}}" - name: Run tests run: | for test in integration_tests{,_v2} do - cargo test -p influxdb --no-default-features --features 'use-serde derive ${{matrix.http-backend}}' --no-fail-fast --test integration_tests + cargo test -p influxdb --no-default-features --features 'use-serde derive ${{matrix.http-backend}}' --no-fail-fast --test $test done + # this uses cargo-tarpaulin to inspect the code coverage coverage: name: Code Coverage (stable/ubuntu-latest) runs-on: ubuntu-latest @@ -139,15 +159,10 @@ jobs: steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable - - - name: Get Rust Version - id: rust-version - run: echo "::set-output name=VERSION::$(cargo -V | head -n1 | awk '{print $2}')" - + id: rust-toolchain - name: Get Tarpaulin Version id: tarpaulin-version - run: echo "::set-output name=VERSION::$(wget -qO- 'https://crates.io/api/v1/crates/cargo-tarpaulin' | jq -r '.crate.max_stable_version')" - + run: echo "version=$(wget -qO- 'https://crates.io/api/v1/crates/cargo-tarpaulin' | jq -r '.crate.max_stable_version')" >>$GITHUB_OUTPUT - uses: actions/cache@v3 with: path: | @@ -155,13 +170,11 @@ jobs: ~/.cargo/git ~/.cargo/registry target - key: ${{ runner.os }}-cargo-${{ steps.rust-version.outputs.VERSION }}-tarpaulin-${{ steps.tarpaulin-version.outputs.VERSION }} }} - + key: "${{runner.os}} Rust ${{steps.rust-version.outputs.version}} tarpaulin ${{steps.tarpaulin-version.outputs.version}}" - name: Install Tarpaulin run: | ls -lh ~/.cargo/bin - test -e ~/.cargo/bin/cargo-tarpaulin || cargo install cargo-tarpaulin --version ${{ steps.tarpaulin-version.outputs.VERSION }} - + test -e ~/.cargo/bin/cargo-tarpaulin || cargo install cargo-tarpaulin --version ${{steps.tarpaulin-version.outputs.version}} - name: Run Tarpaulin coverage tests run: | cargo tarpaulin -v \ @@ -175,7 +188,6 @@ jobs: env: RUST_BACKTRACE: 1 RUST_LOG: info - - uses: actions/upload-artifact@v3 with: name: tarpaulin-report @@ -183,6 +195,7 @@ jobs: tarpaulin-report.json tarpaulin-report.html + # this uploads the code coverage to github pages pages: runs-on: ubuntu-latest needs: @@ -192,11 +205,9 @@ jobs: - uses: actions/checkout@v3 with: ref: gh-pages - - uses: actions/download-artifact@v3 with: name: tarpaulin-report - - run: | coverage=$(jq '.files | { covered: map(.covered) | add, coverable: map(.coverable) | add } | .covered / .coverable * 10000 | round | . / 100' tarpaulin-report.json) color=$([[ $coverage < 80 ]] && printf yellow || printf brightgreen) @@ -204,7 +215,6 @@ jobs: git add coverage.svg tarpaulin-report.html git status - - uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "GitHub Pages for ${{ github.sha }}" diff --git a/influxdb/tests/integration_tests_v2.rs b/influxdb/tests/integration_tests_v2.rs index 2cedfec6..74e17a7d 100644 --- a/influxdb/tests/integration_tests_v2.rs +++ b/influxdb/tests/integration_tests_v2.rs @@ -16,7 +16,7 @@ use influxdb::{Client, Error, ReadQuery, Timestamp}; async fn test_authed_write_and_read() { run_test( || async move { - let client = Client::new("http://127.0.0.1:9086", "mydb").with_token("admintoken"); + let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("admintoken"); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); @@ -32,7 +32,7 @@ async fn test_authed_write_and_read() { ); }, || async move { - let client = Client::new("http://127.0.0.1:9086", "mydb").with_token("admintoken"); + let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("admintoken"); let read_query = ReadQuery::new("DELETE MEASUREMENT weather"); let read_result = client.query(read_query).await; assert_result_ok(&read_result); @@ -50,7 +50,7 @@ async fn test_authed_write_and_read() { async fn test_wrong_authed_write_and_read() { run_test( || async move { - let client = Client::new("http://127.0.0.1:9086", "mydb").with_token("falsetoken"); + let client = Client::new("http://127.0.0.1:2086", "mydb").with_token("falsetoken"); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); @@ -88,7 +88,7 @@ async fn test_wrong_authed_write_and_read() { async fn test_non_authed_write_and_read() { run_test( || async move { - let non_authed_client = Client::new("http://127.0.0.1:9086", "mydb"); + let non_authed_client = Client::new("http://127.0.0.1:2086", "mydb"); let write_query = Timestamp::Hours(11) .into_query("weather") .add_field("temperature", 82); From 25ec8c8aa4c65ac5c7b34597d93f7ec1ba99ddb2 Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 29 Jun 2023 18:19:00 +0200 Subject: [PATCH 3/4] don't fail fast --- .github/workflows/rust.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 496fdbd8..4bb139cd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -49,6 +49,7 @@ jobs: runs-on: ${{matrix.os}} continue-on-error: ${{matrix.rust.nightly}} strategy: + fail-fast: false matrix: rust: - name: MSRV @@ -86,6 +87,7 @@ jobs: runs-on: ubuntu-latest continue-on-error: ${{matrix.rust.nightly}} strategy: + fail-fast: false matrix: rust: - name: Stable From 789ae28f0836345e99603b780de9d907b563f380 Mon Sep 17 00:00:00 2001 From: Dominic Date: Thu, 29 Jun 2023 18:25:46 +0200 Subject: [PATCH 4/4] include name of http-backend --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4bb139cd..410376e8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -83,7 +83,7 @@ jobs: # this tests that all integration tests are successful integration_tests: - name: Integration Tests (Rust ${{matrix.rust.name}}) + name: Integration Tests (Rust ${{matrix.rust.name}} with ${{matrix.http-backend}}) runs-on: ubuntu-latest continue-on-error: ${{matrix.rust.nightly}} strategy: