Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: Improve speed of tools/changelogger-release.sh #39146

Merged
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
34 changes: 16 additions & 18 deletions tools/changelogger-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ if $ANY; then
fi

# Release the projects, in build order so we can force a release of something if one of its deps got updated.
declare -A RELEASED
for SLUG in "${TO_RELEASE[@]}"; do
cd "$BASE/projects/$SLUG"

Expand All @@ -172,7 +171,6 @@ for SLUG in "${TO_RELEASE[@]}"; do
fi

info "Processing $SLUG..."
RELEASED[$SLUG]=1

# Avoid "There are no changes with content for this write. Proceed?" prompts and empty changelog entries.
ANY=false
Expand Down Expand Up @@ -224,6 +222,7 @@ for SLUG in "${TO_RELEASE[@]}"; do
if [[ -z "$OLDVER" ]] || is_major_bump "$OLDVER" "$VER"; then
debug " Version bump ${OLDVER:-none} -> $VER looks like a major bump, adding a change entry to dependents without one"
for S in $( jq -r --arg slug "$SLUG" '.[$slug] // empty | .[]' <<<"$DEPTS" ); do
[[ "$S" == monorepo ]] && continue
cd "$BASE/projects/$S"
CHANGES_DIR=$(jq -r '.extra.changelogger["changes-dir"] // "changelog"' composer.json)
if [[ ! -d "$CHANGES_DIR" || -z "$(ls -- "$CHANGES_DIR")" ]]; then
Expand Down Expand Up @@ -251,25 +250,24 @@ done

cd "$BASE"
info "Updating dependencies..."
SLUGS=()
# Use a temp variable so pipefail works
TMP="$(pnpm jetpack dependencies build-order --pretty)"
mapfile -t SLUGS <<<"$TMP"

TMPDIR="${TMPDIR:-/tmp}"
TEMP=$(mktemp "${TMPDIR%/}/changelogger-release-XXXXXXXX")

for DEPENDENCY_SLUG in "${SLUGS[@]}"; do
if [[ -n "${RELEASED[$DEPENDENCY_SLUG]}" ]]; then
debug " tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -U $DEPENDENCY_SLUG"
PACKAGE_VERSIONS_CACHE="$TEMP" tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -U "$DEPENDENCY_SLUG"
debug " tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -U -P"
"$BASE"/tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -U -P
info "Adding changelog entries for unreleased projects..."
for DS in $( git -c core.quotepath=off diff --name-only projects | sed -e 's!^projects/\([^/]\+/[^/]\+\)/.*$!\1!' | sort -u ); do
cd "$BASE/projects/$DS"
if ! git diff --quiet ./CHANGELOG.md; then
debug " $DS is being released, no change entry needed"
elif ! git diff --quiet -- "./$( q -r '.extra.changelogger["changes-dir"] // "changelog"' composer.json )/"; then
debug " $DS already has an uncommitted change entry file, skipping"
elif ! git diff --quiet -- . ":!./composer.lock"; then
debug " $DS has non-lockfile changes"
changelogger_add 'Updated package dependencies.'
else
debug " tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -u $DEPENDENCY_SLUG"
PACKAGE_VERSIONS_CACHE="$TEMP" tools/check-intra-monorepo-deps.sh $VERBOSE $RELEASEBRANCH -u "$DEPENDENCY_SLUG"
debug " $DS has lockfile changes only"
changelogger_add '' 'Updated composer.lock.'
fi
done

rm "$TEMP"
cd "$BASE"

debug " Updating pnpm.lock..."
pnpm install --silent
Expand Down
23 changes: 10 additions & 13 deletions tools/check-intra-monorepo-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ BASE=$PWD
# Print help and exit.
function usage {
cat <<-EOH
usage: $0 [-a] [-n <name>] [-v] [-R] [-U|-u] [<slug> ...]
usage: $0 [-a] [-n <name>] [-v] [-R] [-P] [-U|-u] [<slug> ...]

Check that all composer and pnpm dependencies between monorepo projects are up to date.

Expand All @@ -28,6 +28,7 @@ function usage {
-n: Set changelogger filename.
-v: Output debug information.
-R: When on a release branch, skip updating the corresponding plugins.
-P: Skip updating pnpm lockfile. Automatically skipped if <slug> is passed.
EOH
exit 1
}
Expand All @@ -39,7 +40,8 @@ DOCL_EVER=true
AUTO_SUFFIX=false
CL_FILENAME=
RELEASEBRANCH=false
while getopts ":uUvhHRan:" opt; do
DO_PNPM_LOCK=true
while getopts ":uUvhHRPan:" opt; do
case ${opt} in
u)
UPDATE=true
Expand All @@ -61,6 +63,9 @@ while getopts ":uUvhHRan:" opt; do
# -H is an old name, kept for back compat.
RELEASEBRANCH=true
;;
P)
DO_PNPM_LOCK=false
;;
h)
usage
;;
Expand Down Expand Up @@ -123,23 +128,15 @@ function get_packages {
else
PKGS=()
fi
if [[ "$PACKAGES" == '{}' && -n "$PACKAGE_VERSIONS_CACHE" && -s "$PACKAGE_VERSIONS_CACHE" ]]; then
PACKAGES="$(<"$PACKAGE_VERSIONS_CACHE")"
else
for PKG in "${PKGS[@]}"; do
PACKAGES=$(jq -c --argjson packages "$PACKAGES" --arg ver "$(cd "${PKG%/composer.json}" && changelogger version current --default-first-version)" '.name as $k | $packages | .[$k] |= { rel: $ver, dep: ( "^" + $ver ) }' "$PKG")
done
if [[ -n "$PACKAGE_VERSIONS_CACHE" ]]; then
echo "$PACKAGES" > "$PACKAGE_VERSIONS_CACHE"
fi
fi
for PKG in "${PKGS[@]}"; do
PACKAGES=$(jq -c --argjson packages "$PACKAGES" --arg ver "$(cd "${PKG%/composer.json}" && changelogger version current --default-first-version)" '.name as $k | $packages | .[$k] |= { rel: $ver, dep: ( "^" + $ver ) }' "$PKG")
done

JSPACKAGES=$(jq -nc 'reduce inputs as $in ({}; if $in.name then .[$in.name] |= [ "workspace:*" ] else . end )' "$BASE"/projects/js-packages/*/package.json)
}

get_packages

DO_PNPM_LOCK=true
SLUGS=()
if [[ $# -le 0 ]]; then
# Use a temp variable so pipefail works
Expand Down
Loading