mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-29 05:14:28 +02:00
Vendor SQLite version setup action
This commit is contained in:
parent
07b603e562
commit
518dec1b4f
3 changed files with 186 additions and 3 deletions
39
.github/actions/setup-sqlite-version/action.yml
vendored
Normal file
39
.github/actions/setup-sqlite-version/action.yml
vendored
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
name: "Setup SQLite version"
|
||||||
|
description: "Build and activate a specific SQLite version from its amalgamation archive"
|
||||||
|
inputs:
|
||||||
|
version:
|
||||||
|
description: "The SQLite version to install"
|
||||||
|
required: true
|
||||||
|
cflags:
|
||||||
|
description: "CFLAGS to use when compiling SQLite"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
skip-activate:
|
||||||
|
description: "Set to true to skip modifying the library path"
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
|
fallback-urls:
|
||||||
|
description: "Whitespace-separated fallback download URLs to try after sqlite.org"
|
||||||
|
required: false
|
||||||
|
default: ""
|
||||||
|
outputs:
|
||||||
|
sqlite-location:
|
||||||
|
description: "Directory containing the compiled SQLite library"
|
||||||
|
value: ${{ steps.build.outputs.sqlite-location }}
|
||||||
|
runs:
|
||||||
|
using: "composite"
|
||||||
|
steps:
|
||||||
|
- shell: bash
|
||||||
|
run: mkdir -p "$RUNNER_TEMP/sqlite-versions/downloads"
|
||||||
|
- uses: actions/cache@v6
|
||||||
|
with:
|
||||||
|
path: ${{ runner.temp }}/sqlite-versions/downloads
|
||||||
|
key: setup-sqlite-version-${{ inputs.version }}-amalgamation-v1
|
||||||
|
- id: build
|
||||||
|
shell: bash
|
||||||
|
run: bash "$GITHUB_ACTION_PATH/setup-sqlite-version.sh"
|
||||||
|
env:
|
||||||
|
SQLITE_VERSION: ${{ inputs.version }}
|
||||||
|
SQLITE_CFLAGS: ${{ inputs.cflags }}
|
||||||
|
SQLITE_SKIP_ACTIVATE: ${{ inputs.skip-activate }}
|
||||||
|
SQLITE_EXTRA_FALLBACK_URLS: ${{ inputs.fallback-urls }}
|
||||||
144
.github/actions/setup-sqlite-version/setup-sqlite-version.sh
vendored
Normal file
144
.github/actions/setup-sqlite-version/setup-sqlite-version.sh
vendored
Normal file
|
|
@ -0,0 +1,144 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
version_spec="${SQLITE_VERSION:?SQLITE_VERSION is required}"
|
||||||
|
cflags="${SQLITE_CFLAGS:-}"
|
||||||
|
skip_activate="${SQLITE_SKIP_ACTIVATE:-false}"
|
||||||
|
extra_fallback_urls="${SQLITE_EXTRA_FALLBACK_URLS:-}"
|
||||||
|
|
||||||
|
case "$version_spec" in
|
||||||
|
3.46 | 3.46.0)
|
||||||
|
sqlite_version="3.46.0"
|
||||||
|
sqlite_year="2024"
|
||||||
|
amalgamation_id="3460000"
|
||||||
|
builtin_fallback_urls="https://static.simonwillison.net/static/2026/sqlite-amalgamation-3460000.zip"
|
||||||
|
;;
|
||||||
|
3.23.1)
|
||||||
|
sqlite_version="3.23.1"
|
||||||
|
sqlite_year="2018"
|
||||||
|
amalgamation_id="3230100"
|
||||||
|
builtin_fallback_urls="https://static.simonwillison.net/static/2026/sqlite-amalgamation-3230100.zip"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "::error::Unsupported SQLite version '$version_spec'. Add its release year and amalgamation id to $GITHUB_ACTION_PATH/setup-sqlite-version.sh."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$(uname -s)" in
|
||||||
|
Linux)
|
||||||
|
library_name="libsqlite3.so.0"
|
||||||
|
library_path_var="LD_LIBRARY_PATH"
|
||||||
|
;;
|
||||||
|
Darwin)
|
||||||
|
library_name="libsqlite3.dylib"
|
||||||
|
library_path_var="DYLD_LIBRARY_PATH"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "::error::Unsupported platform $(uname -s)"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
runner_temp="${RUNNER_TEMP:-}"
|
||||||
|
if [ -z "$runner_temp" ]; then
|
||||||
|
runner_temp="$(mktemp -d)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
filename="sqlite-amalgamation-${amalgamation_id}"
|
||||||
|
official_url="https://www.sqlite.org/${sqlite_year}/${filename}.zip"
|
||||||
|
download_dir="${runner_temp}/sqlite-versions/downloads"
|
||||||
|
source_root="${runner_temp}/sqlite-versions/source"
|
||||||
|
source_dir="${source_root}/${filename}"
|
||||||
|
build_dir="${runner_temp}/sqlite-versions/build/${sqlite_version}"
|
||||||
|
archive_path="${download_dir}/${filename}.zip"
|
||||||
|
|
||||||
|
mkdir -p "$download_dir" "$source_root" "$build_dir"
|
||||||
|
|
||||||
|
download_archive() {
|
||||||
|
local url
|
||||||
|
local candidate_path="${archive_path}.tmp"
|
||||||
|
local urls=("$official_url")
|
||||||
|
|
||||||
|
for url in $builtin_fallback_urls $extra_fallback_urls; do
|
||||||
|
urls+=("$url")
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -f "$candidate_path"
|
||||||
|
for url in "${urls[@]}"; do
|
||||||
|
echo "Downloading SQLite ${sqlite_version} amalgamation from ${url}"
|
||||||
|
if curl \
|
||||||
|
--fail \
|
||||||
|
--location \
|
||||||
|
--show-error \
|
||||||
|
--retry 5 \
|
||||||
|
--retry-delay 2 \
|
||||||
|
--retry-max-time 180 \
|
||||||
|
--retry-all-errors \
|
||||||
|
--connect-timeout 20 \
|
||||||
|
--max-time 240 \
|
||||||
|
--output "$candidate_path" \
|
||||||
|
"$url"; then
|
||||||
|
mv "$candidate_path" "$archive_path"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "::warning::Download failed from ${url}"
|
||||||
|
rm -f "$candidate_path"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "::error::Could not download SQLite ${sqlite_version} amalgamation"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ ! -f "${source_dir}/sqlite3.c" ]; then
|
||||||
|
if [ ! -f "$archive_path" ]; then
|
||||||
|
download_archive
|
||||||
|
fi
|
||||||
|
|
||||||
|
rm -rf "$source_dir"
|
||||||
|
unzip -q "$archive_path" -d "$source_root"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f "${source_dir}/sqlite3.c" ]; then
|
||||||
|
echo "::error::Expected ${source_dir}/sqlite3.c after extracting ${archive_path}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
read -r -a cflag_args <<< "$cflags"
|
||||||
|
|
||||||
|
echo "Compiling SQLite ${sqlite_version} to ${build_dir}/${library_name}"
|
||||||
|
gcc \
|
||||||
|
-fPIC \
|
||||||
|
-shared \
|
||||||
|
"${cflag_args[@]}" \
|
||||||
|
"${source_dir}/sqlite3.c" \
|
||||||
|
"-I${source_dir}" \
|
||||||
|
-o "${build_dir}/${library_name}"
|
||||||
|
|
||||||
|
if [ "$library_name" = "libsqlite3.so.0" ]; then
|
||||||
|
ln -sf "$library_name" "${build_dir}/libsqlite3.so"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "${GITHUB_OUTPUT:-}" ]; then
|
||||||
|
echo "sqlite-location=${build_dir}" >> "$GITHUB_OUTPUT"
|
||||||
|
else
|
||||||
|
echo "sqlite-location=${build_dir}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$(printf '%s' "$skip_activate" | tr '[:upper:]' '[:lower:]')" in
|
||||||
|
true | 1 | yes)
|
||||||
|
echo "Skipping ${library_path_var} activation"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
existing_value="${!library_path_var:-}"
|
||||||
|
if [ -n "${GITHUB_ENV:-}" ]; then
|
||||||
|
if [ -n "$existing_value" ]; then
|
||||||
|
echo "${library_path_var}=${build_dir}:${existing_value}" >> "$GITHUB_ENV"
|
||||||
|
else
|
||||||
|
echo "${library_path_var}=${build_dir}" >> "$GITHUB_ENV"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
echo "Added ${build_dir} to ${library_path_var}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
6
.github/workflows/test-sqlite-support.yml
vendored
6
.github/workflows/test-sqlite-support.yml
vendored
|
|
@ -18,16 +18,16 @@ jobs:
|
||||||
"3.23.1", # 2018-04-10, before UPSERT
|
"3.23.1", # 2018-04-10, before UPSERT
|
||||||
]
|
]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v7
|
||||||
- name: Set up Python ${{ matrix.python-version }}
|
- name: Set up Python ${{ matrix.python-version }}
|
||||||
uses: actions/setup-python@v5
|
uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: ${{ matrix.python-version }}
|
python-version: ${{ matrix.python-version }}
|
||||||
allow-prereleases: true
|
allow-prereleases: true
|
||||||
cache: pip
|
cache: pip
|
||||||
cache-dependency-path: pyproject.toml
|
cache-dependency-path: pyproject.toml
|
||||||
- name: Set up SQLite ${{ matrix.sqlite-version }}
|
- name: Set up SQLite ${{ matrix.sqlite-version }}
|
||||||
uses: asg017/sqlite-versions@71ea0de37ae739c33e447af91ba71dda8fcf22e6
|
uses: ./.github/actions/setup-sqlite-version
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.sqlite-version }}
|
version: ${{ matrix.sqlite-version }}
|
||||||
cflags: "-DSQLITE_ENABLE_DESERIALIZE -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_JSON1"
|
cflags: "-DSQLITE_ENABLE_DESERIALIZE -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_FTS4 -DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_RTREE -DSQLITE_ENABLE_JSON1"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue