From d4ace2c36392b37a083257bac5309212259e2beb Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Fri, 30 Aug 2024 15:23:07 +0200 Subject: [PATCH] Speed up other CI jobs by avoiding the usage of a live Postgres database --- .github/workflows/general.yml | 36 +++++++++---------- ...afd6439db2d49d0cb506618ae9e780c7e0558.json | 17 +++++++++ ...caa9da2220f8a9ad6c1debc3095deb9f84759.json | 26 ++++++++++++++ 3 files changed, 59 insertions(+), 20 deletions(-) create mode 100644 .sqlx/query-793f0df728d217c204123f12e4eafd6439db2d49d0cb506618ae9e780c7e0558.json create mode 100644 .sqlx/query-ed279fc2dda0c3ede3e81a4500fcaa9da2220f8a9ad6c1debc3095deb9f84759.json diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index 8a49167..7e9c3b6 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -21,6 +21,7 @@ jobs: test: name: Test runs-on: ubuntu-latest + # Service containers to run alongside the `test` container job services: postgres: # Docker Hub image @@ -43,6 +44,7 @@ jobs: # It also takes care of caching intermediate build artifacts. - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Install sqlx-cli run: cargo install sqlx-cli @@ -53,13 +55,18 @@ jobs: # The --locked flag can be used to force Cargo to use the packaged Cargo.lock file if it is available. # This may be useful for ensuring reproducible builds, to use the exact same set of dependencies that were available when the package was published. # It may also be useful if a newer version of a dependency is published that no longer builds on your system, or has other problems + - name: Migrate database run: | - sudo apt-get install libpq-dev -y SKIP_DOCKER=true ./scripts/init_db.sh + - name: Run tests run: cargo test + - name: Check that queries are fresh + run: cargo sqlx prepare --workspace --check -- --all-targets + + # `fmt` container job fmt: name: Rustfmt runs-on: ubuntu-latest @@ -75,31 +82,20 @@ jobs: clippy: name: Clippy runs-on: ubuntu-latest - services: - postgres: - image: postgres:14 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: password - POSTGRES_DB: postgres - ports: - - 5432:5432 + env: + # This environment variable forces sqlx to use its offline mode, + # which means that it will not attempt to connect to a database + # when running the tests. It'll instead use the cached query results. + # We check that the cached query results are up-to-date in another job, + # to speed up the overall CI pipeline. + # This will all be covered in detail in chapter 5. + SQLX_OFFLINE: true steps: - uses: actions/checkout@v4 - name: Install the Rust toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: clippy - - name: Install sqlx-cli - run: cargo install sqlx-cli - --version=${{ env.SQLX_VERSION }} - --features ${{ env.SQLX_FEATURES }} - --no-default-features - --locked - - name: Migrate database - run: | - sudo apt-get install libpq-dev -y - SKIP_DOCKER=true ./scripts/init_db.sh - name: Linting run: cargo clippy -- -D warnings diff --git a/.sqlx/query-793f0df728d217c204123f12e4eafd6439db2d49d0cb506618ae9e780c7e0558.json b/.sqlx/query-793f0df728d217c204123f12e4eafd6439db2d49d0cb506618ae9e780c7e0558.json new file mode 100644 index 0000000..349e0dd --- /dev/null +++ b/.sqlx/query-793f0df728d217c204123f12e4eafd6439db2d49d0cb506618ae9e780c7e0558.json @@ -0,0 +1,17 @@ +{ + "db_name": "PostgreSQL", + "query": "\n INSERT INTO subscriptions (id, email, name, subscribed_at)\n VALUES ($1, $2, $3, $4)\n ", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Uuid", + "Text", + "Text", + "Timestamptz" + ] + }, + "nullable": [] + }, + "hash": "793f0df728d217c204123f12e4eafd6439db2d49d0cb506618ae9e780c7e0558" +} diff --git a/.sqlx/query-ed279fc2dda0c3ede3e81a4500fcaa9da2220f8a9ad6c1debc3095deb9f84759.json b/.sqlx/query-ed279fc2dda0c3ede3e81a4500fcaa9da2220f8a9ad6c1debc3095deb9f84759.json new file mode 100644 index 0000000..5204918 --- /dev/null +++ b/.sqlx/query-ed279fc2dda0c3ede3e81a4500fcaa9da2220f8a9ad6c1debc3095deb9f84759.json @@ -0,0 +1,26 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT email, name FROM subscriptions", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "email", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + } + ], + "parameters": { + "Left": [] + }, + "nullable": [ + false, + false + ] + }, + "hash": "ed279fc2dda0c3ede3e81a4500fcaa9da2220f8a9ad6c1debc3095deb9f84759" +}