From b737f52f9c471aad374f170f677ca3fff1704786 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski Date: Sun, 7 Aug 2022 12:23:51 -0400 Subject: [PATCH] Build rustdoc with all features and with private items. --- README.md | 16 +++++++++++++--- action.yml | 22 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 051c451..50f386e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A GitHub Action for running cargo-semver-checks By default, this action assumes that: -- Your cargo workspace contains a single crate. +- Your cargo workspace contains a single crate which contains a library target. - Your releases are tagged in git as `v{major}.{minor}.{patch}`, for example `v1.2.3`. Single-crate workspaces can use it as: @@ -13,9 +13,9 @@ Single-crate workspaces can use it as: run: # your `cargo publish` code here ``` -To use it in a workspace with more than one crate: +In a workspace with more than one crate: - use the `crate-name` setting to specify which crate should be checked in a given run, and -- use the `version-tag-prefix` setting to override the default prefix `v` to match the way the releases of your crate are tagged. +- use the `version-tag-prefix` setting to override the default prefix `v` to match the way the releases of your crate are tagged. The version number `1.2.3` will be appended to this prefix. For example, this is publishing `my-crate` whose releases are tagged as `my-crate-v1.2.3`: ``` @@ -27,3 +27,13 @@ For example, this is publishing `my-crate` whose releases are tagged as `my-crat - name: Publish my-crate to crates.io run: # your `cargo publish` code here ``` + +To check a different (non-library) target in a crate, use the `crate-target` setting: +``` +- name: Check semver for my_binary + uses: obi1kenobi/cargo-semver-checks-action@v1 + with: + crate-target: --bin my_binary +- name: Publish my-crate to crates.io + run: # your `cargo publish` code here +``` diff --git a/action.yml b/action.yml index 0d31e2f..dac1ed2 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,10 @@ inputs: description: 'The crate whose API to check for semver' required: false default: '' + crate-target: + description: 'By default, check the library target of the crate. If you'd like to check a different target (e.g. a binary target), set this to `--bin `' + required: false + default: '--lib' version-tag-prefix: description: 'The prefix to use for the git tag for a version; the default "v" creates tags like "v1.0.0"' required: false @@ -28,9 +32,23 @@ runs: # Record the current git sha, so we can come back to it after generating the baseline. export CURRENT_GIT_SHA="$(git rev-parse HEAD)" + # We add `--all-features` to semver-check every part of the crate. + # In principle, semver can be broken by moving public API code into a feature. + # Checking this requires rebuilding rustdoc multiple times with different sets of features, + # which can get expensive and is therefore left to individual maintainers' discretion. + # + # We add `--document-private-items` because for some reason, rustdoc seems to not always + # generate all implemented trait information without it: + # https://github.com/obi1kenobi/cargo-semver-check/issues/32 + export RUSTDOC_EARLY_FLAGS="${{ inputs.crate-target }} --all-features" + export RUSTDOC_LATE_FLAGS="--document-private-items -Zunstable-options --output-format json" + export PACKAGE_NAME="${{ inputs.crate-name }}" if [[ "$PACKAGE_NAME" == '' ]]; then export PACKAGE_NAME="$("$GITHUB_ACTION_PATH/find_workspace_crates.sh")" + else + # cargo rustdoc uses the exact package name, not the "underscores" version. + export RUSTDOC_EARLY_FLAGS="--package $PACKAGE_NAME $RUSTDOC_EARLY_FLAGS" fi export PACKAGE_NAME_WITH_UNDERSCORES="$(echo "$PACKAGE_NAME" | tr '-' '_')" @@ -43,7 +61,7 @@ runs: export COMPARISON_TAG="${{ inputs.version-tag-prefix }}$("$GITHUB_ACTION_PATH/find_comparison_version.sh" "$PACKAGE_NAME")" git fetch --depth=1 origin "+refs/tags/$COMPARISON_TAG:refs/tags/$COMPARISON_TAG" git checkout "$COMPARISON_TAG" - cargo +nightly rustdoc -- -Zunstable-options --output-format json + cargo +nightly rustdoc $RUSTDOC_EARLY_FLAGS -- $RUSTDOC_LATE_FLAGS mv "$(cargo metadata --format-version 1 | jq -r .target_directory)/doc/$PACKAGE_NAME_WITH_UNDERSCORES.json" /tmp/baseline.json # Return to the original git sha. @@ -51,7 +69,7 @@ runs: # Build rustdoc JSON for the current version, and move it to /tmp/ # so it doesn't get overwritten by the baseline build. - cargo +nightly rustdoc -- -Zunstable-options --output-format json + cargo +nightly rustdoc $RUSTDOC_EARLY_FLAGS -- $RUSTDOC_LATE_FLAGS mv "$(cargo metadata --format-version 1 | jq -r .target_directory)/doc/$PACKAGE_NAME_WITH_UNDERSCORES.json" /tmp/current.json # Check for semver violations.