Skip to content

Build & Publish Prebuilt Libraries #9

Build & Publish Prebuilt Libraries

Build & Publish Prebuilt Libraries #9

Workflow file for this run

name: Build & Publish Prebuilt Libraries
on:
workflow_dispatch:
inputs:
turso_ref:
description: 'turso ref (tag or branch)'
required: true
push_changes:
description: 'push changes to the repo'
required: true
type: boolean
permissions:
contents: write
concurrency:
group: build-libs-${{ github.event.inputs.turso_ref }}
cancel-in-progress: false
jobs:
build:
name: Build (${{ matrix.os }}${{ matrix.name_suffix || '' }})
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
- os: ubuntu-24.04-arm
- os: macos-14
- os: macos-13
- os: windows-latest
- os: windows-11-arm
- os: ubuntu-latest
container: alpine:latest
musl_tag: true
name_suffix: " (Alpine x64)"
- os: ubuntu-24.04-arm
musl_tag: true
build_musl: true
name_suffix: " (musl cross-compile)"
runs-on: ${{ matrix.os }}
container: ${{ matrix.container }}
steps:
- name: Install Alpine dependencies
if: matrix.container == 'alpine:latest'
run: |
apk add --no-cache bash curl gcc musl-dev git
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
source $HOME/.cargo/env
echo "$HOME/.cargo/bin" >> $GITHUB_PATH
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup go
uses: actions/setup-go@v6
with:
go-version-file: 'go.mod'
- name: Clean libs dir
shell: bash
run: rm -rf libs && mkdir -p libs
- name: Set up Rust
if: matrix.container != 'alpine:latest'
uses: dtolnay/rust-toolchain@stable
- name: Install musl tools for cross-compile
if: matrix.build_musl == true
run: |
sudo apt-get update
sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu
rustup target add aarch64-unknown-linux-musl
- name: Add musl target
if: matrix.build_musl == true
run: rustup target add aarch64-unknown-linux-musl
- name: Cache cargo
if: matrix.container != 'alpine:latest'
uses: Swatinem/rust-cache@v2
with:
workspaces: |
. -> target
- name: Make script executable (POSIX)
if: runner.os != 'Windows'
run: chmod +x ./build_libs.sh
- name: Build cdylib (release)
shell: bash
run: |
if [[ "${{ matrix.build_musl }}" == "true" ]]; then
export TURSO_RS_LIBC_VARIANT="_musl"
fi
TURSO_RS_BUILD_REF=${{ github.event.inputs.turso_ref }} ./build_libs.sh
./hash_libs.sh
echo "After build, libs/ contains:"
find libs -maxdepth 3 -type f || true
- name: run test
if: matrix.musl_tag == true
run: go test --tags musl ./... -v
- name: run test
if: matrix.musl_tag != true
run: go test ./... -v
- name: Upload platform artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.name_suffix || '' }}
path: libs/**/*
if-no-files-found: error
publish:
name: Aggregate & PR commit
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/download-artifact@v4
with:
path: _libs_artifacts
merge-multiple: true
- name: Merge platform folders into repo
shell: bash
run: |
set -euo pipefail
shopt -s nullglob
mkdir -p libs
echo "Downloaded artifact roots:"
for d in _libs_artifacts/*; do
[ -d "$d" ] && echo " - $(basename "$d")"
done
for src in _libs_artifacts/*; do
[ -d "$src" ] || continue
plat="$(basename "$src")"
dest="libs/$plat"
echo "Syncing $src -> $dest"
mkdir -p "$dest"
rsync -a "$src"/ "$dest"/
done
echo "Merged libs layout:"
for f in libs/*/*; do [ -f "$f" ] && echo "$f"; done
- name: Skip if no libs changed
shell: bash
run: |
git add -N libs || true
if git diff --quiet -- libs ; then
echo "No changes under libs/; skipping PR."
exit 0
fi
- name: Create / update prebuilt-libs branch and push
if: github.event.inputs.push_changes == 'true'
shell: bash
env:
TURSO_REF: ${{ github.event.inputs.turso_ref }}
run: |
set -euo pipefail
# Determine branch name based on ref type
if [[ "$TURSO_REF" =~ ^v[0-9]+\.[0-9]+\.[0-9]+([\-+][0-9A-Za-z\.-]+)?$ ]]; then
BRANCH="${TURSO_REF}"
else
BRANCH="turso-branch-${TURSO_REF}"
fi
echo "Target branch: $BRANCH"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Try to fetch existing branch if present
if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then
echo "Branch $BRANCH exists on remote — checking it out."
git fetch origin "$BRANCH":"$BRANCH"
git checkout "$BRANCH"
else
echo "Branch $BRANCH does not exist — creating it."
git checkout -b "$BRANCH"
fi
echo "Staging changes..."
git add libs
if git diff --cached --quiet; then
echo "No staged changes, skipping push."
exit 0
fi
git commit -m "Update prebuilt libs for ref: ${TURSO_REF}"
echo "Pushing branch: $BRANCH"
git push --set-upstream origin "$BRANCH"