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

Improve 'Please run' messages in the CI #48365

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ derive:
.PHONY: derive-up-to-date
derive-up-to-date: must-start-clean/host derive
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "derived functions" "make derive"; \
./build.assets/please-run.sh "derived functions" "make derive"; \
exit 1; \
fi

Expand Down Expand Up @@ -1578,14 +1578,15 @@ endif
.PHONY: protos-up-to-date/host
protos-up-to-date/host: must-start-clean/host grpc/host
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "protos gRPC" "make grpc"; \
./build.assets/please-run.sh "protos gRPC" "make grpc"; \
exit 1; \
fi

.PHONY: must-start-clean/host
must-start-clean/host:
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "protos gRPC" "make grpc"; \
echo 'This must be run from a repo with no unstaged commits.'; \
hugoShaka marked this conversation as resolved.
Show resolved Hide resolved
git diff; \
exit 1; \
fi

Expand All @@ -1594,12 +1595,12 @@ must-start-clean/host:
crds-up-to-date: must-start-clean/host
$(MAKE) -C integrations/operator manifests
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "operator CRD manifests" "make -C integrations/operator crd"; \
./build.assets/please-run.sh "operator CRD manifests" "make -C integrations/operator crd"; \
exit 1; \
fi
$(MAKE) -C integrations/operator crd-docs
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "operator CRD docs" "make -C integrations/operator crd"; \
./build.assets/please-run.sh "operator CRD docs" "make -C integrations/operator crd"; \
exit 1; \
fi

Expand All @@ -1608,7 +1609,7 @@ crds-up-to-date: must-start-clean/host
terraform-resources-up-to-date: must-start-clean/host
$(MAKE) -C integrations/terraform docs
@if ! git diff --quiet; then \
./build.assets/tooling/cmd/please-run.sh "TF provider docs" "make -C integrations/terraform docs"; \
./build.assets/please-run.sh "TF provider docs" "make -C integrations/terraform docs"; \
exit 1; \
fi

Expand Down
42 changes: 42 additions & 0 deletions build.assets/please-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

# This script is a helper that tells developers what generated content is out of date
# and which command to run.
# When running on GitHub actions, the script will also create an error in the PR and
# collapse the diff to improve readability.

set -eu

# only echoes the string if we are in GitHub Actions
echo_gha() {
if [ -n "${GITHUB_ACTIONS+x}" ]; then
echo "$@"
fi
hugoShaka marked this conversation as resolved.
Show resolved Hide resolved
}

main() {
if [ $# -ne 2 ]; then
echo "Usage: $0 <kind> <generate command>" >&2
exit 1
fi

KIND="$1"
GENERATE_COMMAND="$2"

TITLE="$KIND are out-of-date"
MESSAGE="Please run the command \`$GENERATE_COMMAND\`"

# Create a GitHub error
echo_gha "::error file=Makefile,title=$TITLE::$MESSAGE"

echo "============="
echo "$TITLE"
echo "$MESSAGE"
echo "============="

echo_gha "::group::Diff output"
git diff || true
echo_gha "::endgroup::"
}

main "$@"
39 changes: 0 additions & 39 deletions build.assets/tooling/cmd/please-run.sh
hugoShaka marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

Loading