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

ci: Only run checks on changed crates #1498

Merged
merged 1 commit into from
Feb 16, 2022
Merged
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
50 changes: 43 additions & 7 deletions .github/workflows/check-each.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env:
RUSTUP_MAX_RETRIES: 10

jobs:
enumerate:
list-changed-crates:
timeout-minutes: 3
runs-on: ubuntu-latest
container:
Expand All @@ -32,24 +32,60 @@ jobs:
- run: apt update && apt install -y jq
- uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579
- run: cargo fetch
- name: list crates
id: list-crates
- uses: tj-actions/changed-files@b3b79dbb9cf4fd390105963b48346e14b4842cc1
id: changed-files
with:
files: |
- Cargo.toml
- "**/Cargo.toml"
- "**/*.rs"
- .github/workflows/check-each.yml
- name: list changed crates
id: list-changed
run: |
files="${{ steps.changed-files.outputs.all_changed_files }}"
# Find the nearest Cargo.toml (except the root).
find_manifest() {
p=$(dirname "$1")
if [ -f "$p/Cargo.toml" ]; then
realpath "$p/Cargo.toml"
else
find_manifest "$p"
fi
}
# Build an expression to match all changed manifests.
manifest_expr() {
expr="false"
for file in $(echo $*) ; do
# If the workflow changes or root Cargo.toml changes, run checks for all crates in the repo.
if [ "$file" = .github/workflows/check-each.yml ] || [ "$file" = "$PWD/Cargo.toml" ]; then
expr="startswith(\"$PWD\")"
break
fi
# Otherwise, only run checks for changes to subcrates (and not the top-level crate).
m=$(find_manifest "$file")
if [ "$m" != "$PWD/Cargo.toml" ]; then
expr="$expr or (. == \"$m\")"
fi
done
echo "$expr"
}
# Get the crate names for all changed manifest direcotires
crates=$(cargo metadata --frozen --format-version=1 \
| jq -cr "[.packages[] | select(.manifest_path | startswith(\"$PWD\")) | .name]")
| jq -cr "[.packages[] | select(.manifest_path | $(manifest_expr $files)) | .name]")
echo "::set-output name=crates::$crates"
outputs:
crates: ${{ steps.list-crates.outputs.crates }}
crates: ${{ steps.list-changed.outputs.crates }}

check:
needs: enumerate
needs: list-changed-crates
timeout-minutes: 20
runs-on: ubuntu-latest
container:
image: docker://rust:1.56.1-buster
strategy:
matrix:
crate: ${{ fromJson(needs.enumerate.outputs.crates) }}
crate: ${{ fromJson(needs.list-changed-crates.outputs.crates) }}
steps:
- run: |
curl --proto =https --tlsv1.3 -vsSfLo /usr/local/bin/cargo-action-fmt "https://github.com/olix0r/cargo-action-fmt/releases/download/release%2F${CARGO_ACTION_FMT_VERSION}/cargo-action-fmt-x86_64-unknown-linux-gnu"
Expand Down