From 4fb1dd5b768157cae722f9d40f0a5803011dd9e5 Mon Sep 17 00:00:00 2001 From: Mingzhuo Yin Date: Tue, 17 Oct 2023 08:00:33 +0800 Subject: [PATCH] ci: run ci when updating tests dir (#92) * ci: run ci when updating tests dir Signed-off-by: silver-ymz * change src Signed-off-by: silver-ymz * use sudo to install extension Signed-off-by: silver-ymz * update ci Signed-off-by: silver-ymz * Elevate permissions Signed-off-by: silver-ymz * update ci Signed-off-by: silver-ymz * fix wrong quotation marks in command Signed-off-by: silver-ymz * fix wrong quotation marks in command Signed-off-by: silver-ymz * use ankane/setup-postgres Signed-off-by: silver-ymz * chmod for postgres dir Signed-off-by: silver-ymz * fix indent Signed-off-by: silver-ymz * set testdb Signed-off-by: silver-ymz * add github cache Signed-off-by: silver-ymz * alter password Signed-off-by: silver-ymz * ignore if binary installed Signed-off-by: silver-ymz * update pg_config path Signed-off-by: silver-ymz * revert ankane/setup-postgres Signed-off-by: silver-ymz * use sccache Signed-off-by: silver-ymz * close previous postgres Signed-off-by: silver-ymz * fix wrong quotation marks Signed-off-by: silver-ymz --------- Signed-off-by: silver-ymz --- .github/workflows/check.yml | 72 ++++++++++++++++++++++++++++++----- .github/workflows/release.yml | 14 ++++++- src/lib.rs | 1 - 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index def641b72..16c9a31f2 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -4,17 +4,21 @@ on: push: branches: [ "main" ] paths: + - '.github/workflows/check.yml' - 'src/**' - 'Cargo.toml' - 'Cargo.lock' - 'rust-toolchain.toml' + - 'tests/**' pull_request: branches: [ "main" ] paths: + - '.github/workflows/check.yml' - 'src/**' - 'Cargo.toml' - 'Cargo.lock' - 'rust-toolchain.toml' + - 'tests/**' merge_group: workflow_dispatch: @@ -24,6 +28,8 @@ concurrency: env: CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: true + RUSTC_WRAPPER: sccache jobs: lint: @@ -33,13 +39,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: cargo-${{ runner.os }}-pg${{ matrix.version }}-${{ hashFiles('./Cargo.toml') }} + restore-keys: cargo-${{ runner.os }}-pg${{ matrix.version }} + - uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare run: | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install libpq-dev postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }} - cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) + cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) || true cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config - name: Format check run: cargo fmt --check @@ -53,13 +69,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: cargo-${{ runner.os }}-pg${{ matrix.version }}-${{ hashFiles('./Cargo.toml') }} + restore-keys: cargo-${{ runner.os }}-pg${{ matrix.version }} + - uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare run: | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install libpq-dev postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }} - cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) + cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) || true cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config - name: Build run: cargo build --verbose @@ -75,19 +101,47 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: cargo-${{ runner.os }}-pg${{ matrix.version }}-${{ hashFiles('./Cargo.toml') }} + restore-keys: cargo-${{ runner.os }}-pg${{ matrix.version }} + - uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare run: | + sudo pg_dropcluster 14 main sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install libpq-dev postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }} - cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) + cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) || true cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config - cargo install sqllogictest-bin - - name: Build && Install - run: cargo pgrx install --release + cargo install sqllogictest-bin || true + - uses: actions/cache/save@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: cargo-${{ runner.os }}-pg${{ matrix.version }}-${{ hashFiles('./Cargo.toml') }} + - name: Build + run: | + sudo chmod -R 777 /usr/share/postgresql/${{ matrix.version }}/extension + sudo chmod -R 777 /usr/lib/postgresql/${{ matrix.version }}/lib + cargo pgrx install --release + sudo systemctl start postgresql@${{ matrix.version }}-main + sudo -u postgres psql -c "CREATE USER $USER LOGIN SUPERUSER" + sudo -u postgres psql -c "CREATE DATABASE $USER OWNER $USER" + psql -c 'ALTER SYSTEM SET shared_preload_libraries = "vectors.so"' + sudo systemctl restart postgresql@${{ matrix.version }}-main - name: Sqllogictest run: | - sudo systemctl restart postgresql - sudo -u postgres psql -f tests/init.sql - sudo -u postgres sqllogictest './tests/**/*.slt' \ No newline at end of file + export password=$(openssl rand -base64 32) + psql -c "ALTER USER $USER WITH PASSWORD '$password'" + psql -f ./tests/init.sql + sqllogictest -u "$USER" -w "$password" -d "$USER" './tests/**/*.slt' \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dcc00bc93..b28590a99 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -33,6 +33,8 @@ permissions: env: CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: true + RUSTC_WRAPPER: sccache jobs: setup: @@ -107,13 +109,23 @@ jobs: uses: actions/checkout@v3 with: ref: ${{ needs.setup.outputs.ref }} + - uses: actions/cache/restore@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: cargo-${{ runner.os }}-pg${{ matrix.version }}-${{ hashFiles('./Cargo.toml') }} + restore-keys: cargo-${{ runner.os }}-pg${{ matrix.version }} + - uses: mozilla-actions/sccache-action@v0.0.3 - name: Prepare run: | sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - sudo apt-get update sudo apt-get -y install libpq-dev postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }} - cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) + cargo install cargo-pgrx --git https://github.com/tensorchord/pgrx.git --rev $(cat Cargo.toml | grep "pgrx =" | awk -F'rev = "' '{print $2}' | cut -d'"' -f1) || true cargo pgrx init --pg${{ matrix.version }}=/usr/lib/postgresql/${{ matrix.version }}/bin/pg_config - name: Build Release id: build_release diff --git a/src/lib.rs b/src/lib.rs index c565b5f94..7d47c7a08 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -22,7 +22,6 @@ mod postgres; mod prelude; pgrx::pg_module_magic!(); - pgrx::extension_sql_file!("./sql/bootstrap.sql", bootstrap); pgrx::extension_sql_file!("./sql/finalize.sql", finalize);