Skip to content
Snippets Groups Projects
Commit dacd91a3 authored by Damien Pollet's avatar Damien Pollet :coffee:
Browse files

Hopefully robust makefile

parent 4d5596d4
No related branches found
No related tags found
No related merge requests found
......@@ -5,10 +5,8 @@ default:
entrypoint: [""]
build:
script:
before_script:
- apk --no-cache add make git
- sh --version; git --version; pandoc --version
- git branch --verbose; git branch --verbose --remote
- make prepare wipe
- make
- git --version; pandoc --version
script:
- make publish
......@@ -9,36 +9,39 @@ OUT_MARKUP := $(SRC_MARKUP:$(SRC)/%.md=$(OUT)/%.php)
OUT_OTHERS := $(SRC_OTHERS:$(SRC)/%=$(OUT)/%)
OUT_DIRS := $(SRC_DIRS:$(SRC)/%=$(OUT)/%)
.PHONY: all prepare wipe publish clean
.PHONY: prepare build publish clean
.DEFAULT_GOAL := build
all : $(OUT_MARKUP) $(OUT_OTHERS)
prepare : $(OUT)/.git
prepare : $(OUT)
git fetch origin public
git worktree add $(OUT) public
if [ -n "$${DEPLOY_TOKEN}" ]; then \
git config user.name '${GITLAB_USER_NAME}'; \
git config user.email '${GITLAB_USER_EMAIL}'; \
git remote set-url origin "https://cicd:$${DEPLOY_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git"; \
fi
build : $(OUT_MARKUP) $(OUT_OTHERS)
wipe :
find $(OUT) -mindepth 1 -not -name '.git' -delete
publish :
git -C $(OUT) add .
git -C $(OUT) commit --message 'Publish from $(shell git rev-parse HEAD)'
git -C $(OUT) push --push-option ci.skip origin 'HEAD:public'
publish : | prepare build
if [ -n "$$(git -C $(OUT) status --porcelain)" ]; then \
cd $(OUT) ;\
git add . ;\
git commit --message 'Publish from $(shell git rev-parse HEAD)' ;\
git push --push-option ci.skip origin 'HEAD:public' ;\
fi
clean :
rm -fr $(OUT)
git worktree prune
$(OUT)/.git :
git fetch origin public
git worktree add --no-checkout $(OUT) public
if [ "$$CI" == 'true' -a -n "$$DEPLOY_TOKEN" ]; then \
git config user.name "$$GITLAB_USER_NAME" ;\
git config user.email "$$GITLAB_USER_EMAIL" ;\
git remote set-url origin "https://cicd:$${DEPLOY_TOKEN}@$${CI_SERVER_HOST}/$${CI_PROJECT_PATH}.git" ;\
fi
$(OUT) :
mkdir $(OUT)
$(OUT_DIRS) : $(OUT)
mkdir -p $@
@mkdir -p $@
.SECONDEXPANSION: # oooh, magic *_*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment