Skip to content

Instantly share code, notes, and snippets.

@dmattia
Created October 20, 2021 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmattia/79c475202758e01e15f71b152c8ffde1 to your computer and use it in GitHub Desktop.
Save dmattia/79c475202758e01e15f71b152c8ffde1 to your computer and use it in GitHub Desktop.
#!/bin/bash
WORKSPACE="${WORKSPACE:-@main/main}"
echo "Finding dependencies to watch under $WORKSPACE..."
watchedDependencies=$(yarn info "$WORKSPACE" --all --recursive --dependents --json | jq ".children.Dependencies[].locator, .value" | grep '@workspace' | sed 's/.*@workspace://' | sed 's/"$//' | xargs echo)
echo "Dependencies being watched: $watchedDependencies"
echo ""
echo "Finding dependencies that changed..."
changedDependencies=$(yarn workspaces list --json --since | jq ".location" | grep -v '\.' | xargs echo)
echo "Dependencies that changed: $changedDependencies"
echo ""
echo "Finding which watched deps have changed..."
has_changed=false
for changedLocation in $watchedDependencies; do
for depLocation in $changedDependencies; do
if [ "$changedLocation" == "$depLocation" ]; then
echo "The dependency $changedLocation changed in this pull request"
has_changed=true
fi
done
done
echo ""
if [[ -z "$GITHUB_ACTIONS" ]]; then
echo "dependencies of $WORKSPACE changed: $has_changed"
else
echo "::set-output name=has_changed::$has_changed"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment