From 77724b3caf97e11f7735bf57d13cec6e3838f6b4 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:03:42 +0000 Subject: [PATCH 01/10] feat: add github workflow --- .github/workflows/ci.yaml | 82 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..13c3f07 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,82 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + branches: + - main + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 1 + CARGO_INCREMENTAL: "false" + +jobs: + Test: + strategy: + fail-fast: false # We want all of them to run, even if one fails + matrix: + os: [ ubuntu-latest, macos-latest ] + pg: [ "12", "13", "14", "15", "16" ] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - name: Install cargo-pgrx + run: | + PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') + cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force + cargo pgrx init --pg${{ matrix.pg }} download + - name: Run tests + run: echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }} + Install: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install PostgreSQL headers + run: | + sudo apt-get update + sudo apt-get install postgresql-server-dev-14 + - name: Install cargo-pgrx + run: | + PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') + cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force + cargo pgrx init --pg14 $(which pg_config) + - name: Install PL/PRQL + run: | + cd plprql + cargo pgrx install --no-default-features --release --sudo + - name: Start PostgreSQL + run: | + sudo systemctl start postgresql.service + pg_isready + # superuser (-s), can create databases (-d) and roles (-r), no password prompt (-w) named runner + sudo -u postgres createuser -s -d -r -w runner + - name: Verify install + run: | + createdb -U runner runner + psql -U runner -c "create extension typeid;" + psql -U runner -c "select typeid_generate('user');" + rustfmt: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Run rustfmt + run: cargo fmt -- --check + rust-clippy: + runs-on: ubuntu-latest + strategy: + matrix: + pg: [ "16" ] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Install cargo-pgrx + run: | + PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') + cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force + cargo pgrx init --pg${{ matrix.pg }} download + - name: Run clippy + run: cargo clippy --all-targets --no-default-features --features pg${{ matrix.pg }} -- -D warnings \ No newline at end of file From 95de2828d00eba567cbde853e8e97550bbf0cd26 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:15:59 +0000 Subject: [PATCH 02/10] fix: try to fix ci --- .github/workflows/ci.yaml | 12 ++++- src/base32.rs | 68 ++++++++++++------------ src/lib.rs | 20 +++---- src/typeid.rs | 106 ++++++++++++++++++++------------------ tests/spec.rs | 8 +-- 5 files changed, 112 insertions(+), 102 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 13c3f07..cf19fea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,6 +23,8 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + with: + path: typeid - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') @@ -34,6 +36,8 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + with: + path: typeid - name: Install PostgreSQL headers run: | sudo apt-get update @@ -43,9 +47,8 @@ jobs: PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force cargo pgrx init --pg14 $(which pg_config) - - name: Install PL/PRQL + - name: Install TypeID/PRQL run: | - cd plprql cargo pgrx install --no-default-features --release --sudo - name: Start PostgreSQL run: | @@ -63,6 +66,8 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + with: + path: typeid - name: Run rustfmt run: cargo fmt -- --check rust-clippy: @@ -73,6 +78,9 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + + with: + path: typeid - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') diff --git a/src/base32.rs b/src/base32.rs index 587b897..f84afb0 100644 --- a/src/base32.rs +++ b/src/base32.rs @@ -9,59 +9,57 @@ pub enum Error { } fn decode_base32_to_u128(id: &str) -> Result { - let mut id: [u8; 26] = id.as_bytes().try_into().map_err(|_| Error::InvalidData)?; - let mut max = 0; - for b in &mut id { - *b = CROCKFORD_INV[*b as usize]; - max |= *b; - } - if max > 32 || id[0] > 7 { - return Err(Error::InvalidData); - } + let mut id: [u8; 26] = id.as_bytes().try_into().map_err(|_| Error::InvalidData)?; + let mut max = 0; + for b in &mut id { + *b = CROCKFORD_INV[*b as usize]; + max |= *b; + } + if max > 32 || id[0] > 7 { + return Err(Error::InvalidData); + } - let mut out = 0u128; - for b in id { - out <<= 5; - out |= b as u128; - } + let mut out = 0u128; + for b in id { + out <<= 5; + out |= b as u128; + } - Ok(out) + Ok(out) } fn encode_u128_to_base32(data: u128) -> String { - let mut buf = [0u8; 26]; - let mut data = data; - for i in (0..26).rev() { - buf[i] = CROCKFORD[(data & 0x1f) as usize]; - debug_assert!(buf[i].is_ascii()); - data >>= 5; - } - unsafe { String::from_utf8_unchecked(buf.to_vec()) } + let mut buf = [0u8; 26]; + let mut data = data; + for i in (0..26).rev() { + buf[i] = CROCKFORD[(data & 0x1f) as usize]; + debug_assert!(buf[i].is_ascii()); + data >>= 5; + } + unsafe { String::from_utf8_unchecked(buf.to_vec()) } } const CROCKFORD: &[u8; 32] = b"0123456789abcdefghjkmnpqrstvwxyz"; const CROCKFORD_INV: &[u8; 256] = &{ - let mut output = [255; 256]; + let mut output = [255; 256]; - let mut i = 0; - while i < 32 { - output[CROCKFORD[i as usize] as usize] = i; - i += 1; - } + let mut i = 0; + while i < 32 { + output[CROCKFORD[i as usize] as usize] = i; + i += 1; + } - output + output }; - pub fn encode_base32_uuid(uuid: &Uuid) -> String { - encode_u128_to_base32(uuid.as_u128()) + encode_u128_to_base32(uuid.as_u128()) } pub fn decode_base32_uuid(encoded: &str) -> Result { - decode_base32_to_u128(encoded).map(|result: u128| Uuid::from_u128(result)) + decode_base32_to_u128(encoded).map(|result: u128| Uuid::from_u128(result)) } - #[cfg(test)] mod tests { use uuid::Uuid; @@ -76,4 +74,4 @@ mod tests { let decoded = decode_base32_uuid(&encoded).unwrap(); assert_eq!(uuid, decoded); } -} \ No newline at end of file +} diff --git a/src/lib.rs b/src/lib.rs index 470df0b..1eea36b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,6 @@ use pgrx::prelude::*; pgrx::pg_module_magic!(); - #[pg_extern] fn typeid_generate(prefix: &str) -> TypeID { TypeID::new(TypeIDPrefix::new(prefix).unwrap(), Uuid::now_v7()) @@ -23,7 +22,10 @@ fn typeid_to_uuid(typeid: TypeID) -> pgrx::Uuid { #[pg_extern] fn uuid_to_typeid(prefix: &str, uuid: pgrx::Uuid) -> TypeID { - TypeID::new(TypeIDPrefix::new(prefix).unwrap(), Uuid::from_slice(uuid.as_bytes()).unwrap()) + TypeID::new( + TypeIDPrefix::new(prefix).unwrap(), + Uuid::from_slice(uuid.as_bytes()).unwrap(), + ) } #[pg_extern] @@ -64,8 +66,8 @@ fn typeid_ne(a: TypeID, b: TypeID) -> bool { typeid_cmp(a, b) != 0 } -extension_sql!{ - r#" +extension_sql! { +r#" CREATE OPERATOR < ( LEFTARG = typeid, RIGHTARG = typeid, @@ -114,14 +116,14 @@ extension_sql!{ OPERATOR 5 > (typeid, typeid), FUNCTION 1 typeid_cmp(typeid, typeid); "#, - name = "create_typeid_operator_class", - finalize, - } + name = "create_typeid_operator_class", + finalize, +} /// Generate a UUID v7, producing a Postgres uuid object #[pg_extern] fn uuid_generate_v7() -> pgrx::Uuid { - pgrx::Uuid::from_bytes(*Uuid::now_v7().as_bytes()) + pgrx::Uuid::from_bytes(*Uuid::now_v7().as_bytes()) } #[cfg(any(test, feature = "pg_test"))] @@ -136,7 +138,6 @@ mod tests { assert_eq!(typeid.type_prefix(), "test"); } - #[pg_test] fn test_uuid() { let uuid: pgrx::Uuid = crate::uuid_generate_v7(); @@ -146,7 +147,6 @@ mod tests { assert_eq!(converted.get_version_num(), 7); } - } /// This module is required by `cargo pgrx test` invocations. diff --git a/src/typeid.rs b/src/typeid.rs index 1055343..7540184 100644 --- a/src/typeid.rs +++ b/src/typeid.rs @@ -2,8 +2,8 @@ use core::fmt; use std::borrow::Cow; use pgrx::prelude::*; +use serde::{Deserialize, Serialize}; use uuid::Uuid; -use serde::{Serialize, Deserialize}; use crate::base32::{decode_base32_uuid, encode_base32_uuid}; @@ -36,7 +36,7 @@ impl TypeIDPrefix { } pub fn try_unsafe(tag: &str) -> Self { - Self(tag.to_string()) + Self(tag.to_string()) } fn try_from_type_prefix(tag: &str) -> Result> { @@ -77,58 +77,62 @@ impl TypeIDPrefix { pub struct TypeID(TypeIDPrefix, Uuid); impl TypeID { - pub fn new(type_prefix: TypeIDPrefix, uuid: Uuid) -> Self { - TypeID(type_prefix, uuid) - } - - pub fn from_string(id: &str) -> Result { - // Split the input string once at the first occurrence of '_' - let (tag, id) = match id.rsplit_once('_') { - Some(("", _)) => return Err(Error::InvalidType), - Some((tag, id)) => (tag, id), - None => ("", id), - }; - - // Decode the UUID part and handle potential errors - let uuid = decode_base32_uuid(id).map_err(|_| Error::InvalidData)?; - - let prefix = TypeIDPrefix::new(tag)?; - - // Create and return the TypeID - Ok(TypeID(prefix, uuid)) - } - - pub fn type_prefix(&self) -> &str { - &self.0.to_type_prefix() - } - - pub fn uuid(&self) -> &Uuid { - &self.1 - } + pub fn new(type_prefix: TypeIDPrefix, uuid: Uuid) -> Self { + TypeID(type_prefix, uuid) + } + + pub fn from_string(id: &str) -> Result { + // Split the input string once at the first occurrence of '_' + let (tag, id) = match id.rsplit_once('_') { + Some(("", _)) => return Err(Error::InvalidType), + Some((tag, id)) => (tag, id), + None => ("", id), + }; + + // Decode the UUID part and handle potential errors + let uuid = decode_base32_uuid(id).map_err(|_| Error::InvalidData)?; + + let prefix = TypeIDPrefix::new(tag)?; + + // Create and return the TypeID + Ok(TypeID(prefix, uuid)) + } + + pub fn type_prefix(&self) -> &str { + self.0.to_type_prefix() + } + + pub fn uuid(&self) -> &Uuid { + &self.1 + } } impl fmt::Display for TypeID { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.type_prefix().is_empty() { - write!(f, "{}", encode_base32_uuid(self.uuid())) - } else { - write!(f, "{}_{}", self.type_prefix(), encode_base32_uuid(self.uuid())) - } - } + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + if self.type_prefix().is_empty() { + write!(f, "{}", encode_base32_uuid(self.uuid())) + } else { + write!( + f, + "{}_{}", + self.type_prefix(), + encode_base32_uuid(self.uuid()) + ) + } + } } - impl InOutFuncs for TypeID { - fn input(input: &core::ffi::CStr) -> TypeID { - // Convert the input to a str and handle potential UTF-8 errors - let str_input = input.to_str().expect("text input is not valid UTF8"); - - TypeID::from_string(str_input).unwrap() - } - - fn output(&self, buffer: &mut pgrx::StringInfo) { - // Use write! macro to directly push the string representation into the buffer - use std::fmt::Write; - write!(buffer, "{}", self).expect("Failed to write to buffer"); - } -} \ No newline at end of file + fn input(input: &core::ffi::CStr) -> TypeID { + // Convert the input to a str and handle potential UTF-8 errors + let str_input = input.to_str().expect("text input is not valid UTF8"); + + TypeID::from_string(str_input).unwrap() + } + + fn output(&self, buffer: &mut pgrx::StringInfo) { + // Use write! macro to directly push the string representation into the buffer + use std::fmt::Write; + write!(buffer, "{}", self).expect("Failed to write to buffer"); + } +} diff --git a/tests/spec.rs b/tests/spec.rs index da39552..0c138df 100644 --- a/tests/spec.rs +++ b/tests/spec.rs @@ -1,6 +1,6 @@ use libtest_mimic::{Arguments, Trial}; use serde::Deserialize; -use typeid::typeid::{TypeID}; +use typeid::typeid::TypeID; use uuid::Uuid; #[derive(Deserialize)] @@ -27,8 +27,8 @@ fn main() { for test in valid { tests.push(Trial::test(format!("valid::{}", test.name), move || { let id = match TypeID::from_string(&test.typeid) { - Ok(id) => id, - Err(e) => return Err(e.to_string().into()), + Ok(id) => id, + Err(e) => return Err(e.to_string().into()), }; if id.uuid().ne(&test.uuid) { @@ -60,4 +60,4 @@ fn main() { let args = Arguments::from_args(); libtest_mimic::run(&args, tests).exit_if_failed(); -} \ No newline at end of file +} From b57d30ff55c44e9d408ef9e9df1f8aa136f66223 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:20:33 +0000 Subject: [PATCH 03/10] fix: setting with.path on workflow didn't work so I rename the repo --- .github/workflows/ci.yaml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index cf19fea..39e2f4a 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -23,8 +23,6 @@ jobs: runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 - with: - path: typeid - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') @@ -36,8 +34,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - path: typeid - name: Install PostgreSQL headers run: | sudo apt-get update @@ -66,8 +62,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - with: - path: typeid - name: Run rustfmt run: cargo fmt -- --check rust-clippy: @@ -78,9 +72,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - with: - path: typeid - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') From 8023af0c2dc1711597bf30eab4c4d60f068fb3cd Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:30:24 +0000 Subject: [PATCH 04/10] feat: kinda curious how clippy will pan out --- .github/workflows/ci.yaml | 19 ++-------- .github/workflows/clippy.yaml | 66 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/clippy.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 39e2f4a..247bf3c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -43,7 +43,7 @@ jobs: PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force cargo pgrx init --pg14 $(which pg_config) - - name: Install TypeID/PRQL + - name: Install TypeID/pgrx run: | cargo pgrx install --no-default-features --release --sudo - name: Start PostgreSQL @@ -63,19 +63,4 @@ jobs: - name: Checkout code uses: actions/checkout@v4 - name: Run rustfmt - run: cargo fmt -- --check - rust-clippy: - runs-on: ubuntu-latest - strategy: - matrix: - pg: [ "16" ] - steps: - - name: Checkout code - uses: actions/checkout@v4 - - name: Install cargo-pgrx - run: | - PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') - cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force - cargo pgrx init --pg${{ matrix.pg }} download - - name: Run clippy - run: cargo clippy --all-targets --no-default-features --features pg${{ matrix.pg }} -- -D warnings \ No newline at end of file + run: cargo fmt -- --check \ No newline at end of file diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml new file mode 100644 index 0000000..3ee69ff --- /dev/null +++ b/.github/workflows/clippy.yaml @@ -0,0 +1,66 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# rust-clippy is a tool that runs a bunch of lints to catch common +# mistakes in your Rust code and help improve your Rust code. +# More details at https://github.com/rust-lang/rust-clippy +# and https://rust-lang.github.io/rust-clippy/ + +name: rust-clippy analyze + +on: + push: + branches: [ "main" ] + pull_request: + # The branches below must be a subset of the branches above + branches: [ "main" ] + schedule: + - cron: '20 14 * * 5' + +jobs: + rust-clippy-analyze: + name: Run rust-clippy analyzing + runs-on: ubuntu-latest + + strategy: + matrix: + pg: [ "16" ] + permissions: + contents: read + security-events: write + actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af #@v1 + with: + profile: minimal + toolchain: stable + components: clippy + override: true + + + - name: Install cargo-pgrx + run: | + PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') + cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force + cargo pgrx init --pg${{ matrix.pg }} download + + - name: Install required cargo + run: cargo install clippy-sarif sarif-fmt + + - name: Run rust-clippy + run: + cargo clippy + --all-features + --message-format=json | clippy-sarif | tee rust-clippy-results.sarif | sarif-fmt + continue-on-error: true + + - name: Upload analysis results to GitHub + uses: github/codeql-action/upload-sarif@v1 + with: + sarif_file: rust-clippy-results.sarif + wait-for-processing: true \ No newline at end of file From 5cadce53e08c60e67c5b5099122da1a0f06e4497 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:53:52 +0000 Subject: [PATCH 05/10] feat: first attempt at caching --- .github/workflows/ci.yaml | 117 +++++++++++++++++++++++++++++++++- .github/workflows/clippy.yaml | 4 +- 2 files changed, 117 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 247bf3c..29a1cd6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,18 +18,131 @@ jobs: strategy: fail-fast: false # We want all of them to run, even if one fails matrix: - os: [ ubuntu-latest, macos-latest ] + os: ubuntu-latest pg: [ "12", "13", "14", "15", "16" ] + include: + - postgres: 16 + rust: "beta" + runs-on: ${{ matrix.os }} + env: + RUSTC_WRAPPER: sccache + SCCACHE_DIR: /home/runner/.cache/sccache + PG_VER: ${{ matrix.postgres }} + RUST_TOOLCHAIN: ${{ matrix.rust || 'stable' }} steps: - uses: actions/checkout@v4 + - name: Set up prerequisites and environment + run: | + sudo apt-get update -y -qq --fix-missing + + echo "" + echo "----- Install sccache -----" + mkdir -p $HOME/.local/bin + curl -L https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz | tar xz + mv -f sccache-v0.2.15-x86_64-unknown-linux-musl/sccache $HOME/.local/bin/sccache + chmod +x $HOME/.local/bin/sccache + echo "$HOME/.local/bin" >> $GITHUB_PATH + mkdir -p /home/runner/.cache/sccache + echo "" + + echo "----- Set up dynamic variables -----" + cat $GITHUB_ENV + echo "" + + echo "----- Remove old postgres -----" + sudo apt remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' + echo "" + + echo "----- Install system dependencies -----" + sudo apt-get install -y \ + build-essential \ + llvm-14-dev libclang-14-dev clang-14 \ + gcc \ + libssl-dev \ + libz-dev \ + make \ + pkg-config \ + strace \ + zlib1g-dev + echo "" + ./ci/rustup.sh + echo "----- Set up cross compilation -----" + sudo apt-get install -y --fix-missing crossbuild-essential-arm64 + echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV + # TODO: not all of these should be needed, but for now it's likely fine. + echo 'BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu=-target aarch64-unknown-linux-gnu -isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc' >> $GITHUB_ENV + + echo "----- Print env -----" + env + echo "" + + - name: Install release version of PostgreSQL + run: | + echo "----- Set up PostgreSQL Apt repository -----" + sudo apt-get install -y wget gnupg + 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 -y -qq --fix-missing + echo "" + + sudo apt-get install -y \ + postgresql-$PG_VER \ + postgresql-server-dev-$PG_VER + + echo "" + echo "----- pg_config -----" + pg_config + echo "" + - name: Set up PostgreSQL permissions + run: sudo chmod a+rwx `/usr/lib/postgresql/$PG_VER/bin/pg_config --pkglibdir` `/usr/lib/postgresql/$PG_VER/bin/pg_config --sharedir`/extension /var/run/postgresql/ + + - name: Cache cargo registry + uses: actions/cache@v4 + continue-on-error: false + with: + path: | + ~/.cargo/registry + ~/.cargo/git + key: tests-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }} + + - name: Cache sccache directory + uses: actions/cache@v4 + continue-on-error: false + with: + path: /home/runner/.cache/sccache + key: pgrx-tests-sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }} + + - name: Start sccache server + run: sccache --start-server + + - name: Print sccache stats (before run) + run: sccache --show-stats + - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force - cargo pgrx init --pg${{ matrix.pg }} download + cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/$PG_VER/bin/pg_config - name: Run tests run: echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }} + + # Attempt to make the cache payload slightly smaller. + - name: Clean up built PGRX files + run: | + cd target/debug/deps/ + for built_file in $(find * -type f -executable -print | grep -v "\.so$"); do + base_name=$(echo $built_file | cut -d- -f1); + for basefile in "$base_name".*; do + [ -f "$basefile" ] || continue; + echo "Removing $basefile" + rm $basefile + done; + echo "Removing $built_file" + rm $built_file + done + - name: Stop sccache server + run: sccache --stop-server || true Install: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml index 3ee69ff..31c8219 100644 --- a/.github/workflows/clippy.yaml +++ b/.github/workflows/clippy.yaml @@ -48,7 +48,7 @@ jobs: PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force cargo pgrx init --pg${{ matrix.pg }} download - + - name: Install required cargo run: cargo install clippy-sarif sarif-fmt @@ -60,7 +60,7 @@ jobs: continue-on-error: true - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v1 + uses: github/codeql-action/upload-sarif@v2 with: sarif_file: rust-clippy-results.sarif wait-for-processing: true \ No newline at end of file From fc29b12f3ada96e4825c8d5af425fd5b95c99ec0 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:54:45 +0000 Subject: [PATCH 06/10] feat: 2nd attempt at caching --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 29a1cd6..f1a7a8d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,7 +32,7 @@ jobs: RUST_TOOLCHAIN: ${{ matrix.rust || 'stable' }} steps: - uses: actions/checkout@v4 - - name: Set up prerequisites and environment + - name: Set up prerequisites and environment run: | sudo apt-get update -y -qq --fix-missing From 54541475807ea0bc86954c320f12e715564e15dd Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 22:59:51 +0000 Subject: [PATCH 07/10] feat: 3rd attempt at caching --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f1a7a8d..f6e2391 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false # We want all of them to run, even if one fails matrix: - os: ubuntu-latest + os: [ "ubuntu-latest" ] pg: [ "12", "13", "14", "15", "16" ] include: - postgres: 16 From bb761a8930550b8c25f69cc0e198199cea6d3366 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 23:04:36 +0000 Subject: [PATCH 08/10] feat: 4th attempt at caching --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f6e2391..afb7125 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -66,7 +66,6 @@ jobs: strace \ zlib1g-dev echo "" - ./ci/rustup.sh echo "----- Set up cross compilation -----" sudo apt-get install -y --fix-missing crossbuild-essential-arm64 echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV From d0612e43406800a4d87187b01f9d2c5d45f99919 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 23:11:57 +0000 Subject: [PATCH 09/10] feat: 5th attempt at caching --- .github/workflows/ci.yaml | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index afb7125..4a24df8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -20,15 +20,11 @@ jobs: matrix: os: [ "ubuntu-latest" ] pg: [ "12", "13", "14", "15", "16" ] - include: - - postgres: 16 - rust: "beta" - + runs-on: ${{ matrix.os }} env: RUSTC_WRAPPER: sccache SCCACHE_DIR: /home/runner/.cache/sccache - PG_VER: ${{ matrix.postgres }} RUST_TOOLCHAIN: ${{ matrix.rust || 'stable' }} steps: - uses: actions/checkout@v4 @@ -50,10 +46,6 @@ jobs: cat $GITHUB_ENV echo "" - echo "----- Remove old postgres -----" - sudo apt remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' - echo "" - echo "----- Install system dependencies -----" sudo apt-get install -y \ build-essential \ @@ -66,12 +58,6 @@ jobs: strace \ zlib1g-dev echo "" - echo "----- Set up cross compilation -----" - sudo apt-get install -y --fix-missing crossbuild-essential-arm64 - echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV - # TODO: not all of these should be needed, but for now it's likely fine. - echo 'BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu=-target aarch64-unknown-linux-gnu -isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc' >> $GITHUB_ENV - echo "----- Print env -----" env echo "" @@ -86,15 +72,15 @@ jobs: echo "" sudo apt-get install -y \ - postgresql-$PG_VER \ - postgresql-server-dev-$PG_VER + postgresql-${{ matrix.pg }} \ + postgresql-server-dev-${{ matrix.pg }} echo "" echo "----- pg_config -----" pg_config echo "" - name: Set up PostgreSQL permissions - run: sudo chmod a+rwx `/usr/lib/postgresql/$PG_VER/bin/pg_config --pkglibdir` `/usr/lib/postgresql/$PG_VER/bin/pg_config --sharedir`/extension /var/run/postgresql/ + run: sudo chmod a+rwx `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --pkglibdir` `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --sharedir`/extension /var/run/postgresql/ - name: Cache cargo registry uses: actions/cache@v4 @@ -122,7 +108,7 @@ jobs: run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force - cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/$PG_VER/bin/pg_config + cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config - name: Run tests run: echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }} From ccce8013f549825f6e608b06e63808246e794f71 Mon Sep 17 00:00:00 2001 From: Andrew Vasilyev Date: Sun, 23 Jun 2024 23:38:49 +0000 Subject: [PATCH 10/10] feat: build in ci as well --- .github/workflows/ci.yaml | 9 +++++++++ .github/workflows/clippy.yaml | 26 +++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4a24df8..740a0d5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -112,6 +112,15 @@ jobs: - name: Run tests run: echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }} + - name: Build + run: cargo pgrx package --features pg${{ matrix.pg }} --pg-config /usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config + + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + with: + name: typeid-${{matrix.pg}} + path: | + target/release/typeid-pg${{ matrix.pg }} # Attempt to make the cache payload slightly smaller. - name: Clean up built PGRX files run: | diff --git a/.github/workflows/clippy.yaml b/.github/workflows/clippy.yaml index 31c8219..289ebe2 100644 --- a/.github/workflows/clippy.yaml +++ b/.github/workflows/clippy.yaml @@ -41,13 +41,33 @@ jobs: toolchain: stable components: clippy override: true - + + - name: Install release version of PostgreSQL + run: | + echo "----- Set up PostgreSQL Apt repository -----" + sudo apt-get install -y wget gnupg + 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 -y -qq --fix-missing + echo "" + + sudo apt-get install -y \ + postgresql-${{ matrix.pg }} \ + postgresql-server-dev-${{ matrix.pg }} + + echo "" + echo "----- pg_config -----" + pg_config + echo "" + + - name: Set up PostgreSQL permissions + run: sudo chmod a+rwx `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --pkglibdir` `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --sharedir`/extension /var/run/postgresql/ - name: Install cargo-pgrx run: | PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version') cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force - cargo pgrx init --pg${{ matrix.pg }} download + cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config - name: Install required cargo run: cargo install clippy-sarif sarif-fmt @@ -60,7 +80,7 @@ jobs: continue-on-error: true - name: Upload analysis results to GitHub - uses: github/codeql-action/upload-sarif@v2 + uses: github/codeql-action/upload-sarif@v3 with: sarif_file: rust-clippy-results.sarif wait-for-processing: true \ No newline at end of file