makefile - 如果变量为空,如何跳过 Make 目标?
问题描述
考虑以下生成文件
# If current commit is not part of a PR, the PULL_REQUEST_ID variable will be empty.
PULL_REQUEST_ID := $(shell git ls-remote origin 'pull/*/head' | grep -F -f <(git rev-parse HEAD) | awk -F'/' '{print $3}')
# if PULL_REQUEST_ID is empty, I want 'make deploy-to-staging' to be no-op
.PHONY deploy-to-staging
deploy-to-staging: update-some-files apply-those-files-to-k8s
解决方案
使用条件指令ifneq
。
deploy-to-staging: update-some-files apply-those-files-to-k8s
ifneq ($(PULL_REQUEST_ID),'')
git push ... # or whatever
else
echo "Refusing to deploy non-pull-request to staging"
endif
推荐阅读
- c++ - 即使 fstream C++ 文件与 .cpp 位于同一位置,也无法打开它
- angular - 从 Angular 中的表中删除数据行(Spring-Rest API,MongoDB)
- terraform - gitlab-ci terraform 状态锁文件根除
- python - Regular Expression construction for plain text using Python
- swift - org.webrtc.RTCPeerConnection 无法将视频发布到服务器
- ruby-on-rails - 来自我的 Rails Web 应用程序的 gRPC 请求
- python - 值错误'/anaconda3/lib/libpython3.7.dylib'不存在?
- deep-learning - 尝试运行深度学习测试代码后,我在 Pycham 中遇到错误
- python - 如何在python中修复“TypeError:'numpy.ndarray'对象不可调用”
- react-native - 强制方向为横向时反应本机相机崩溃