From 8fc6ca21c741d8acf0a24f592e41939cc8343eb6 Mon Sep 17 00:00:00 2001 From: Hugo Shaka Date: Tue, 5 Nov 2024 09:42:01 -0500 Subject: [PATCH] Improve 'Please run' messages in the CI (#48365) (#48411) * Improve 'Please run error' * add missing file * fix script * Apply suggestions from code review * address alan's feedback * Update Makefile * Update build.assets/please-run.sh --------- Co-authored-by: Alan Parra --- Makefile | 9 ++++---- build.assets/please-run.sh | 40 ++++++++++++++++++++++++++++++++++ integrations/operator/Makefile | 3 +++ 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100755 build.assets/please-run.sh diff --git a/Makefile b/Makefile index e1a6c660854cc..7f96ba78d3a70 100644 --- a/Makefile +++ b/Makefile @@ -1419,7 +1419,7 @@ derive: .PHONY: derive-up-to-date derive-up-to-date: must-start-clean/host derive @if ! $(GIT) diff --quiet; then \ - echo 'Please run make derive.'; \ + ./build.assets/please-run.sh "derived functions" "make derive"; \ exit 1; \ fi @@ -1454,14 +1454,15 @@ endif .PHONY: protos-up-to-date/host protos-up-to-date/host: must-start-clean/host grpc/host @if ! $(GIT) diff --quiet; then \ - echo 'Please run 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 \ - echo 'This must be run from a repo with no unstaged commits.'; \ + @echo 'This must be run from a repo with no unstaged commits.'; \ + git diff; \ exit 1; \ fi @@ -1470,7 +1471,7 @@ must-start-clean/host: crds-up-to-date: must-start-clean/host $(MAKE) -C integrations/operator manifests @if ! $(GIT) diff --quiet; then \ - echo 'Please run make -C integrations/operator manifests.'; \ + ./build.assets/please-run.sh "operator CRD manifests" "make -C integrations/operator crd"; \ exit 1; \ fi diff --git a/build.assets/please-run.sh b/build.assets/please-run.sh new file mode 100755 index 0000000000000..236684efbb2b1 --- /dev/null +++ b/build.assets/please-run.sh @@ -0,0 +1,40 @@ +#!/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() { + [ -n "${GITHUB_ACTIONS+x}" ] && echo "$@" +} + +main() { + if [ $# -ne 2 ]; then + echo "Usage: $0 " >&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 "$@" \ No newline at end of file diff --git a/integrations/operator/Makefile b/integrations/operator/Makefile index f241376dbd068..033bc4c66388b 100644 --- a/integrations/operator/Makefile +++ b/integrations/operator/Makefile @@ -72,6 +72,9 @@ help: ## Display this help. ##@ Development +.PHONY: crd ## Single command to generate anything CRD-related (only manifests for this branch) +crd: crdgen + .PHONY: crdgen crdgen: ## Generate CRDs make -C crdgen