Skip to content

Commit 5cadce5

Browse files
committed
feat: first attempt at caching
1 parent 8023af0 commit 5cadce5

File tree

2 files changed

+117
-4
lines changed

2 files changed

+117
-4
lines changed

.github/workflows/ci.yaml

Lines changed: 115 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,131 @@ jobs:
1818
strategy:
1919
fail-fast: false # We want all of them to run, even if one fails
2020
matrix:
21-
os: [ ubuntu-latest, macos-latest ]
21+
os: ubuntu-latest
2222
pg: [ "12", "13", "14", "15", "16" ]
23+
include:
24+
- postgres: 16
25+
rust: "beta"
26+
2327
runs-on: ${{ matrix.os }}
28+
env:
29+
RUSTC_WRAPPER: sccache
30+
SCCACHE_DIR: /home/runner/.cache/sccache
31+
PG_VER: ${{ matrix.postgres }}
32+
RUST_TOOLCHAIN: ${{ matrix.rust || 'stable' }}
2433
steps:
2534
- uses: actions/checkout@v4
35+
- name: Set up prerequisites and environment
36+
run: |
37+
sudo apt-get update -y -qq --fix-missing
38+
39+
echo ""
40+
echo "----- Install sccache -----"
41+
mkdir -p $HOME/.local/bin
42+
curl -L https://github.com/mozilla/sccache/releases/download/v0.2.15/sccache-v0.2.15-x86_64-unknown-linux-musl.tar.gz | tar xz
43+
mv -f sccache-v0.2.15-x86_64-unknown-linux-musl/sccache $HOME/.local/bin/sccache
44+
chmod +x $HOME/.local/bin/sccache
45+
echo "$HOME/.local/bin" >> $GITHUB_PATH
46+
mkdir -p /home/runner/.cache/sccache
47+
echo ""
48+
49+
echo "----- Set up dynamic variables -----"
50+
cat $GITHUB_ENV
51+
echo ""
52+
53+
echo "----- Remove old postgres -----"
54+
sudo apt remove -y '^postgres.*' '^libpq.*' '^clang.*' '^llvm.*' '^libclang.*' '^libllvm.*' '^mono-llvm.*'
55+
echo ""
56+
57+
echo "----- Install system dependencies -----"
58+
sudo apt-get install -y \
59+
build-essential \
60+
llvm-14-dev libclang-14-dev clang-14 \
61+
gcc \
62+
libssl-dev \
63+
libz-dev \
64+
make \
65+
pkg-config \
66+
strace \
67+
zlib1g-dev
68+
echo ""
69+
./ci/rustup.sh
70+
echo "----- Set up cross compilation -----"
71+
sudo apt-get install -y --fix-missing crossbuild-essential-arm64
72+
echo 'CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc' >> $GITHUB_ENV
73+
# TODO: not all of these should be needed, but for now it's likely fine.
74+
echo 'BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu=-target aarch64-unknown-linux-gnu -isystem /usr/aarch64-linux-gnu/include/ -ccc-gcc-name aarch64-linux-gnu-gcc' >> $GITHUB_ENV
75+
76+
echo "----- Print env -----"
77+
env
78+
echo ""
79+
80+
- name: Install release version of PostgreSQL
81+
run: |
82+
echo "----- Set up PostgreSQL Apt repository -----"
83+
sudo apt-get install -y wget gnupg
84+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
85+
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
86+
sudo apt-get update -y -qq --fix-missing
87+
echo ""
88+
89+
sudo apt-get install -y \
90+
postgresql-$PG_VER \
91+
postgresql-server-dev-$PG_VER
92+
93+
echo ""
94+
echo "----- pg_config -----"
95+
pg_config
96+
echo ""
97+
- name: Set up PostgreSQL permissions
98+
run: sudo chmod a+rwx `/usr/lib/postgresql/$PG_VER/bin/pg_config --pkglibdir` `/usr/lib/postgresql/$PG_VER/bin/pg_config --sharedir`/extension /var/run/postgresql/
99+
100+
- name: Cache cargo registry
101+
uses: actions/cache@v4
102+
continue-on-error: false
103+
with:
104+
path: |
105+
~/.cargo/registry
106+
~/.cargo/git
107+
key: tests-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }}
108+
109+
- name: Cache sccache directory
110+
uses: actions/cache@v4
111+
continue-on-error: false
112+
with:
113+
path: /home/runner/.cache/sccache
114+
key: pgrx-tests-sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }}
115+
116+
- name: Start sccache server
117+
run: sccache --start-server
118+
119+
- name: Print sccache stats (before run)
120+
run: sccache --show-stats
121+
26122
- name: Install cargo-pgrx
27123
run: |
28124
PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
29125
cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
30-
cargo pgrx init --pg${{ matrix.pg }} download
126+
cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/$PG_VER/bin/pg_config
31127
- name: Run tests
32128
run: echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }}
129+
130+
# Attempt to make the cache payload slightly smaller.
131+
- name: Clean up built PGRX files
132+
run: |
133+
cd target/debug/deps/
134+
for built_file in $(find * -type f -executable -print | grep -v "\.so$"); do
135+
base_name=$(echo $built_file | cut -d- -f1);
136+
for basefile in "$base_name".*; do
137+
[ -f "$basefile" ] || continue;
138+
echo "Removing $basefile"
139+
rm $basefile
140+
done;
141+
echo "Removing $built_file"
142+
rm $built_file
143+
done
144+
- name: Stop sccache server
145+
run: sccache --stop-server || true
33146
Install:
34147
runs-on: ubuntu-latest
35148
steps:

.github/workflows/clippy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
4949
cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
5050
cargo pgrx init --pg${{ matrix.pg }} download
51-
51+
5252
- name: Install required cargo
5353
run: cargo install clippy-sarif sarif-fmt
5454

@@ -60,7 +60,7 @@ jobs:
6060
continue-on-error: true
6161

6262
- name: Upload analysis results to GitHub
63-
uses: github/codeql-action/upload-sarif@v1
63+
uses: github/codeql-action/upload-sarif@v2
6464
with:
6565
sarif_file: rust-clippy-results.sarif
6666
wait-for-processing: true

0 commit comments

Comments
 (0)