From 46cadab0c9f159480c2371a4af4ff7fe08b6b8d9 Mon Sep 17 00:00:00 2001 From: Pavel Mikhalkevich Date: Sat, 24 Aug 2024 11:44:04 +0400 Subject: [PATCH] Update workflows --- .github/workflows/check.yml | 12 ++++- .github/workflows/nostd.yml | 30 ------------ .github/workflows/safety.yml | 84 --------------------------------- .github/workflows/scheduled.yml | 26 ++++++++-- .github/workflows/test.yml | 79 +++++++++++++++++++++++++++---- .gitignore | 3 +- Makefile | 7 ++- tests/e2e/client.rs | 3 ++ 8 files changed, 113 insertions(+), 131 deletions(-) delete mode 100644 .github/workflows/nostd.yml delete mode 100644 .github/workflows/safety.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 5251954..44c08d6 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -20,6 +20,8 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true name: check +env: + PUBLISHED_TO_CRATESIO: false jobs: fmt: runs-on: ubuntu-latest @@ -57,20 +59,23 @@ jobs: - name: cargo clippy uses: giraffate/clippy-action@v1 with: - reporter: 'github-pr-check' + reporter: "github-pr-check" github_token: ${{ secrets.GITHUB_TOKEN }} semver: runs-on: ubuntu-latest name: semver steps: - uses: actions/checkout@v4 + if: ${{ env.PUBLISHED_TO_CRATESIO == 'true' }} with: submodules: true - name: Install stable + if: ${{ env.PUBLISHED_TO_CRATESIO == 'true' }} uses: dtolnay/rust-toolchain@stable with: components: rustfmt - name: cargo-semver-checks + if: ${{ env.PUBLISHED_TO_CRATESIO == 'true' }} uses: obi1kenobi/cargo-semver-checks-action@v2 doc: # run docs generation on nightly rather than stable. This enables features like @@ -112,7 +117,10 @@ jobs: # https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability strategy: matrix: - msrv: ["1.56.1"] # 2021 edition requires 1.56 + # SQLx is being tested against the latest rustc ("1.80.1" as of August 24, 2024), + # so when updating this dependency there is always a chance we will need to bump MSRV. + # As of August 24, 2024, our crate will build with rustc 1.74 + msrv: ["1.74.0"] name: ubuntu / ${{ matrix.msrv }} steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/nostd.yml b/.github/workflows/nostd.yml deleted file mode 100644 index c12227a..0000000 --- a/.github/workflows/nostd.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow checks whether the library is able to run without the std library (e.g., embedded). -# This entire file should be removed if this crate does not support no-std. See check.yml for -# information about how the concurrency cancellation and workflow triggering works -permissions: - contents: read -on: - push: - branches: [main] - pull_request: -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true -name: no-std -jobs: - nostd: - runs-on: ubuntu-latest - name: ${{ matrix.target }} - strategy: - matrix: - target: [thumbv7m-none-eabi, aarch64-unknown-none] - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install stable - uses: dtolnay/rust-toolchain@stable - - name: rustup target add ${{ matrix.target }} - run: rustup target add ${{ matrix.target }} - - name: cargo check - run: cargo check --target ${{ matrix.target }} --no-default-features diff --git a/.github/workflows/safety.yml b/.github/workflows/safety.yml deleted file mode 100644 index 6bdd055..0000000 --- a/.github/workflows/safety.yml +++ /dev/null @@ -1,84 +0,0 @@ -# This workflow runs checks for unsafe code. In crates that don't have any unsafe code, this can be -# removed. Runs: -# - miri - detects undefined behavior and memory leaks -# - address sanitizer - detects memory errors -# - leak sanitizer - detects memory leaks -# - loom - Permutation testing for concurrent code https://crates.io/crates/loom -# See check.yml for information about how the concurrency cancellation and workflow triggering works -permissions: - contents: read -on: - push: - branches: [main] - pull_request: -concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} - cancel-in-progress: true -name: safety -jobs: - sanitizers: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install nightly - uses: dtolnay/rust-toolchain@nightly - - run: | - # to get the symbolizer for debug symbol resolution - sudo apt install llvm - # to fix buggy leak analyzer: - # https://github.com/japaric/rust-san#unrealiable-leaksanitizer - # ensure there's a profile.dev section - if ! grep -qE '^[ \t]*[profile.dev]' Cargo.toml; then - echo >> Cargo.toml - echo '[profile.dev]' >> Cargo.toml - fi - # remove pre-existing opt-levels in profile.dev - sed -i '/^\s*\[profile.dev\]/,/^\s*\[/ {/^\s*opt-level/d}' Cargo.toml - # now set opt-level to 1 - sed -i '/^\s*\[profile.dev\]/a opt-level = 1' Cargo.toml - cat Cargo.toml - name: Enable debug symbols - - name: cargo test -Zsanitizer=address - # only --lib --tests b/c of https://github.com/rust-lang/rust/issues/53945 - run: cargo test --lib --tests --all-features --target x86_64-unknown-linux-gnu - env: - ASAN_OPTIONS: "detect_odr_violation=0:detect_leaks=0" - RUSTFLAGS: "-Z sanitizer=address" - - name: cargo test -Zsanitizer=leak - if: always() - run: cargo test --all-features --target x86_64-unknown-linux-gnu - env: - LSAN_OPTIONS: "suppressions=lsan-suppressions.txt" - RUSTFLAGS: "-Z sanitizer=leak" - miri: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - run: | - echo "NIGHTLY=nightly-$(curl -s https://rust-lang.github.io/rustup-components-history/x86_64-unknown-linux-gnu/miri)" >> $GITHUB_ENV - - name: Install ${{ env.NIGHTLY }} - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ env.NIGHTLY }} - components: miri - - name: cargo miri test - run: cargo miri test - env: - MIRIFLAGS: "" - loom: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: true - - name: Install stable - uses: dtolnay/rust-toolchain@stable - - name: cargo test --test loom - run: cargo test --release --test loom - env: - LOOM_MAX_PREEMPTIONS: 2 - RUSTFLAGS: "--cfg loom" diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 02aa275..347e586 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -8,7 +8,7 @@ on: branches: [main] pull_request: schedule: - - cron: '7 7 * * *' + - cron: "7 7 * * *" concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true @@ -27,8 +27,16 @@ jobs: - name: cargo generate-lockfile if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile - - name: cargo test --locked - run: cargo test --locked --all-features --all-targets + - name: ensure PostgreSQL service + run: | + docker compose -f docker/compose.yaml up -d --build + docker ps + sleep 10 + docker compose -f docker/compose.yaml logs postgres --tail 10 + - name: run e2e tests + env: + POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss + run: cargo test --locked --all-features --all-targets --test e2e -- --nocapture # https://twitter.com/alcuadrado/status/1571291687837732873 update: # This action checks that updating the dependencies of this crate to the latest available that @@ -51,8 +59,16 @@ jobs: - name: cargo update if: hashFiles('Cargo.lock') != '' run: cargo update - - name: cargo test + - name: ensure PostgreSQL service + if: hashFiles('Cargo.lock') != '' + run: | + docker compose -f docker/compose.yaml up -d --build + docker ps + sleep 10 + docker compose -f docker/compose.yaml logs postgres --tail 10 + - name: run e2e tests if: hashFiles('Cargo.lock') != '' - run: cargo test --locked --all-features --all-targets env: + POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss RUSTFLAGS: -D deprecated + run: cargo test --locked --all-features --all-targets --test e2e -- --nocapture diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f7540ae..3a37e17 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,21 @@ jobs: required: runs-on: ubuntu-latest name: ubuntu / ${{ matrix.toolchain }} + services: + postgres: + image: postgres:16.4 + env: + POSTGRES_USER: username + POSTGRES_PASSWORD: password + POSTGRES_HOST: "127.0.0.1" + POSTGRES_DB: "pgboss" + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 127.0.0.1:5444:5432 strategy: matrix: # run on stable and beta to ensure that tests won't break on the next version of the rust @@ -37,9 +52,10 @@ jobs: # enable this ci template to run regardless of whether the lockfile is checked in or not if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile - # https://twitter.com/jonhoo/status/1571290371124260865 - - name: cargo test --locked - run: cargo test --locked --all-features --all-targets + - name: run e2e tests + env: + POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss + run: cargo test --locked --all-features --all-targets --test e2e -- --nocapture # https://github.com/rust-lang/cargo/issues/6669 - name: cargo test --doc run: cargo test --locked --all-features --doc @@ -68,6 +84,21 @@ jobs: # This action is run on ubuntu with the stable toolchain, as it is not expected to fail runs-on: ubuntu-latest name: ubuntu / stable / minimal-versions + services: + postgres: + image: postgres:16.4 + env: + POSTGRES_USER: username + POSTGRES_PASSWORD: password + POSTGRES_HOST: "127.0.0.1" + POSTGRES_DB: "pgboss" + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 127.0.0.1:5444:5432 steps: - uses: actions/checkout@v4 with: @@ -80,12 +111,32 @@ jobs: run: rustup default stable - name: cargo update -Zminimal-versions run: cargo +nightly update -Zminimal-versions - - name: cargo test - run: cargo test --locked --all-features --all-targets + - name: run e2e tests + env: + POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss + run: cargo test --locked --all-features --all-targets --test e2e -- --nocapture os-check: # run cargo test on mac and windows runs-on: ${{ matrix.os }} name: ${{ matrix.os }} / stable + # Container actions are only supported on Linux runners as of August 24, 2024 + # So we are only building the library, not running e2e tests. + # + #services: + # postgres: + # image: postgres:16.4 + # env: + # POSTGRES_USER: username + # POSTGRES_PASSWORD: password + # POSTGRES_HOST: "127.0.0.1" + # POSTGRES_DB: "pgboss" + # options: >- + # --health-cmd pg_isready + # --health-interval 10s + # --health-timeout 5s + # --health-retries 5 + # ports: + # - 127.0.0.1:5444:5432 strategy: fail-fast: false matrix: @@ -105,8 +156,12 @@ jobs: - name: cargo generate-lockfile if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile - - name: cargo test - run: cargo test --locked --all-features --all-targets + - name: cargo build --release + run: cargo build --all-features --all-targets + #- name: run e2e tests + # env: + # POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss + # run: cargo test --locked --all-features --all-targets --test e2e -- --nocapture coverage: # use llvm-cov to build and collect coverage and outputs in a format that # is compatible with codecov.io @@ -144,8 +199,16 @@ jobs: - name: cargo generate-lockfile if: hashFiles('Cargo.lock') == '' run: cargo generate-lockfile + - name: ensure PostgeSQL service + run: | + docker compose -f docker/compose.yaml up -d --build + docker ps + sleep 10 + docker compose -f docker/compose.yaml logs postgres --tail 10 - name: cargo llvm-cov - run: cargo llvm-cov --locked --all-features --lcov --output-path lcov.info + env: + POSTGRES_URL: postgres://username:password@127.0.0.1:5444/pgboss + run: cargo llvm-cov --locked --all-features --test e2e --lcov --output-path lcov.info -- include-ignored - name: Record Rust version run: echo "RUST=$(rustc --version)" >> "$GITHUB_ENV" - name: Upload to codecov.io diff --git a/.gitignore b/.gitignore index 1e5c0df..4acb3df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/misc \ No newline at end of file +/misc +lcov.info \ No newline at end of file diff --git a/Makefile b/Makefile index c9db85a..7491839 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,12 @@ test/doc: .PHONY: test/e2e test/e2e: POSTGRES_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE} \ - cargo test --locked --all-features --all-targets --test e2e -- --nocapture + cargo test --locked --all-features --all-targets --test e2e -- --nocapture --include-ignored + +.PHONY: test/cov +test/cov: + POSTGRES_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DATABASE} \ + cargo llvm-cov --locked --all-features --lcov --test e2e --output-path lcov.info -- --include-ignored .PHONY: test test: test/e2e diff --git a/tests/e2e/client.rs b/tests/e2e/client.rs index 650a820..9d4476a 100644 --- a/tests/e2e/client.rs +++ b/tests/e2e/client.rs @@ -14,6 +14,9 @@ async fn simple_connect() { let _c = Client::connect().await.unwrap(); } +// On CI - when running on Ubuntu with our postgres service with TLS enabled - use '--include-ignored' +// to run this test, just like we do with `make test` and `make test/cov` +#[ignore = "this test requires a dedicated test run aganst PostgreSQL server with TLS enabled"] #[tokio::test] async fn bring_your_own_pool() { let local = "bring_your_own_pool";