Skip to content

Commit 43dd5cd

Browse files
authored
chore: release pipeline (#9)
Signed-off-by: usamoi <usamoi@outlook.com>
1 parent d270f23 commit 43dd5cd

30 files changed

+486150
-12
lines changed

.github/workflows/release.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
type: string
8+
description: Version
9+
required: true
10+
tag:
11+
type: string
12+
description: Tag
13+
required: true
14+
15+
concurrency:
16+
group: ${{ github.ref }}-${{ github.workflow }}
17+
cancel-in-progress: true
18+
19+
env:
20+
CARGO_TERM_COLOR: always
21+
RUST_BACKTRACE: 1
22+
SCCACHE_GHA_ENABLED: true
23+
RUSTC_WRAPPER: sccache
24+
RUSTFLAGS: "-Dwarnings"
25+
26+
permissions:
27+
contents: write
28+
pull-requests: read
29+
30+
jobs:
31+
semver:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/github-script@v7
35+
with:
36+
script: |
37+
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-]+)*))?$/;
38+
if (!r.test("${{ github.event.inputs.version }}")) {
39+
core.setFailed(`Action failed with an invalid semver.`);
40+
}
41+
binary:
42+
strategy:
43+
matrix:
44+
version: [12, 13, 14, 15, 16]
45+
arch: ["x86_64", "aarch64"]
46+
runs-on: ubuntu-20.04
47+
env:
48+
SEMVER: ${{ github.event.inputs.version }}
49+
VERSION: ${{ matrix.version }}
50+
ARCH: ${{ matrix.arch }}
51+
needs: ["semver"]
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v4
55+
- name: Set up Environment
56+
run: |
57+
sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*'
58+
sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*'
59+
sudo apt-get update
60+
sudo apt-get install -y build-essential crossbuild-essential-arm64
61+
sudo apt-get install -y qemu-user-static
62+
echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' | tee ~/.cargo/config.toml
63+
- name: Set up Sccache
64+
uses: mozilla-actions/sccache-action@v0.0.4
65+
- name: Set up Cache
66+
uses: actions/cache/restore@v4
67+
id: cache
68+
with:
69+
path: |
70+
~/.cargo/registry/index/
71+
~/.cargo/registry/cache/
72+
~/.cargo/git/db/
73+
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }}
74+
- name: Set up Clang-16
75+
run: |
76+
sudo sh -c 'echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-16 main" >> /etc/apt/sources.list'
77+
wget --quiet -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
78+
sudo apt-get update
79+
sudo apt-get install -y clang-16
80+
- name: Set up Pgrx
81+
run: |
82+
# pg_config
83+
mkdir -p ~/.pg_config
84+
touch ~/.pg_config/pg_config
85+
chmod 777 ~/.pg_config/pg_config
86+
echo "#!/usr/bin/env bash" >> ~/.pg_config/pg_config
87+
echo "$(pwd)/tools/pg_config.sh \"\$@\" < $(pwd)/vendor/pg_config/pg${VERSION}_${ARCH}-unknown-linux-gnu.txt" >> ~/.pg_config/pg_config
88+
mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$HOME/.pg_config/pg_config\"" > ~/.pgrx/config.toml
89+
# pgrx_binding
90+
mkdir -p ~/.pgrx_binding
91+
cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs
92+
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
93+
- name: Build
94+
run: |
95+
cargo build --lib --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu
96+
./tools/schema.sh --no-default-features --features pg$VERSION --release --target $ARCH-unknown-linux-gnu | expand -t 4 > ./target/pg_bestmatch--$SEMVER.sql
97+
- name: Package
98+
run: |
99+
export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/')
100+
./scripts/package.sh
101+
- name: Upload
102+
env:
103+
GH_TOKEN: ${{ github.token }}
104+
run: |
105+
export TAG=${{ github.event.inputs.tag }}
106+
export PLATFORM=$(echo $ARCH | sed 's/aarch64/arm64/; s/x86_64/amd64/')
107+
gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${ARCH}-unknown-linux-gnu_${SEMVER}.zip
108+
gh release upload --clobber $TAG ./build/pg_bestmatch-pg${VERSION}_${SEMVER}_${PLATFORM}.deb
109+
- name: Post Set up Cache
110+
uses: actions/cache/save@v4
111+
if: ${{ !steps.cache.outputs.cache-hit }}
112+
with:
113+
path: |
114+
~/.cargo/registry/index/
115+
~/.cargo/registry/cache/
116+
~/.cargo/git/db/
117+
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release Nightly
2+
3+
on:
4+
schedule:
5+
# 00:00 UTC+8 -> 16:00
6+
- cron: "0 16 * * *"
7+
workflow_dispatch:
8+
9+
permissions:
10+
actions: write
11+
12+
jobs:
13+
trigger:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Trigger
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
run: |
22+
commit_date=$(git log -1 --since="24 hours ago" --pretty=format:"%cI")
23+
if [[ -n "$commit_date" ]]; then
24+
gh workflow run release.yml -f version=$(TZ='Asia/Shanghai' date +"0.0.0-nightly.%Y%m%d") -f tag=v0.0.0-nightly
25+
fi
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Release Officially
2+
3+
on:
4+
release:
5+
types:
6+
- created
7+
- edited
8+
9+
permissions:
10+
actions: write
11+
12+
jobs:
13+
trigger:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
- name: Trigger
19+
env:
20+
GH_TOKEN: ${{ github.token }}
21+
run: |
22+
R=${{ github.event.release.tag_name }}
23+
V=${R:1}
24+
gh workflow run release.yml -r $R -f version=$V -f tag=$R

.github/workflows/rust.yml

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "Cargo.lock"
1111
- "Cargo.toml"
1212
- "pg_bestmatch.control"
13+
- "vendor/**"
1314
pull_request:
1415
branches: ["main"]
1516
paths:
@@ -19,6 +20,7 @@ on:
1920
- "Cargo.lock"
2021
- "Cargo.toml"
2122
- "pg_bestmatch.control"
23+
- "vendor/**"
2224
merge_group:
2325
workflow_dispatch:
2426

@@ -38,7 +40,12 @@ jobs:
3840
strategy:
3941
matrix:
4042
version: [12, 13, 14, 15, 16]
43+
arch: ["x86_64"]
4144
runs-on: ubuntu-latest
45+
env:
46+
SEMVER: "0.0.0"
47+
VERSION: ${{ matrix.version }}
48+
ARCH: ${{ matrix.arch }}
4249
steps:
4350
- name: Checkout
4451
uses: actions/checkout@v4
@@ -47,20 +54,45 @@ jobs:
4754
sudo apt-get remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*'
4855
sudo apt-get purge -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*'
4956
sudo apt-get update
50-
sudo apt-get install -y build-essential
57+
sudo apt-get install -y build-essential crossbuild-essential-arm64
58+
sudo apt-get install -y qemu-user-static
59+
touch ~/.cargo/config.toml
60+
echo 'target.aarch64-unknown-linux-gnu.linker = "aarch64-linux-gnu-gcc"' >> ~/.cargo/config.toml
61+
echo 'target.aarch64-unknown-linux-gnu.runner = ["qemu-aarch64-static", "-L", "/usr/aarch64-linux-gnu"]' >> ~/.cargo/config.toml
5162
- name: Set up Sccache
5263
uses: mozilla-actions/sccache-action@v0.0.4
53-
- name: Set up PostgreSQL
54-
run: |
55-
sudo apt-get install -y postgresql-common
56-
echo | sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
57-
sudo apt update
58-
sudo apt-get install -y postgresql-${{ matrix.version }} postgresql-server-dev-${{ matrix.version }}
64+
- name: Set up Cache
65+
uses: actions/cache/restore@v4
66+
id: cache
67+
with:
68+
path: |
69+
~/.cargo/registry/index/
70+
~/.cargo/registry/cache/
71+
~/.cargo/git/db/
72+
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }}
5973
- name: Set up Pgrx
6074
run: |
61-
cargo install cargo-pgrx --debug --branch v0.12.0-alpha.1-patch2 --git https://github.com/tensorchord/pgrx.git
62-
cargo pgrx init --pg${{ matrix.version }}=$(which pg_config)
75+
# pg_config
76+
mkdir -p ~/.pg_config
77+
touch ~/.pg_config/pg_config
78+
chmod 777 ~/.pg_config/pg_config
79+
echo "#!/usr/bin/env bash" >> ~/.pg_config/pg_config
80+
echo "$(pwd)/tools/pg_config.sh \"\$@\" < $(pwd)/vendor/pg_config/pg${VERSION}_${ARCH}-unknown-linux-gnu.txt" >> ~/.pg_config/pg_config
81+
mkdir -p ~/.pgrx && echo "configs.pg$VERSION=\"$HOME/.pg_config/pg_config\"" > ~/.pgrx/config.toml
82+
# pgrx_binding
83+
mkdir -p ~/.pgrx_binding
84+
cp ./vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs ~/.pgrx_binding/pg${VERSION}_raw_bindings.rs
85+
echo PGRX_TARGET_INFO_PATH_PG$VERSION=$HOME/.pgrx_binding >> "$GITHUB_ENV"
6386
- name: Clippy
64-
run: cargo clippy --lib --features "pg${{ matrix.version }}"
87+
run: cargo clippy --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
6588
- name: Build
66-
run: cargo build --lib --features "pg${{ matrix.version }}"
89+
run: cargo build --lib --features "pg$VERSION" --target $ARCH-unknown-linux-gnu
90+
- name: Post Set up Cache
91+
uses: actions/cache/save@v4
92+
if: ${{ !steps.cache.outputs.cache-hit }}
93+
with:
94+
path: |
95+
~/.cargo/registry/index/
96+
~/.cargo/registry/cache/
97+
~/.cargo/git/db/
98+
key: ${{ github.job }}-${{ hashFiles('./Cargo.lock') }}-${{ matrix.version }}-${{ matrix.arch }}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Update Vendor
2+
3+
on:
4+
workflow_dispatch:
5+
6+
env:
7+
CARGO_TERM_COLOR: always
8+
RUST_BACKTRACE: 1
9+
SCCACHE_GHA_ENABLED: true
10+
RUSTC_WRAPPER: sccache
11+
RUSTFLAGS: "-Dwarnings"
12+
13+
permissions:
14+
contents: write
15+
pull-requests: write
16+
17+
jobs:
18+
generate:
19+
runs-on: ubuntu-20.04
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
- name: Set up QEMU
24+
uses: docker/setup-qemu-action@v3
25+
- name: Generate
26+
run: |
27+
export BRANCH=$(grep -o 'pgrx = { git = "https://github.com/tensorchord/pgrx.git", branch = "[^"]*' Cargo.toml | cut -d '"' -f 4)
28+
docker run --rm --platform linux/amd64 -v ./:/mnt/build \
29+
-e "VERSION=12" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
30+
docker run --rm --platform linux/amd64 -v ./:/mnt/build \
31+
-e "VERSION=13" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
32+
docker run --rm --platform linux/amd64 -v ./:/mnt/build \
33+
-e "VERSION=14" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
34+
docker run --rm --platform linux/amd64 -v ./:/mnt/build \
35+
-e "VERSION=15" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
36+
docker run --rm --platform linux/amd64 -v ./:/mnt/build \
37+
-e "VERSION=16" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
38+
docker run --rm --platform linux/arm64 -v ./:/mnt/build \
39+
-e "VERSION=12" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
40+
docker run --rm --platform linux/arm64 -v ./:/mnt/build \
41+
-e "VERSION=13" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
42+
docker run --rm --platform linux/arm64 -v ./:/mnt/build \
43+
-e "VERSION=14" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
44+
docker run --rm --platform linux/arm64 -v ./:/mnt/build \
45+
-e "VERSION=15" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
46+
docker run --rm --platform linux/arm64 -v ./:/mnt/build \
47+
-e "VERSION=16" -e "BRANCH=$BRANCH" debian:buster bash /mnt/build/scripts/update_vendor.sh &
48+
wait
49+
sudo chown -R $USER ./vendor
50+
- name: Create Pull Request
51+
uses: peter-evans/create-pull-request@v6
52+
with:
53+
commit-message: 'chore: update vendor'
54+
title: 'chore: update vendor'
55+
body: 'Update vendor: `pg_config` contents and pgrx bindings.'
56+
branch: update-vendor

.typos.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ extend-ignore-re = [
55
]
66

77
[files]
8-
extend-exclude = ["tokenizer/*.json"]
8+
extend-exclude = [
9+
"tokenizer/*.json",
10+
"vendor/pg_config/*.txt",
11+
"vendor/pgrx_binding/*.rs",
12+
]

scripts/update_vendor.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
printf "VERSION = ${VERSION}\n"
5+
printf "BRANCH = ${BRANCH}\n"
6+
7+
apt-get update
8+
apt-get install -y --no-install-recommends ca-certificates curl build-essential gnupg lsb-release wget git
9+
10+
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | tee -a /etc/apt/sources.list.d/pgdg.list
11+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
12+
apt-get update
13+
apt-get install -y --no-install-recommends postgresql-${VERSION} postgresql-server-dev-${VERSION}
14+
15+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
16+
source ~/.cargo/env
17+
18+
cd $(mktemp -d)
19+
20+
cargo init --lib --name vectors
21+
cargo add pgrx-pg-sys --git https://github.com/tensorchord/pgrx.git --branch $BRANCH --no-default-features --features pg$VERSION
22+
PGRX_PG_CONFIG_PATH=$(which pg_config) PGRX_PG_SYS_EXTRA_OUTPUT_PATH=$(pwd)/pgrx-binding.rs cargo build
23+
rustfmt ./pgrx-binding.rs
24+
25+
cp ./pgrx-binding.rs /mnt/build/vendor/pgrx_binding/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.rs
26+
pg_config > /mnt/build/vendor/pg_config/pg${VERSION}_$(uname --machine)-unknown-linux-gnu.txt

0 commit comments

Comments
 (0)