Skip to content

Commit 1c2a544

Browse files
committed
fix: use gh release download to fetch pg-ffi native libraries
1 parent 0d1056f commit 1c2a544

2 files changed

Lines changed: 22 additions & 28 deletions

File tree

.github/workflows/build.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ jobs:
2121
# Download pre-built native library for CI
2222
- name: Download pg-ffi native library
2323
run: |
24-
# Fetch the latest pg-ffi release from the postguard repo
25-
DOWNLOAD_URL=$(gh release view --repo encryption4all/postguard --json assets -q '.assets[] | select(.name == "pg-ffi-linux-x64.tar.gz") | .url' 2>/dev/null || true)
26-
if [ -n "$DOWNLOAD_URL" ]; then
24+
TAG=$(gh release list --repo encryption4all/postguard --json tagName -q '[.[] | select(.tagName | startswith("pg-ffi-"))][0].tagName' 2>/dev/null || true)
25+
if [ -n "$TAG" ]; then
2726
mkdir -p src/runtimes/linux-x64/native
28-
curl -sL "$DOWNLOAD_URL" | tar xz -C src/runtimes/linux-x64/native
27+
gh release download "$TAG" --repo encryption4all/postguard --pattern "pg-ffi-linux-x64.tar.gz" --dir /tmp
28+
tar xzf /tmp/pg-ffi-linux-x64.tar.gz -C src/runtimes/linux-x64/native
2929
else
3030
echo "::warning::No pg-ffi release found. Building from source."
31-
# Fallback: build from source if no release exists yet
3231
rustup default stable
3332
git clone --depth 1 https://github.com/encryption4all/postguard.git /tmp/postguard
3433
cargo build --release -p pg-ffi --manifest-path /tmp/postguard/Cargo.toml

.github/workflows/publish.yml

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,29 @@ jobs:
2020
# Download native libraries for all platforms from the postguard repo
2121
- name: Download pg-ffi native libraries
2222
run: |
23-
TARGETS=("linux-x64:tar.gz" "linux-arm64:tar.gz" "osx-arm64:tar.gz" "osx-x64:tar.gz" "win-x64:zip")
2423
RUNTIMES_DIR="src/runtimes"
24+
# Find the latest pg-ffi release tag
25+
TAG=$(gh release list --repo encryption4all/postguard --json tagName -q '[.[] | select(.tagName | startswith("pg-ffi-"))][0].tagName')
26+
if [ -z "$TAG" ]; then
27+
echo "::error::No pg-ffi release found"
28+
exit 1
29+
fi
30+
echo "Using release: $TAG"
2531
26-
for entry in "${TARGETS[@]}"; do
27-
TARGET="${entry%%:*}"
28-
EXT="${entry##*:}"
29-
ASSET="pg-ffi-${TARGET}.${EXT}"
30-
32+
# Download each platform asset
33+
for TARGET in linux-x64 linux-arm64 osx-arm64 osx-x64; do
34+
ASSET="pg-ffi-${TARGET}.tar.gz"
3135
mkdir -p "${RUNTIMES_DIR}/${TARGET}/native"
32-
3336
echo "Downloading ${ASSET}..."
34-
DOWNLOAD_URL=$(gh release list --repo encryption4all/postguard --json tagName,assets -q "
35-
[.[] | .assets[] | select(.name == \"${ASSET}\")] | first | .url // empty
36-
" 2>/dev/null || true)
37-
38-
if [ -z "$DOWNLOAD_URL" ]; then
39-
echo "::warning::Could not find ${ASSET} in postguard releases"
40-
continue
41-
fi
42-
43-
if [ "$EXT" = "tar.gz" ]; then
44-
curl -sL "$DOWNLOAD_URL" | tar xz -C "${RUNTIMES_DIR}/${TARGET}/native"
45-
else
46-
curl -sL "$DOWNLOAD_URL" -o /tmp/pg-ffi.zip
47-
unzip -o /tmp/pg-ffi.zip -d "${RUNTIMES_DIR}/${TARGET}/native"
48-
rm /tmp/pg-ffi.zip
49-
fi
37+
gh release download "$TAG" --repo encryption4all/postguard --pattern "$ASSET" --dir /tmp
38+
tar xzf "/tmp/${ASSET}" -C "${RUNTIMES_DIR}/${TARGET}/native"
5039
done
40+
41+
# Windows
42+
mkdir -p "${RUNTIMES_DIR}/win-x64/native"
43+
echo "Downloading pg-ffi-win-x64.zip..."
44+
gh release download "$TAG" --repo encryption4all/postguard --pattern "pg-ffi-win-x64.zip" --dir /tmp
45+
unzip -o /tmp/pg-ffi-win-x64.zip -d "${RUNTIMES_DIR}/win-x64/native"
5146
env:
5247
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5348

0 commit comments

Comments
 (0)