Skip to content

Commit c535470

Browse files
authored
Merge pull request #5 from blitss/staging
add CI publish
2 parents c66680b + 94f5c26 commit c535470

File tree

7 files changed

+226
-5
lines changed

7 files changed

+226
-5
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[target.'cfg(target_os="macos")']
22
# Postgres symbols won't be available until runtime
3-
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup", "-C target-feature=+aes,+sse2"]
3+
rustflags = ["-Clink-arg=-Wl,-undefined,dynamic_lookup"]
44

55
[target.'cfg(target_arch = "x86_64")']
66
rustflags = ["-C", "target-feature=+aes"]

.github/workflows/release.yaml

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Build and Publish TypeID Extension
2+
3+
permissions:
4+
contents: write
5+
6+
on:
7+
push:
8+
tags:
9+
- 'v*'
10+
11+
env:
12+
EXTENSION_NAME: typeid
13+
DOCKER_IMAGE: ghcr.io/blitss/typeid-pg
14+
15+
jobs:
16+
build-and-publish:
17+
strategy:
18+
fail-fast: false # We want all of them to run, even if one fails
19+
matrix:
20+
pg_version: [12, 13, 14, 15, 16]
21+
os: [ubuntu-latest, macos-latest]
22+
arch: [amd64, arm64]
23+
exclude:
24+
- os: macos-latest
25+
arch: amd64
26+
27+
runs-on: ${{ matrix.os }}
28+
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
- name: Set up Rust
33+
uses: actions-rs/toolchain@v1
34+
with:
35+
toolchain: stable
36+
override: true
37+
38+
- name: Install PostgreSQL (Linux)
39+
if: runner.os == 'Linux'
40+
run: |
41+
sudo apt-get install -y wget gnupg
42+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
43+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
44+
sudo apt-get update -y -qq --fix-missing
45+
sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
46+
47+
sudo chmod a+rwx `/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config --pkglibdir` `/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config --sharedir`/extension /var/run/postgresql/
48+
49+
- name: Install PostgreSQL (macOS)
50+
if: runner.os == 'macOS'
51+
run: |
52+
brew install postgresql@${{ matrix.pg_version }}
53+
echo "/usr/local/opt/postgresql@${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
54+
55+
- name: Install cargo-pgrx
56+
run: |
57+
if [ "${{ runner.os }}" == "Linux" ]; then
58+
PG_CONFIG_PATH="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
59+
else
60+
PG_CONFIG_PATH="/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin/pg_config"
61+
fi
62+
PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
63+
cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
64+
cargo pgrx init --pg${{ matrix.pg_version }} $PG_CONFIG_PATH
65+
66+
- name: Build
67+
run: |
68+
if [ "${{ runner.os }}" == "Linux" ]; then
69+
PG_CONFIG_PATH="/usr/lib/postgresql/${{ matrix.pg_version }}/bin/pg_config"
70+
else
71+
PG_CONFIG_PATH="/opt/homebrew/opt/postgresql@${{ matrix.pg_version }}/bin/pg_config"
72+
fi
73+
cargo pgrx package --features pg${{ matrix.pg_version }} --pg-config $PG_CONFIG_PATH
74+
75+
- name: Set lowercase OS name
76+
run: echo "LOWERCASE_OS=$(echo ${{ runner.os }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
77+
78+
- name: Package Extension
79+
run: |
80+
mkdir -p release
81+
tar -czvf release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ env.LOWERCASE_OS }}-${{ matrix.arch }}.tar.gz -C target/release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }} .
82+
83+
- name: Upload Release Asset
84+
uses: softprops/action-gh-release@v1
85+
with:
86+
files: release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ env.LOWERCASE_OS }}-${{ matrix.arch }}.tar.gz
87+
88+
build-and-push-docker:
89+
needs: build-and-publish
90+
runs-on: ubuntu-latest
91+
steps:
92+
- uses: actions/checkout@v3
93+
94+
- name: Set up QEMU
95+
uses: docker/setup-qemu-action@v2
96+
97+
- name: Set up Docker Buildx
98+
uses: docker/setup-buildx-action@v2
99+
100+
- name: Login to GHCR
101+
uses: docker/login-action@v2
102+
with:
103+
registry: ghcr.io
104+
username: ${{ github.actor }}
105+
password: ${{ secrets.GITHUB_TOKEN }}
106+
107+
- name: Build and push Docker image
108+
uses: docker/build-push-action@v4
109+
with:
110+
context: .
111+
push: true
112+
platforms: linux/amd64,linux/arm64
113+
tags: |
114+
${{ env.DOCKER_IMAGE }}:latest
115+
${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "typeid"
3-
version = "0.0.0"
3+
version = "0.1.0"
44
edition = "2021"
55

66
[lib]

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG PG_VERSION=16
2+
3+
# Stage 1: Build the extension
4+
FROM rust:latest AS builder
5+
6+
ARG PG_VERSION=16
7+
8+
RUN apt-get update && apt-get install -y \
9+
wget \
10+
gnupg \
11+
lsb-release \
12+
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
13+
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
14+
&& apt-get update \
15+
&& apt-get install -y postgresql-${PG_VERSION} postgresql-server-dev-${PG_VERSION}
16+
17+
WORKDIR /usr/src/typeid
18+
19+
COPY . .
20+
21+
RUN cargo install cargo-pgrx \
22+
&& cargo pgrx init --pg${PG_VERSION} /usr/lib/postgresql/${PG_VERSION}/bin/pg_config \
23+
&& cargo pgrx package --pg-config /usr/lib/postgresql/${PG_VERSION}/bin/pg_config
24+
25+
RUN ls -R /usr/src/typeid/target/release/
26+
27+
# Stage 2: Create the final Postgres image with the extension
28+
FROM postgres:${PG_VERSION}
29+
30+
ARG PG_VERSION=16
31+
32+
# Copy the built extension files from the builder stage
33+
# Copy the built extension files
34+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/lib/postgresql/${PG_VERSION}/lib/typeid.so /usr/lib/postgresql/${PG_VERSION}/lib/
35+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid.control /usr/share/postgresql/${PG_VERSION}/extension/
36+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid--0.1.0.sql /usr/share/postgresql/${PG_VERSION}/extension/
37+
38+
# Enable the extension
39+
RUN echo "shared_preload_libraries = 'typeid'" >> /usr/share/postgresql/postgresql.conf.sample

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,6 @@ age | Internal name | Description
8686
public | typeid_lt | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_lt_wrapper |
8787
public | typeid_ne | boolean | a typeid, b typeid | func | volatile | unsafe | codespace | invoker | | c | typeid_ne_wrapper |
8888
public | typeid_out | cstring | input typeid | func | immutable | safe | codespace | invoker | | c | typeid_out_wrapper |
89-
public | uuid_generate_v7 | uuid | | func | volatile | unsafe | codespace | invoker | | c | uuid_generate_v7_wrapper |
89+
public | typeid_uuid_generate_v7 | uuid | | func | volatile | unsafe | codespace | invoker | | c | uuid_generate_v7_wrapper |
9090
(11 rows)
9191
```

install.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Check if a custom pg_config path is provided
6+
if [ $# -eq 1 ]; then
7+
PG_CONFIG="$1"
8+
else
9+
PG_CONFIG=$(which pg_config)
10+
fi
11+
12+
# Function to get the latest release version
13+
get_latest_release() {
14+
curl --silent "https://api.github.com/repos/blitss/typeid-postgres/releases/latest" |
15+
grep '"tag_name":' |
16+
sed -E 's/.*"([^"]+)".*/\1/'
17+
}
18+
19+
# Detect OS and architecture
20+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
21+
ARCH=$(uname -m)
22+
23+
if [ "$ARCH" = "x86_64" ]; then
24+
ARCH="amd64"
25+
elif [ "$ARCH" = "aarch64" ] || [ "$ARCH" = "arm64" ]; then
26+
ARCH="arm64"
27+
else
28+
echo "Unsupported architecture: $ARCH"
29+
exit 1
30+
fi
31+
32+
# Get PostgreSQL version
33+
PG_VERSION=$("$PG_CONFIG" --version | awk '{print $2}' | cut -d. -f1)
34+
35+
if [ -z "$PG_VERSION" ]; then
36+
echo "PostgreSQL not found. Please install PostgreSQL and make sure 'pg_config' is in your PATH or provide the path to pg_config as an argument."
37+
exit 1
38+
fi
39+
40+
# Get the latest release version
41+
RELEASE_VERSION=$(get_latest_release)
42+
43+
# Download URL
44+
DOWNLOAD_URL="https://github.com/blitss/typeid-postgres/releases/download/${RELEASE_VERSION}/typeid-pg${PG_VERSION}-${OS}-${ARCH}.tar.gz"
45+
46+
# Temporary directory for extraction
47+
TMP_DIR=$(mktemp -d)
48+
49+
# Download and extract
50+
echo "Downloading TypeID extension from $DOWNLOAD_URL"
51+
curl -L "$DOWNLOAD_URL" | tar xz -C "$TMP_DIR"
52+
53+
# Get PostgreSQL directories
54+
EXTENSION_DIR=$("$PG_CONFIG" --sharedir)/extension
55+
LIB_DIR=$("$PG_CONFIG" --pkglibdir)
56+
57+
# Install files
58+
echo "Installing TypeID extension..."
59+
sudo cp "$TMP_DIR"/usr/share/postgresql/*/extension/typeid.control "$EXTENSION_DIR"
60+
sudo cp "$TMP_DIR"/usr/share/postgresql/*/extension/typeid--*.sql "$EXTENSION_DIR"
61+
sudo cp "$TMP_DIR"/usr/lib/postgresql/*/lib/typeid.so "$LIB_DIR"
62+
63+
# Clean up
64+
rm -rf "$TMP_DIR"
65+
66+
echo "TypeID extension installed successfully."
67+
echo "To enable the extension, run: CREATE EXTENSION typeid;"

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ r#"
144144

145145
/// Generate a UUID v7, producing a Postgres uuid object
146146
#[pg_extern]
147-
fn uuid_generate_v7() -> pgrx::Uuid {
147+
fn typeid_uuid_generate_v7() -> pgrx::Uuid {
148148
pgrx::Uuid::from_bytes(*Uuid::now_v7().as_bytes())
149149
}
150150

@@ -163,7 +163,7 @@ mod tests {
163163

164164
#[pg_test]
165165
fn test_uuid() {
166-
let uuid: pgrx::Uuid = crate::uuid_generate_v7();
166+
let uuid: pgrx::Uuid = crate::typeid_uuid_generate_v7();
167167
let converted: Uuid = Uuid::from_slice(uuid.as_bytes()).unwrap();
168168

169169
println!("UUID: {:?}", uuid.to_string());

0 commit comments

Comments
 (0)