2024-01-31 00:19:49 +00:00
|
|
|
#!/usr/bin/env bash
|
2024-01-20 14:07:03 +00:00
|
|
|
|
2024-03-26 23:08:57 +00:00
|
|
|
set -euo pipefail
|
2024-01-20 14:07:03 +00:00
|
|
|
|
|
|
|
# Generates the label configuration using crates in the repository.
|
|
|
|
# The label configuration is appended to the labeler config file.
|
|
|
|
|
|
|
|
config=.github/labeler.yml
|
|
|
|
|
2024-03-27 22:08:08 +00:00
|
|
|
# Define a default value for SCAN_DIR if not set
|
|
|
|
: "${SCAN_DIR:=.}"
|
2024-01-20 14:07:03 +00:00
|
|
|
|
2024-03-27 22:08:08 +00:00
|
|
|
if [ "${1:-default}" '!=' "--force" ] && ! git diff --exit-code "$config";
|
2024-01-20 14:07:03 +00:00
|
|
|
then
|
|
|
|
echo "Error: $config is not committed."
|
|
|
|
echo "Refusing to overwrite it to prevent disaster."
|
|
|
|
echo "Run the script with --force to override this."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
excluded_crates="fuzz|dep_test"
|
|
|
|
|
2024-03-27 22:08:08 +00:00
|
|
|
CRATES="`cd "$SCAN_DIR" && cargo metadata --no-deps --format-version 1 | jq -j -r '.packages | map(.manifest_path | rtrimstr("/Cargo.toml") | ltrimstr("'$PWD'/")) | join(" ")'`"
|
2024-01-20 14:07:03 +00:00
|
|
|
|
|
|
|
for crate in $CRATES;
|
|
|
|
do
|
|
|
|
if echo "$crate" | grep -qE "$excluded_crates";
|
|
|
|
then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "C-$crate:" >> "$config"
|
|
|
|
echo " - changed-files:" >> "$config"
|
|
|
|
echo " - any-glob-to-any-file: $crate/**" >> "$config"
|
|
|
|
done
|