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: Fix check-each workflow #2511

Merged
merged 1 commit into from
Nov 10, 2023
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
14 changes: 4 additions & 10 deletions .github/list-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -eu

if [ $# -ne 1 ]; then
if [ $# -eq 0 ]; then
echo "Usage: $0 <changed-files>"
exit 1
fi
Expand All @@ -23,30 +23,24 @@ manifest_expr() {

for file in "$@" ; do
# If the workflow changes or root Cargo.toml changes, run checks for all crates in the repo.
if [[ "$file" = .github/* ]] || [ "$file" = "$PWD/Cargo.toml" ]; then
if [[ "$file" = .github/* ]] || [ "$file" = "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
if [ "$m" != "Cargo.toml" ]; then
expr="$expr or (. == \"$m\")"
fi
done

echo "$expr"
}

files=$1
if [ -z "$files" ]; then
echo '[]'
exit 0
fi

# Get the crate names for all changed manifest directories.
crates=$(cargo metadata --locked --format-version=1 \
| jq -cr "[.packages[] | select(.manifest_path | $(manifest_expr "$files")) | .name]")
| jq -cr "[.packages[] | select(.manifest_path | $(manifest_expr "$@")) | .name]")

echo "crates=$crates" >> "$GITHUB_OUTPUT"
echo "$crates" | jq .
3 changes: 2 additions & 1 deletion .github/workflows/check-each.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ on:
- "**/Cargo.toml"
- "**/*.rs"
- .github/workflows/check-each.yml
- .github/list-crates.sh
- justfile

env:
Expand All @@ -39,7 +40,7 @@ jobs:
.github/workflows/check-each.yml
- name: List changed crates
id: changed-crates
run: ./.github/list-crates.sh '${{ steps.changed-files.outputs.all_changed_files }}'
run: ./.github/list-crates.sh ${{ steps.changed-files.outputs.all_changed_files }}
outputs:
crates: ${{ steps.changed-crates.outputs.crates }}

Expand Down