I have a GitHub action that includes a call to find
where the result is chained to another command:
echo "Compiling..." && find $GEN_PROTO_DIR -type f -name "*.proto" -exec protoc \
--go_out=$GEN_OUT_DIR --go_opt=module=github.com/xefino \
--go-grpc_out=$GEN_OUT_DIR --go-grpc_opt=module=github.com/xefino \
--grpc-gateway_out=$GEN_OUT_DIR --grpc-gateway_opt logtostderr=true \
--grpc-gateway_opt paths=source_relative --grpc-gateway_opt generate_unbound_methods=true \{} \;
This command works but, if protoc
fails the action will still succeed and the message will be logged. Instead I want the message to be logged and the action to fail. How can I modify this code to achieve that behavior?
CodePudding user response:
You're using this find's -exec
syntax with a trailing ;
:
-exec command ;
which doesn't propagate the exit status from the -exec
part.
I believe you're looking for this syntax with a trailing
:
-exec command {}
which propagates the exit status.
According to its description from the find manual:
-exec command {} ... If any invocation with the ` ' form returns a non-zero value as exit status, then find returns a non-zero exit status. ...