我有以下 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 文件或用普通的编程语言编写这些工具?