我有下面的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