我有下面的Makefile:当子命令抛出时终止makefile命令?
#runs the working directory unit tests
test:
@NODE_ENV=test; \
mocha --ignore-leaks $(shell find ./test -name \*test.js);
#deploys working directory
deploy:
@make test; \
make deploy-git; \
make deploy-servers;
#deploys working to git deployment branch
deploy-git:
@status=$$(git status --porcelain); \
if test "x$${status}" = x; then \
git branch -f deployment; \
git push origin deployment; \
echo "Done deploying to git deployment branch."; \
else \
git status; \
echo "Error: cannot deploy. Working directory is dirty."; \
fi
deploy-servers:
# for each server
# @DEPLOY_SERVER_IP = "127.0.0.1"; \
# make deploy-server
#deploy-server:
# connect to this server with ssh
# check if app is already running
# stop the app on the server if already running
# set working directory to app folder
# update deployment git branch
# use git to move head to deployment branch
# start app again
注意deploy-servers
和deploy-server
是现在只是假人。这是deploy
命令应该做的:
- 运行测试(
make test
),退出失败 - 推现任部署分支(
make deploy-git
),退出失败 服务器上
- 拉部署分支(
make deploy-servers
)
可以在Makefile中看到如下:
deploy:
@make test; \
make deploy-git; \
make deploy-servers;
问题是我不知道如何防止make deploy-git
在make test
失败时执行,以及如何防止make deploy-servers
在测试失败或make deploy-git
失败时执行。
有没有一个明确的方法来做到这一点,或者我应该使用shell文件还是使用正常的编程语言编写这些工具?
+1,但是请注意OP,您可能希望(至少)执行'make test $(MAKEFLAGS)'将任何其他命令行标志传播到子版本。 –
@威廉 - 这取决于,因为我的make(GNU Make 3.81)似乎自动执行此操作。我刚刚测试过,因为你的评论让我感到紧张。 – sage