1+ name : CI
2+
3+ on :
4+ push :
5+ branches :
6+ - main
7+ pull_request :
8+ branches :
9+ - main
10+
11+ env :
12+ CARGO_TERM_COLOR : always
13+ RUST_BACKTRACE : 1
14+ CARGO_INCREMENTAL : " false"
15+
16+ jobs :
17+ Test :
18+ strategy :
19+ fail-fast : false # We want all of them to run, even if one fails
20+ matrix :
21+ os : [ "ubuntu-latest" ]
22+ pg : [ "12", "13", "14", "15", "16" ]
23+
24+ runs-on : ${{ matrix.os }}
25+ env :
26+ RUSTC_WRAPPER : sccache
27+ SCCACHE_DIR : /home/runner/.cache/sccache
28+ RUST_TOOLCHAIN : ${{ matrix.rust || 'stable' }}
29+ steps :
30+ - uses : actions/checkout@v4
31+ - name : Set up prerequisites and environment
32+ run : |
33+ sudo apt-get update -y -qq --fix-missing
34+
35+ echo ""
36+ echo "----- Install sccache -----"
37+ mkdir -p $HOME/.local/bin
38+ 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
39+ mv -f sccache-v0.2.15-x86_64-unknown-linux-musl/sccache $HOME/.local/bin/sccache
40+ chmod +x $HOME/.local/bin/sccache
41+ echo "$HOME/.local/bin" >> $GITHUB_PATH
42+ mkdir -p /home/runner/.cache/sccache
43+ echo ""
44+
45+ echo "----- Set up dynamic variables -----"
46+ cat $GITHUB_ENV
47+ echo ""
48+
49+ echo "----- Install system dependencies -----"
50+ sudo apt-get install -y \
51+ build-essential \
52+ llvm-14-dev libclang-14-dev clang-14 \
53+ gcc \
54+ libssl-dev \
55+ libz-dev \
56+ make \
57+ pkg-config \
58+ strace \
59+ zlib1g-dev
60+ echo ""
61+ echo "----- Print env -----"
62+ env
63+ echo ""
64+
65+ - name : Install release version of PostgreSQL
66+ run : |
67+ echo "----- Set up PostgreSQL Apt repository -----"
68+ sudo apt-get install -y wget gnupg
69+ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
70+ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
71+ sudo apt-get update -y -qq --fix-missing
72+ echo ""
73+
74+ sudo apt-get install -y \
75+ postgresql-${{ matrix.pg }} \
76+ postgresql-server-dev-${{ matrix.pg }}
77+
78+ echo ""
79+ echo "----- pg_config -----"
80+ pg_config
81+ echo ""
82+ - name : Set up PostgreSQL permissions
83+ run : sudo chmod a+rwx `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --pkglibdir` `/usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config --sharedir`/extension /var/run/postgresql/
84+
85+ - name : Cache cargo registry
86+ uses : actions/cache@v4
87+ continue-on-error : false
88+ with :
89+ path : |
90+ ~/.cargo/registry
91+ ~/.cargo/git
92+ key : tests-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }}
93+
94+ - name : Cache sccache directory
95+ uses : actions/cache@v4
96+ continue-on-error : false
97+ with :
98+ path : /home/runner/.cache/sccache
99+ key : pgrx-tests-sccache-${{ runner.os }}-${{ hashFiles('**/Cargo.lock', '.github/workflows/tests.yml') }}
100+
101+ - name : Start sccache server
102+ run : sccache --start-server
103+
104+ - name : Print sccache stats (before run)
105+ run : sccache --show-stats
106+
107+ - name : Install cargo-pgrx
108+ run : |
109+ PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
110+ cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
111+ cargo pgrx init --pg${{ matrix.pg }} /usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config
112+ - name : Run tests
113+ run : echo "\q" | cargo pgrx run pg${{ matrix.pg }} && cargo test --no-default-features --features pg${{ matrix.pg }}
114+
115+ - name : Build
116+ run : cargo pgrx package --features pg${{ matrix.pg }} --pg-config /usr/lib/postgresql/${{ matrix.pg }}/bin/pg_config
117+
118+ - name : Archive production artifacts
119+ uses : actions/upload-artifact@v4
120+ with :
121+ name : typeid-${{matrix.pg}}
122+ path : |
123+ target/release/typeid-pg${{ matrix.pg }}
124+ # Attempt to make the cache payload slightly smaller.
125+ - name : Clean up built PGRX files
126+ run : |
127+ cd target/debug/deps/
128+ for built_file in $(find * -type f -executable -print | grep -v "\.so$"); do
129+ base_name=$(echo $built_file | cut -d- -f1);
130+ for basefile in "$base_name".*; do
131+ [ -f "$basefile" ] || continue;
132+ echo "Removing $basefile"
133+ rm $basefile
134+ done;
135+ echo "Removing $built_file"
136+ rm $built_file
137+ done
138+ - name : Stop sccache server
139+ run : sccache --stop-server || true
140+ Install :
141+ runs-on : ubuntu-latest
142+ steps :
143+ - uses : actions/checkout@v4
144+ - name : Install PostgreSQL headers
145+ run : |
146+ sudo apt-get update
147+ sudo apt-get install postgresql-server-dev-14
148+ - name : Install cargo-pgrx
149+ run : |
150+ PGRX_VERSION=$(cargo metadata --format-version 1 | jq -r '.packages[]|select(.name=="pgrx")|.version')
151+ cargo install --locked --version=$PGRX_VERSION cargo-pgrx --debug --force
152+ cargo pgrx init --pg14 $(which pg_config)
153+ - name : Install TypeID/pgrx
154+ run : |
155+ cargo pgrx install --no-default-features --release --sudo
156+ - name : Start PostgreSQL
157+ run : |
158+ sudo systemctl start postgresql.service
159+ pg_isready
160+ # superuser (-s), can create databases (-d) and roles (-r), no password prompt (-w) named runner
161+ sudo -u postgres createuser -s -d -r -w runner
162+ - name : Verify install
163+ run : |
164+ createdb -U runner runner
165+ psql -U runner -c "create extension typeid;"
166+ psql -U runner -c "select typeid_generate('user');"
167+ rustfmt :
168+ runs-on : ubuntu-latest
169+ steps :
170+ - name : Checkout code
171+ uses : actions/checkout@v4
172+ - name : Run rustfmt
173+ run : cargo fmt -- --check
0 commit comments