This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d3b1e2
commit 3b0636b
Showing
3 changed files
with
55 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
function error() { | ||
echo "$@" 1>&2 | ||
} | ||
|
||
CHANGED_PACKAGES="" | ||
CHANGED_PACKAGE_LIST=() | ||
|
||
function check_changed_packages() { | ||
# Try get a merge base for the branch and calculate affected packages. | ||
# We need this check because some CIs can do a single branch clones with a limited history of commits. | ||
local packages | ||
local branch_base_sha="$(git merge-base --fork-point FETCH_HEAD HEAD || git merge-base FETCH_HEAD HEAD)" | ||
if [[ "$?" == 0 ]]; then | ||
echo "Checking for changed packages from $branch_base_sha" | ||
IFS=$'\n' packages=( $(git diff --name-only "$branch_base_sha" HEAD | grep -o "packages/[^/]*" | sed -e "s/packages\///g" | sort | uniq) ) | ||
else | ||
error "Cannot find a merge base for the current branch to run an incremental build..." | ||
error "Please rebase your branch onto the latest master!" | ||
return 1 | ||
fi | ||
|
||
# Filter out any packages that don't have a pubspec.yaml: they have probably | ||
# been deleted in this PR. | ||
CHANGED_PACKAGES="" | ||
local CHANGED_PACKAGE_LIST=() | ||
for package in "${packages[@]}"; do | ||
if [[ -f "$REPO_DIR/packages/$package/pubspec.yaml" ]]; then | ||
CHANGED_PACKAGES="${CHANGED_PACKAGES},$package" | ||
CHANGED_PACKAGE_LIST=("${CHANGED_PACKAGE_LIST[@]}" "$package") | ||
fi | ||
done | ||
|
||
if [[ "${#CHANGED_PACKAGE_LIST[@]}" == 0 ]]; then | ||
echo "No changes detected in packages. Skipping." | ||
return 0 | ||
else | ||
echo "Detected changes in the following ${#CHANGED_PACKAGE_LIST[@]} package(s):" | ||
for package in "${CHANGED_PACKAGE_LIST[@]}"; do | ||
echo "$package" | ||
done | ||
echo "" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters