Skip to content

Commit

Permalink
[v17] Improve 'Please run' messages in the CI (#48409)
Browse files Browse the repository at this point in the history
* Improve 'Please run error'

* add missing file

* fix script

* Apply suggestions from code review

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* address alan's feedback

* Update Makefile

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

* Update build.assets/please-run.sh

Co-authored-by: Alan Parra <alan.parra@goteleport.com>

---------

Co-authored-by: Alan Parra <alan.parra@goteleport.com>
  • Loading branch information
hugoShaka and codingllama authored Nov 5, 2024
1 parent 2226b46 commit 36406f5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 11 deletions.
17 changes: 6 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1543,8 +1543,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.'; \
git diff; \
./build.assets/please-run.sh "derived functions" "make derive"; \
exit 1; \
fi

Expand Down Expand Up @@ -1579,15 +1578,14 @@ 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.'; \
git diff; \
./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
Expand All @@ -1597,14 +1595,12 @@ 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.'; \
git diff; \
./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 \
echo 'Please run make -C integrations/operator crd-docs.'; \
git diff; \
./build.assets/please-run.sh "operator CRD docs" "make -C integrations/operator crd"; \
exit 1; \
fi

Expand All @@ -1613,8 +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 \
echo 'Please run make -C integrations/terraform docs.'; \
git diff; \
./build.assets/please-run.sh "TF provider docs" "make -C integrations/terraform docs"; \
exit 1; \
fi

Expand Down
40 changes: 40 additions & 0 deletions build.assets/please-run.sh
Original file line number Diff line number Diff line change
@@ -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 <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 "$@"
3 changes: 3 additions & 0 deletions integrations/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ help: ## Display this help.

##@ Development

.PHONY: crd ## Single command to generate anything CRD-related (manifests and docs)
crd: crdgen crd-docs

.PHONY: crdgen
crdgen: ## Generate CRDs
make -C crdgen
Expand Down

0 comments on commit 36406f5

Please sign in to comment.