Skip to content

Commit 3ba559b

Browse files
committed
feat: attempt to make ci work for release
1 parent 361e440 commit 3ba559b

File tree

4 files changed

+187
-1
lines changed

4 files changed

+187
-1
lines changed

.github/workflows/release.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Build and Publish TypeID Extension
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
env:
9+
EXTENSION_NAME: typeid
10+
DOCKER_IMAGE: ghcr.io/blitss/typeid-pg
11+
12+
jobs:
13+
build-and-publish:
14+
strategy:
15+
matrix:
16+
pg_version: [11, 12, 13, 14, 15, 16]
17+
os: [ubuntu-latest, macos-latest]
18+
arch: [amd64, arm64]
19+
exclude:
20+
- os: macos-latest
21+
arch: arm64
22+
23+
runs-on: ${{ matrix.os }}
24+
25+
steps:
26+
- uses: actions/checkout@v4
27+
28+
- name: Set up Rust
29+
uses: actions-rs/toolchain@v1
30+
with:
31+
toolchain: stable
32+
override: true
33+
34+
- name: Install PostgreSQL (Linux)
35+
if: runner.os == 'Linux'
36+
run: |
37+
sudo apt-get install -y wget gnupg
38+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
39+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
40+
sudo apt-get update -y -qq --fix-missing
41+
sudo apt-get install -y postgresql-${{ matrix.pg_version }} postgresql-server-dev-${{ matrix.pg_version }}
42+
43+
- name: Install PostgreSQL (macOS)
44+
if: runner.os == 'macOS'
45+
run: |
46+
brew install postgresql@${{ matrix.pg_version }}
47+
echo "/usr/local/opt/postgresql@${{ matrix.pg_version }}/bin" >> $GITHUB_PATH
48+
49+
- name: Build Extension
50+
run: |
51+
cargo pgrx init
52+
cargo pgrx package --pg-config /usr/bin/pg_config-${{ matrix.pg_version }}
53+
54+
- name: Package Extension
55+
run: |
56+
mkdir -p release
57+
tar -czvf release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ runner.os }}-${{ matrix.arch }}.tar.gz -C target/release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }} .
58+
59+
- name: Upload Release Asset
60+
uses: softprops/action-gh-release@v1
61+
with:
62+
files: release/${{ env.EXTENSION_NAME }}-pg${{ matrix.pg_version }}-${{ runner.os }}-${{ matrix.arch }}.tar.gz
63+
64+
build-and-push-docker:
65+
needs: build-and-publish
66+
runs-on: ubuntu-latest
67+
steps:
68+
- uses: actions/checkout@v3
69+
70+
- name: Set up QEMU
71+
uses: docker/setup-qemu-action@v2
72+
73+
- name: Set up Docker Buildx
74+
uses: docker/setup-buildx-action@v2
75+
76+
- name: Login to GHCR
77+
uses: docker/login-action@v2
78+
with:
79+
registry: ghcr.io
80+
username: ${{ github.actor }}
81+
password: ${{ secrets.GITHUB_TOKEN }}
82+
83+
- name: Build and push Docker image
84+
uses: docker/build-push-action@v4
85+
with:
86+
context: .
87+
push: true
88+
platforms: linux/amd64,linux/arm64
89+
tags: |
90+
${{ env.DOCKER_IMAGE }}:latest
91+
${{ 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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Stage 1: Build the extension
2+
FROM rust:latest as builder
3+
4+
ARG PG_VERSION=16
5+
6+
RUN apt-get update && apt-get install -y \
7+
wget \
8+
gnupg \
9+
lsb-release \
10+
&& wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
11+
&& echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
12+
&& apt-get update \
13+
&& apt-get install -y postgresql-${PG_VERSION} postgresql-server-dev-${PG_VERSION}
14+
15+
WORKDIR /usr/src/typeid
16+
17+
COPY . .
18+
19+
RUN cargo install cargo-pgrx \
20+
&& cargo pgrx init \
21+
&& cargo pgrx package --pg-config /usr/bin/pg_config-${PG_VERSION}
22+
23+
# Stage 2: Create the final Postgres image with the extension
24+
FROM postgres:${PG_VERSION}
25+
26+
ARG PG_VERSION=16
27+
28+
# Copy the built extension files from the builder stage
29+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid.control /usr/share/postgresql/extension/
30+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/lib/postgresql/${PG_VERSION}/lib/typeid.so /usr/lib/postgresql/lib/
31+
COPY --from=builder /usr/src/typeid/target/release/typeid-pg${PG_VERSION}/usr/share/postgresql/${PG_VERSION}/extension/typeid--0.0.0.sql /usr/share/postgresql/extension/
32+
33+
# Enable the extension
34+
RUN echo "shared_preload_libraries = 'typeid'" >> /usr/share/postgresql/postgresql.conf.sample

install.sh

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

0 commit comments

Comments
 (0)