Skip to content

Commit edbe764

Browse files
authored
Guard pgrx docs.rs release builds (#2315)
This adds a script that our `./publish.sh` runs to do a docs build first. It also runs in CI in the `package-test.yml` job. The idea is if that fails we'll have to figure out why and fix it before finally pushing the release. I'll find out how well this works when I do the next one.
1 parent beb6803 commit edbe764

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

.github/workflows/package-test.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ jobs:
110110
-p pgrx-tests \
111111
-p cargo-pgrx \
112112
--features "pg$PG_VER"
113+
114+
- name: Verify docs.rs build path
115+
run: ./tools/docsrs-check.sh

publish.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
DIR=`pwd`
1414
set -x
1515

16+
./tools/docsrs-check.sh || exit $?
17+
1618
# dependency graph, from roots to facades
1719
#
1820
# pgrx-pg-config

tools/docsrs-check.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
#LICENSE Portions Copyright 2026 PgCentral Foundation, Inc. <contact@pgcentral.org>
3+
#LICENSE
4+
#LICENSE All rights reserved.
5+
#LICENSE
6+
#LICENSE Use of this source code is governed by the MIT license that can be found in the LICENSE file.
7+
8+
set -euo pipefail
9+
10+
PG_VER="${PG_VER:-14}"
11+
PG_FEATURE="pg${PG_VER#pg}"
12+
TOOLCHAIN="${DOCSRS_TOOLCHAIN:-nightly}"
13+
PACKAGE_DIR="${CARGO_TARGET_DIR:-target}/package"
14+
15+
echo "Checking packaged pgrx-bindgen dependency metadata"
16+
# Package the local internal dependency too so unpublished release-candidate
17+
# workspace versions do not force pgrx-bindgen to resolve it from crates.io.
18+
cargo "+${TOOLCHAIN}" package --allow-dirty --no-verify -p pgrx-pg-config -p pgrx-bindgen
19+
20+
shopt -s nullglob
21+
crates=("${PACKAGE_DIR}"/pgrx-bindgen-*.crate)
22+
if (( ${#crates[@]} == 0 )); then
23+
echo "Could not find packaged pgrx-bindgen crate in ${PACKAGE_DIR}" >&2
24+
exit 1
25+
fi
26+
crate="$(ls -t "${crates[@]}" | head -n 1)"
27+
28+
tmpdir="$(mktemp -d)"
29+
trap 'rm -rf "${tmpdir}"' EXIT
30+
31+
manifest_path="$(tar -tf "${crate}" | grep '/Cargo.toml$' | head -n 1)"
32+
lock_path="$(tar -tf "${crate}" | grep '/Cargo.lock$' | head -n 1 || true)"
33+
34+
tar -xOf "${crate}" "${manifest_path}" > "${tmpdir}/Cargo.toml"
35+
if grep -A 8 '^\[dependencies.bindgen\]' "${tmpdir}/Cargo.toml" | grep -q '"experimental"'; then
36+
echo "pgrx-bindgen package enables bindgen/experimental, which breaks docs.rs via annotate-snippets" >&2
37+
exit 1
38+
fi
39+
40+
if [[ -n "${lock_path}" ]]; then
41+
tar -xOf "${crate}" "${lock_path}" > "${tmpdir}/Cargo.lock"
42+
if grep -q 'name = "annotate-snippets"' "${tmpdir}/Cargo.lock"; then
43+
echo "pgrx-bindgen package lockfile contains annotate-snippets; check bindgen features" >&2
44+
exit 1
45+
fi
46+
fi
47+
48+
echo "Running docs.rs-style rustdoc check for pgrx with ${PG_FEATURE} cshim"
49+
host="$(rustc "+${TOOLCHAIN}" -vV | awk '/^host:/ { print $2 }')"
50+
rustdoc_cmd=(
51+
cargo "+${TOOLCHAIN}" rustdoc
52+
-p pgrx
53+
--lib
54+
--no-default-features
55+
--features "${PG_FEATURE} cshim"
56+
-Zrustdoc-map
57+
-Zhost-config
58+
-Ztarget-applies-to-host
59+
)
60+
61+
docsrs_target="${DOCSRS_TARGET:-}"
62+
if [[ -z "${docsrs_target}" && "${host}" == "x86_64-unknown-linux-gnu" ]]; then
63+
docsrs_target="x86_64-unknown-linux-gnu"
64+
fi
65+
66+
if [[ -n "${docsrs_target}" ]]; then
67+
rustdoc_cmd+=(--target "${docsrs_target}")
68+
fi
69+
70+
docsrs_rustdocflags="${RUSTDOCFLAGS:-}"
71+
docsrs_rustdocflags="${docsrs_rustdocflags:+${docsrs_rustdocflags} }--cfg docsrs -Z unstable-options --emit=invocation-specific --cap-lints warn"
72+
73+
DOCS_RS=1 RUSTDOCFLAGS="${docsrs_rustdocflags}" "${rustdoc_cmd[@]}"

0 commit comments

Comments
 (0)