Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gspencergoog committed Aug 20, 2018
1 parent 1d3b1e2 commit 3b0636b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 87 deletions.
52 changes: 7 additions & 45 deletions script/check_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@
set -e

# This script checks to make sure that each of the plugins *could* be published.
# It doesn't acutually publish anything.
# It doesn't actually publish anything.

# So that users can run this script from anywhere and it will work as expected.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"

function error() {
echo "$@" 1>&2
}
source "$SCRIPT_DIR/common.sh"

function check_publish() {
local failures=()
Expand All @@ -25,51 +23,15 @@ function check_publish() {
fi
done
if [[ "${#failures[@]}" != 0 ]]; then
echo "FAIL: The following ${#failures[@]} package(s) failed the publishing check:"
error "FAIL: The following ${#failures[@]} package(s) failed the publishing check:"
for failure in "${failures[@]}"; do
echo "$failure"
error "$failure"
done
fi
return "${#failures[@]}"
}

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.
# If merge-base --fork-point can't be found (it's more conservative), then use regular merge-base.
local branch_base_sha="$(git merge-base --fork-point FETCH_HEAD HEAD || git merge-base FETCH_HEAD HEAD)"
echo "Checking for changed packages from $branch_base_sha"
local packages
if [[ "$?" == 0 ]]; then
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.
local existing=()
for package in "${packages[@]}"; do
if [[ -f "$REPO_DIR/packages/$package/pubspec.yaml" ]]; then
existing=("${existing[@]}" "$package")
fi
done

if [[ "${#existing[@]}" == 0 ]]; then
echo "No changes detected in packages. Skipping publish check."
return 0
else
echo "Detected changes in the following ${#existing[@]} package(s):"
for package in "${existing[@]}"; do
echo "$package"
done
echo ""
fi

check_publish "${existing[@]}"
}

check_changed_packages "$@"
# Sets CHANGED_PACKAGE_LIST
check_changed_packages

check_publish "${CHANGED_PACKAGE_LIST[@]}"
45 changes: 45 additions & 0 deletions script/common.sh
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
}
45 changes: 3 additions & 42 deletions script/incremental_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,7 @@ set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"

function error() {
echo "$@" 1>&2
}

CHANGED_PACKAGES=""

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 package_set=()
for package in "${packages[@]}"; do
if [[ -f "$REPO_DIR/packages/$package/pubspec.yaml" ]]; then
CHANGED_PACKAGES="${CHANGED_PACKAGES},$package"
package_set=("${package_set[@]}" "$package")
fi
done

if [[ "${#package_set[@]}" == 0 ]]; then
echo "No changes detected in packages. Skipping."
return 0
else
echo "Detected changes in the following ${#package_set[@]} package(s):"
for package in "${package_set[@]}"; do
echo "$package"
done
echo ""
fi
}
source "$SCRIPT_DIR/common.sh"

# Set some default actions if run without arguments.
ACTIONS=("$@")
Expand All @@ -58,7 +17,9 @@ if [[ "${BRANCH_NAME}" == "master" ]]; then
echo "Running for all packages"
(cd "$REPO_DIR" && pub global run flutter_plugin_tools "${ACTIONS[@]}" $PLUGIN_SHARDING)
else
# Sets CHANGED_PACKAGES
check_changed_packages

if [[ "$CHANGED_PACKAGES" == "" ]]; then
echo "Running for all packages"
(cd "$REPO_DIR" && pub global run flutter_plugin_tools "${ACTIONS[@]}" $PLUGIN_SHARDING)
Expand Down

0 comments on commit 3b0636b

Please sign in to comment.