Build rustdoc with all features and with private items.

This commit is contained in:
Predrag Gruevski 2022-08-07 12:23:51 -04:00
parent 12560d69ad
commit b737f52f9c
2 changed files with 33 additions and 5 deletions

View file

@ -2,7 +2,7 @@
A GitHub Action for running cargo-semver-checks A GitHub Action for running cargo-semver-checks
By default, this action assumes that: 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`. - Your releases are tagged in git as `v{major}.{minor}.{patch}`, for example `v1.2.3`.
Single-crate workspaces can use it as: Single-crate workspaces can use it as:
@ -13,9 +13,9 @@ Single-crate workspaces can use it as:
run: # your `cargo publish` code here 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 `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`: 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 - name: Publish my-crate to crates.io
run: # your `cargo publish` code here 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
```

View file

@ -5,6 +5,10 @@ inputs:
description: 'The crate whose API to check for semver' description: 'The crate whose API to check for semver'
required: false required: false
default: '' 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 <NAME>`'
required: false
default: '--lib'
version-tag-prefix: version-tag-prefix:
description: 'The prefix to use for the git tag for a version; the default "v" creates tags like "v1.0.0"' description: 'The prefix to use for the git tag for a version; the default "v" creates tags like "v1.0.0"'
required: false required: false
@ -28,9 +32,23 @@ runs:
# Record the current git sha, so we can come back to it after generating the baseline. # Record the current git sha, so we can come back to it after generating the baseline.
export CURRENT_GIT_SHA="$(git rev-parse HEAD)" 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 }}" export PACKAGE_NAME="${{ inputs.crate-name }}"
if [[ "$PACKAGE_NAME" == '' ]]; then if [[ "$PACKAGE_NAME" == '' ]]; then
export PACKAGE_NAME="$("$GITHUB_ACTION_PATH/find_workspace_crates.sh")" 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 fi
export PACKAGE_NAME_WITH_UNDERSCORES="$(echo "$PACKAGE_NAME" | tr '-' '_')" 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")" 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 fetch --depth=1 origin "+refs/tags/$COMPARISON_TAG:refs/tags/$COMPARISON_TAG"
git checkout "$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 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. # Return to the original git sha.
@ -51,7 +69,7 @@ runs:
# Build rustdoc JSON for the current version, and move it to /tmp/ # Build rustdoc JSON for the current version, and move it to /tmp/
# so it doesn't get overwritten by the baseline build. # 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 mv "$(cargo metadata --format-version 1 | jq -r .target_directory)/doc/$PACKAGE_NAME_WITH_UNDERSCORES.json" /tmp/current.json
# Check for semver violations. # Check for semver violations.