Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the check public API script #59

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,18 @@ jobs:
run: cargo install cross --locked
- name: run cross test
run: cross test --target s390x-unknown-linux-gnu

API:
name: Check for changes to the public API
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@nightly
- name: Install cargo-public-api
run: cargo install --locked cargo-public-api
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to cache this.

- name: Running API checker script
run: ./contrib/check-for-api-changes.sh
493 changes: 155 additions & 338 deletions api/all-features.txt

Large diffs are not rendered by default.

489 changes: 153 additions & 336 deletions api/alloc.txt

Large diffs are not rendered by default.

469 changes: 143 additions & 326 deletions api/core2.txt

Large diffs are not rendered by default.

896 changes: 154 additions & 742 deletions api/default-features.txt

Large diffs are not rendered by default.

467 changes: 142 additions & 325 deletions api/no-default-features.txt

Large diffs are not rendered by default.

72 changes: 50 additions & 22 deletions contrib/check-for-api-changes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,62 @@

set -e

export RUSTDOCFLAGS='-A rustdoc::broken-intra-doc-links'
REPO_DIR=$(git rev-parse --show-toplevel)
API_DIR="$REPO_DIR/api"
CMD="cargo +nightly public-api --simplified"

CARGO="cargo +nightly public-api --simplified"
# `sort -n -u` doesn't work for some reason.
SORT="sort --numeric-sort"

# cargo public-api uses nightly so the toolchain must be available.
if ! cargo +nightly --version > /dev/null; then
echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2
exit 1
fi

pushd "$REPO_DIR" > /dev/null
$CMD --no-default-features | $SORT | uniq > "$API_DIR/no-default-features.txt"
$CMD | $SORT > "$API_DIR/default-features.txt"
$CMD --no-default-features --features=alloc | $SORT | uniq > "$API_DIR/alloc.txt"
$CMD --no-default-features --features=core2 | $SORT | uniq > "$API_DIR/core2.txt"
$CMD --all-features | $SORT | uniq > "$API_DIR/all-features.txt"

if [[ $(git status --porcelain api) ]]; then
echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2
# Sort order is effected by locale. See `man sort`.
# > Set LC_ALL=C to get the traditional sort order that uses native byte values.
export LC_ALL=C

main() {
# cargo public-api uses nightly so the toolchain must be available.
if ! cargo +nightly --version > /dev/null; then
echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2
exit 1
fi

generate_api_files
check_for_changes
}

generate_api_files() {
pushd "$REPO_DIR" > /dev/null

$CARGO | $SORT | uniq > "$API_DIR/default-features.txt"

$CARGO --no-default-features | $SORT | uniq > "$API_DIR/no-default-features.txt"
$CARGO --no-default-features --features=alloc | $SORT | uniq > "$API_DIR/alloc.txt"
$CARGO --no-default-features --features=core2 | $SORT | uniq > "$API_DIR/core2.txt"

$CARGO --all-features | $SORT | uniq > "$API_DIR/all-features.txt"

popd > /dev/null
exit 1
else
echo "No changes to the current public API"
}

# Check if there are changes (dirty git index) to the `api/` directory.
check_for_changes() {
pushd "$REPO_DIR" > /dev/null

if [[ $(git status --porcelain api) ]]; then
git diff --color=always

echo
echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2
exit 1

else
echo "No changes to the current public API"
fi

popd > /dev/null
fi
}

#
# Main script
#
main "$@"
exit 0

Loading