-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: usamoi <[email protected]>
- Loading branch information
Showing
6 changed files
with
331 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Release | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
version: | ||
type: string | ||
description: Version | ||
required: true | ||
tag: | ||
type: string | ||
description: Tag | ||
required: true | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
RUST_BACKTRACE: 1 | ||
SCCACHE_GHA_ENABLED: true | ||
RUSTC_WRAPPER: sccache | ||
RUSTFLAGS: "-Dwarnings" | ||
|
||
permissions: | ||
contents: write | ||
pull-requests: read | ||
|
||
jobs: | ||
semver: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const r = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/; | ||
if (!r.test("${{ github.event.inputs.version }}")) { | ||
core.setFailed(`Action failed with an invalid semver.`); | ||
} | ||
binary: | ||
strategy: | ||
matrix: | ||
version: [12, 13, 14, 15, 16] | ||
arch: ["x86_64", "aarch64"] | ||
runs-on: ubuntu-20.04 | ||
env: | ||
SEMVER: ${{ github.event.inputs.version }} | ||
VERSION: ${{ matrix.version }} | ||
ARCH: ${{ matrix.arch }} | ||
needs: ["semver"] | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Set up Environment | ||
run: | | ||
sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' | ||
sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*' | ||
sudo apt-get update | ||
sudo apt-get install -y build-essential crossbuild-essential-arm64 | ||
sudo apt-get install -y qemu-user-static | ||
echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml | ||
- name: Set up Sccache | ||
uses: mozilla-actions/[email protected] | ||
- name: Set up Cache | ||
uses: actions/cache/restore@v4 | ||
id: cache | ||
with: | ||
path: | | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }} | ||
- name: Set up Clang-16 | ||
run: | | ||
sudo sh -c 'echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-16 main" >> /etc/apt/sources.list' | ||
wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - | ||
sudo apt-get update | ||
sudo apt-get install -y clang-16 | ||
- name: Set up Pgrx | ||
run: | | ||
# pg_config | ||
mkdir -p ~/.pg_config | ||
touch ~/.pg_config/pg_config | ||
chmod 777 ~/.pg_config/pg_config | ||
echo "#!/usr/bin/env bash" >> ~/.pg_config/pg_config | ||
echo "$(pwd)/tools/pg_config.sh \"\$@\" < $(pwd)/vendor/pg_config/pg${VERSION}_${ARCH}-unknown-linux-gnu.txt" >> ~/.pg_config/pg_config | ||
mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$HOME/.pg_config/pg_config\"" > ~/.pgrx/config.toml | ||
# pgrx_binding | ||
mkdir -p ~/.pgrx_binding | ||
cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs | ||
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV" | ||
- name: Build | ||
run: | | ||
cargo build --lib --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | ||
./tools/schema.sh --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/pg_bestmatch--$SEMVER.sql | ||
- name: Package | ||
run: | | ||
export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') | ||
./scripts/package.sh | ||
- name: Upload | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
export TAG=${{ github.event.inputs.tag }} | ||
export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/') | ||
gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip | ||
gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${SEMVER}_${PLATFORM}.deb | ||
- name: Post Set up Cache | ||
uses: actions/cache/save@v4 | ||
if: ${{ !steps.cache.outputs.cache-hit }} | ||
with: | ||
path: | | ||
~/.cargo/registry/index/ | ||
~/.cargo/registry/cache/ | ||
~/.cargo/git/db/ | ||
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Release Nightly | ||
|
||
on: | ||
schedule: | ||
# 00:00 UTC+8 -> 16:00 | ||
- cron: "0 16 * * *" | ||
workflow_dispatch: | ||
|
||
permissions: | ||
actions: write | ||
|
||
jobs: | ||
trigger: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Trigger | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
commit_date=$(git log -1 --since="24 hours ago" --pretty=format:"%cI") | ||
if [[ -n "$commit_date" ]]; then | ||
gh workflow run release.yml -f version=$(TZ='Asia/Shanghai' date +"0.0.0-nightly.%Y%m%d") -f tag=v0.0.0-nightly | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: Release Officially | ||
|
||
on: | ||
release: | ||
types: | ||
- created | ||
- edited | ||
|
||
permissions: | ||
actions: write | ||
|
||
jobs: | ||
trigger: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
- name: Trigger | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
R=${{ github.event.release.tag_name }} | ||
V=${R:1} | ||
gh workflow run release.yml -r $R -f version=$V -f tag=$R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
source=$(cat -) | ||
|
||
if [ -z "$source" ]; then | ||
echo "pg_config: could't find configuration file" | ||
exit 1 | ||
fi | ||
|
||
for arg in "$@"; do | ||
if [ "$arg" = "--help" ] || [ "$arg" = "-?" ]; then | ||
cat <<EOF | ||
pg_config provides information about the installed version of PostgreSQL. | ||
Usage: | ||
pg_config [OPTION]... | ||
Options: | ||
--bindir show location of user executables | ||
--docdir show location of documentation files | ||
--htmldir show location of HTML documentation files | ||
--includedir show location of C header files of the client | ||
interfaces | ||
--pkgincludedir show location of other C header files | ||
--includedir-server show location of C header files for the server | ||
--libdir show location of object code libraries | ||
--pkglibdir show location of dynamically loadable modules | ||
--localedir show location of locale support files | ||
--mandir show location of manual pages | ||
--sharedir show location of architecture-independent support files | ||
--sysconfdir show location of system-wide configuration files | ||
--pgxs show location of extension makefile | ||
--configure show options given to "configure" script when | ||
PostgreSQL was built | ||
--cc show CC value used when PostgreSQL was built | ||
--cppflags show CPPFLAGS value used when PostgreSQL was built | ||
--cflags show CFLAGS value used when PostgreSQL was built | ||
--cflags_sl show CFLAGS_SL value used when PostgreSQL was built | ||
--ldflags show LDFLAGS value used when PostgreSQL was built | ||
--ldflags_ex show LDFLAGS_EX value used when PostgreSQL was built | ||
--ldflags_sl show LDFLAGS_SL value used when PostgreSQL was built | ||
--libs show LIBS value used when PostgreSQL was built | ||
--version show the PostgreSQL version | ||
-?, --help show this help, then exit | ||
With no arguments, all known items are shown. | ||
Report bugs to <[email protected]>. | ||
PostgreSQL home page: <https://www.postgresql.org/> | ||
EOF | ||
exit 0 | ||
fi | ||
done | ||
|
||
if [ $# -eq 0 ]; then | ||
echo "$source" | ||
exit 0 | ||
fi | ||
|
||
for arg in "$@"; do | ||
res="" | ||
|
||
if [[ "$arg" == --* ]]; then | ||
var=$(echo "$arg" | cut -c 3- | tr '[:lower:]' '[:upper:]') | ||
res=$(printf "%s" "$source" | grep -E "^$var = " - | cut -d "=" -f "2-") | ||
fi | ||
|
||
if [ -z "$res" ]; then | ||
echo "pg_config: invalid argument: $arg" | ||
echo "Try "pg_config --help" for more information." | ||
exit 1 | ||
fi | ||
|
||
echo $res | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
# CONTROL_FILEPATH | ||
# SO_FILEPATH | ||
|
||
printf "fn main() {\n" | ||
|
||
cat << EOF | ||
pg_bestmatch::__pgrx_marker(); | ||
let mut entities = Vec::new(); | ||
let control_file_path = std::path::PathBuf::from("$CONTROL_FILEPATH"); | ||
let control_file = ::pgrx::pgrx_sql_entity_graph::ControlFile::try_from(control_file_path).expect(".control file should properly formatted"); | ||
let control_file_entity = ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity::ExtensionRoot(control_file); | ||
entities.push(control_file_entity); | ||
EOF | ||
|
||
while read -r name_ident; do | ||
cat << EOF | ||
extern "Rust" { | ||
fn $name_ident() -> ::pgrx::pgrx_sql_entity_graph::SqlGraphEntity; | ||
} | ||
let entity = unsafe { $name_ident() }; | ||
entities.push(entity); | ||
EOF | ||
done <<< $(nm -D -g $SO_FILEPATH | grep "T __pgrx_internals_" | awk '{print $3}') | ||
|
||
cat << EOF | ||
let pgrx_sql = ::pgrx::pgrx_sql_entity_graph::PgrxSql::build( | ||
entities.into_iter(), | ||
"pg_bestmatch".to_string(), | ||
false, | ||
) | ||
.expect("SQL generation error"); | ||
eprintln!("SQL entities to {}", "/dev/stdout",); | ||
pgrx_sql | ||
.write(&mut std::io::stdout()) | ||
.expect("Could not write SQL to stdout"); | ||
EOF | ||
|
||
printf "}\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
if [[ " $@ " =~ --target' '([^ ]+) ]]; then | ||
TARGET="${BASH_REMATCH[1]}" | ||
if [[ " $@ " =~ " --release " ]]; then | ||
DIR="./target/$TARGET/release" | ||
else | ||
DIR="./target/$TARGET/debug" | ||
fi | ||
else | ||
TARGET="" | ||
if [[ " $@ " =~ " --release " ]]; then | ||
DIR="./target/release" | ||
else | ||
DIR="./target/debug" | ||
fi | ||
fi | ||
|
||
if [ "$TARGET" = "" ]; then | ||
printf "Target: [not specified]\n" 1>&2 | ||
RUNNER=() | ||
elif [ "$TARGET" = $(rustc -vV | awk '/^host/ { print $2 }') ]; then | ||
printf "Target: [host]\n" 1>&2 | ||
RUNNER=() | ||
elif [ "$TARGET" = "aarch64-unknown-linux-gnu" ]; then | ||
printf "Target: $TARGET\n" 1>&2 | ||
QEMU_LD_PREFIX="/usr/aarch64-linux-gnu" | ||
RUNNER=("qemu-aarch64-static") | ||
elif [ "$TARGET" = "riscv64gc-unknown-linux-gnu" ]; then | ||
printf "Target: $TARGET\n" 1>&2 | ||
QEMU_LD_PREFIX="/usr/riscv64-linux-gnu" | ||
RUNNER=("qemu-riscv64-static") | ||
else | ||
printf "Unknown target: $TARGET\n" 1>&2 | ||
exit 1 | ||
fi | ||
|
||
code=$(mktemp) | ||
chmod 700 $code | ||
CONTROL_FILEPATH="./pg_bestmatch.control" SO_FILEPATH="$DIR/libpg_bestmatch.so" $(dirname "$0")/schema-codegen.sh >> $code | ||
|
||
PGRX_EMBED=$code cargo rustc --bin pgrx_embed_vectors "$@" -- --cfg pgrx_embed | ||
|
||
CARGO_PKG_VERSION="0.0.0" QEMU_LD_PREFIX=$QEMU_LD_PREFIX "${RUNNER[@]}" "$DIR/pgrx_embed_vectors" | expand -t 4 |