Skip to content
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
65 changes: 25 additions & 40 deletions .github/scripts/get-changeset-arguments.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash -e

SOURCE_DIR=$(dirname "$0")

# This script takes a list of adapter names to release and outputs the
# arguments to pass to `yarn changeset version`.
#
Expand All @@ -22,57 +24,40 @@ get_packages_from_changeset_files() {
git grep -Eh "^'@chainlink/[^']*-adapter': (major|minor|patch)$" "$@" | sed -E "s#^'(@chainlink/[^']*-adapter)': (major|minor|patch).*\$#\\1#" | sort -u
}

CHANGED_PACKAGES_RECURSIVE="$(get_packages_from_changeset_files)"
CHANGED_PACKAGES_RECURSIVE="$($SOURCE_DIR/get-reverse-dependencies.sh $(get_packages_from_changeset_files) )"

is_changed() {
package="$1"
echo "$CHANGED_PACKAGES_RECURSIVE" | grep -Fxq "$package"
intersect() {
list1="$1"
list2="$2"
grep -Fxf <(echo "$list1") <<< "$list2"
}

add_reverse_package_deps() {
add_changed_reverse_package_deps() {
packages="$1"
{
for package in $packages; do
echo $package
# We need to include reverse dependencies because if a dependency is
# bumped, this also results in a patch bump of the dependent package.
# But if the dependency is not actually changed (either directly or
# transitively), but only included because of a requirement of
# `changeset version`, we don't want to include it. Otherwise almost all
# packages get included through common dependencies such as
# @chainlink/ea-test-helpers.
if ! is_changed $package; then
continue
fi
# git grep is a fast way to find candidate package.json files that probably depend on $package
for reverse_dep_package_file in $(git grep -l '"'"$package"'": "' 'packages/*/*/package.json'); do
# Check to make sure the candidate package.json file actually depends on $package
if jq -e --arg package "$package" '[ .dependencies | select(. | has($package)) ] | length > 0' "$reverse_dep_package_file" > /dev/null; then
jq -r '.name' "$reverse_dep_package_file"
fi
done
done
} | sort -u
# We need to include reverse dependencies because if a dependency is
# bumped, this also results in a patch bump of the dependent package.
# But if the dependency is not actually changed (either directly or
# transitively), but only included because of a requirement of
# `changeset version`, we don't want to include it. Otherwise almost all
# packages get included through common dependencies such as
# @chainlink/ea-test-helpers.
intersect "$($SOURCE_DIR/get-reverse-dependencies.sh $packages)" "$CHANGED_PACKAGES_RECURSIVE"
}

# Make sure CHANGED_PACKAGES_RECURSIVE contains transitive reverse dependencies.
new_changed_packages=$(add_reverse_package_deps "$CHANGED_PACKAGES_RECURSIVE")
while [[ "$new_changed_packages" != "$CHANGED_PACKAGES_RECURSIVE" ]]; do
CHANGED_PACKAGES_RECURSIVE="$new_changed_packages"
new_changed_packages="$(add_reverse_package_deps "$CHANGED_PACKAGES_RECURSIVE")"
done

add_package_deps() {
packages="$1"
{
for package in $packages; do
echo $package
package_file="$(git grep -l '"name": "'"$package"'"' packages)"
if [[ -z "$package_file" ]]; then
# This package is from another repo
continue
fi
jq -r '.dependencies | keys[]' "$package_file" | grep '@chainlink/'
for dep in $(jq -r '.dependencies | keys[]' "$package_file" | grep '@chainlink/'); do
dep_file="$(git grep -l '"name": "'"$dep"'"' packages)"
if [[ -z "$dep_file" ]]; then
# This package is from another repo
continue
fi
echo $dep
done
done
} | sort -u
}
Expand All @@ -94,7 +79,7 @@ add_deps() {
packages="$1"
packages=$(add_changeset_deps "$packages")
packages=$(add_package_deps "$packages")
packages=$(add_reverse_package_deps "$packages")
packages=$(add_changed_reverse_package_deps "$packages")
echo "$packages"
}

Expand Down
43 changes: 43 additions & 0 deletions .github/scripts/get-reverse-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash -e

# Returns a transitive list of reverse dependencies within the repository,
# including the input list of packages. Does not include reverse dependencies
# from devDependencies or peerDependencies.

if [[ "$#" = "0" ]]; then
echo "Usage: $0 <list of packages to get reverse dependencies of>" >&2
exit 1
fi

packages="$*"

for package_name in $packages; do
if ! git grep -q '"name": "'"$package_name"'"' packages; then
echo "'$package_name' is not a package in this repository." >&2
exit 1
fi
done

add_reverse_package_deps() {
packages="$1"
{
for package in $packages; do
echo $package
# git grep is a fast way to find candidate package.json files that probably depend on $package
for reverse_dep_package_file in $(git grep -l '"'"$package"'": "' 'packages/*/*/package.json'); do
# Check to make sure the candidate package.json file actually depends on $package
if jq -e --arg package "$package" '[ .dependencies | select(. | has($package)) ] | length > 0' "$reverse_dep_package_file" > /dev/null; then
jq -r '.name' "$reverse_dep_package_file"
fi
done
done
} | sort -u
}

new_packages=$(add_reverse_package_deps "$packages")
while [[ "$new_packages" != "$packages" ]]; do
packages="$new_packages"
new_packages="$(add_reverse_package_deps "$packages")"
done

echo "$packages"
10 changes: 9 additions & 1 deletion .github/scripts/list-packages-adapters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ SOURCE_DIR="$(dirname "$0")"

UPSTREAM_BRANCH="${1:-}"

PACKAGE_LIST=$(yarn workspaces list -R --json)

if [[ -z "$UPSTREAM_BRANCH" ]]; then
PACKAGE_LIST=$(yarn workspaces list -R --json)
else
PACKAGE_LIST=$(yarn workspaces list -R --json --since=$UPSTREAM_BRANCH)
changed_packages="$(yarn workspaces list --json --since=$UPSTREAM_BRANCH | jq -r 'select(.location | startswith("packages")) | .name')"
packages_to_include="$($SOURCE_DIR/get-reverse-dependencies.sh "$changed_packages")"
# Keep only the packages changed since UPSTREAM_BRANCH
PACKAGE_LIST=$(
echo $PACKAGE_LIST \
| jq -cr --arg packages "$packages_to_include" '($packages | split("\n")) as $packageNames | select(.name as $name | $packageNames | any($name == .))'
)
fi

# The yarn command used above will give us a list of the packages that have changed (including changes by dependencies)
Expand Down
Loading