This commit is contained in:
aynic.os 2021-06-14 14:32:14 +02:00
parent 97cd91a020
commit f0c10a3082
7 changed files with 72 additions and 76 deletions

5
CHANGELOG.md Normal file
View File

@ -0,0 +1,5 @@
# CHANGELOG
## v1.0-alpha
First public release. Code as Doc.

View File

@ -38,7 +38,7 @@ build@%: myos-base
$(if $(build_app), \
$(call make,build-init app-build), \
$(foreach service,$(SERVICES), \
$(call INFO,docker image $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) has id $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null)) && \
$(or $(call INFO,docker image $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) has id $(shell docker images -q $(DOCKER_REPOSITORY)/$(service):$(DOCKER_IMAGE_TAG) 2>/dev/null)), true) && \
) true \
)

View File

@ -135,8 +135,8 @@ docker-network-create: docker-network-create-$(DOCKER_NETWORK)
.PHONY: docker-network-create-%
docker-network-create-%:
if [ -z "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ]; then \
$(RUN) docker network create $* >/dev/null \
&& $(call INFO,docker network $* created); fi \
$(RUN) sh -c 'docker network create $* >/dev/null' \
&& $(or $(call INFO,docker network $* created), true); fi \
# target docker-network-rm: Fire docker-network-rm-% for DOCKER_NETWORK
.PHONY: docker-network-rm
@ -147,7 +147,7 @@ docker-network-rm: docker-network-rm-$(DOCKER_NETWORK)
docker-network-rm-%:
if [ -n "$(shell docker network ls -q --filter name='^$*$$' 2>/dev/null)" ]; then \
$(RUN) docker network rm $* >/dev/null \
&& $(call INFO,docker network $* removed); fi \
&& $(or $(call INFO,docker network $* removed), true); fi \
# target docker-plugin-install: Exec 'docker plugin install DOCKER_PLUGIN_OPTIONS DOCKER_PLUGIN'
.PHONY: docker-plugin-install

View File

@ -3,84 +3,72 @@
# target git-branch-create-upstream-%: Create git BRANCH from upstream/% branch
.PHONY: git-branch-create-upstream-%
git-branch-create-upstream-%: myos-base update-upstream
$(RUN) $(call exec,git fetch --prune upstream)
$(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1) \
&& $(call WARNING,present branch,$(BRANCH)) \
|| $(RUN) $(call exec,git branch $(BRANCH) upstream/$*)
$(call exec,[ $$(git ls-remote --heads upstream $(BRANCH) |wc -l) -eq 0 ]) \
&& $(RUN) $(call exec,git push upstream $(BRANCH)) \
|| $(call WARNING,present branch,$(BRANCH),upstream)
$(RUN) $(call exec,git checkout $(BRANCH))
git-branch-create-upstream-%: $(if $(DOCKER_RUN),myos-base) update-upstream
$(RUN) git fetch --prune upstream
git rev-parse --verify $(BRANCH) >/dev/null 2>&1 \
&& $(or $(call WARNING,present branch,$(BRANCH)), true) \
|| $(RUN) git branch $(BRANCH) upstream/$*
[ $$(git ls-remote --heads upstream $(BRANCH) |wc -l) -eq 0 ] \
&& $(RUN) git push upstream $(BRANCH) \
|| $(or $(call WARNING,present branch,$(BRANCH),upstream), true)
$(RUN) git checkout $(BRANCH)
# target git-branch-delete: Delete git BRANCH
.PHONY: git-branch-delete
git-branch-delete: myos-base update-upstream
$(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1) \
&& $(RUN) $(call exec,git branch -d $(BRANCH)) \
|| $(call WARNING,no branch,$(BRANCH))
$(foreach remote,upstream,$(call exec,[ $$(git ls-remote --heads $(remote) $(BRANCH) |wc -l) -eq 1 ]) \
&& $(RUN) $(call exec,git push $(remote) :$(BRANCH)) \
|| $(call WARNING,no branch,$(BRANCH),$(remote)) \
git-branch-delete: $(if $(DOCKER_RUN),myos-base) update-upstream
git rev-parse --verify $(BRANCH) >/dev/null 2>&1 \
&& $(RUN) git branch -d $(BRANCH) \
|| $(or $(call WARNING,no branch,$(BRANCH)), true)
$(foreach remote,upstream,[ $$(git ls-remote --heads $(remote) $(BRANCH) |wc -l) -eq 1 ] \
&& $(RUN) git push $(remote) :$(BRANCH) \
|| $(or $(call WARNING,no branch,$(BRANCH),$(remote)), true) \
&&) true
# target git-branch-merge-upstream-%: Merge git BRANCH into upstream/% branch
.PHONY: git-branch-merge-upstream-%
git-branch-merge-upstream-%: myos-base update-upstream
$(RUN) $(call exec,git rev-parse --verify $(BRANCH) >/dev/null 2>&1)
$(RUN) $(call exec,git checkout $(BRANCH))
$(RUN) $(call exec,git pull --ff-only upstream $(BRANCH))
$(RUN) $(call exec,git push upstream $(BRANCH))
$(RUN) $(call exec,git checkout $*)
$(RUN) $(call exec,git pull --ff-only upstream $*)
$(RUN) $(call exec,git merge --no-ff --no-edit $(BRANCH))
$(RUN) $(call exec,git push upstream $*)
git-branch-merge-upstream-%: $(if $(DOCKER_RUN),myos-base) update-upstream
git rev-parse --verify $(BRANCH) >/dev/null 2>&1
$(RUN) git checkout $(BRANCH)
$(RUN) git pull --ff-only upstream $(BRANCH)
$(RUN) git push upstream $(BRANCH)
$(RUN) git checkout $*
$(RUN) git pull --ff-only upstream $*
$(RUN) git merge --no-ff --no-edit $(BRANCH)
$(RUN) git push upstream $*
# target git-stash: git stash
.PHONY: git-stash
git-stash: myos-base git-status
if [ ! $(STATUS) -eq 0 ]; then \
$(RUN) $(call exec,git stash); \
fi
# target git-status: Define STATUS with number of lines of git status
.PHONY: git-status
git-status: myos-base
$(eval IGNORE_DRYRUN := true)
$(eval STATUS := $(shell $(call exec,sh -c 'git status -uno --porcelain 2>/dev/null |wc -l')))
$(eval IGNORE_DRYRUN := false)
git-stash: $(if $(DOCKER_RUN),myos-base)
$(if $(filter-out 0,$(STATUS)),$(RUN) git stash)
# target git-tag-create-upstream-%: Create git TAG to reference upstream/% branch
.PHONY: git-tag-create-upstream-%
git-tag-create-upstream-%: myos-base update-upstream
git-tag-create-upstream-%: $(if $(DOCKER_RUN),myos-base) update-upstream
ifneq ($(words $(TAG)),0)
$(RUN) $(call exec,git checkout $*)
$(RUN) $(call exec,git pull --tags --prune upstream $*)
$(RUN) $(call sed,s/^##\? $(TAG).*/## $(TAG) - $(shell date +%Y-%m-%d)/,CHANGELOG.md)
$(call exec,[ $$(git diff CHANGELOG.md 2>/dev/null |wc -l) -eq 0 ]) \
|| $(RUN) $(call exec,git commit -m "$$(cat CHANGELOG.md |sed -n '/$(TAG)/,/^$$/{s/##\(.*\)/release\1\n/;p;}')" CHANGELOG.md)
$(call exec,[ $$(git tag -l $(TAG) |wc -l) -eq 0 ]) \
|| $(RUN) $(call exec,git tag -d $(TAG))
$(RUN) $(call exec,git tag $(TAG))
$(call exec,[ $$(git ls-remote --tags upstream $(TAG) |wc -l) -eq 0 ]) \
|| $(RUN) $(call exec,git push upstream :refs/tags/$(TAG))
$(RUN) $(call exec,git push --tags upstream $*)
$(RUN) git checkout $*
$(RUN) git pull --tags --prune upstream $*
$(call sed,s/^##\? $(TAG).*/## $(TAG) - $(shell date +%Y-%m-%d)/,CHANGELOG.md)
[ $$(git diff CHANGELOG.md 2>/dev/null |wc -l) -eq 0 ] \
|| $(RUN) git commit -m "$$(cat CHANGELOG.md |sed -n '/$(TAG)/,/^$$/{s/##\(.*\)/release\1\n/;p;}')" CHANGELOG.md
[ $$(git tag -l $(TAG) |wc -l) -eq 0 ] \
|| $(RUN) git tag -d $(TAG)
$(RUN) git tag $(TAG)
[ $$(git ls-remote --tags upstream $(TAG) |wc -l) -eq 0 ] \
|| $(RUN) git push upstream :refs/tags/$(TAG)
$(RUN) git push --tags upstream $*
endif
# target git-tag-merge-upstream-%: Merge git TAG into upstream/% branch
.PHONY: git-tag-merge-upstream-%
git-tag-merge-upstream-%: myos-base update-upstream
git-tag-merge-upstream-%: $(if $(DOCKER_RUN),myos-base) update-upstream
ifneq ($(words $(TAG)),0)
$(RUN) $(call exec,git fetch --tags -u --prune upstream $*:$*)
$(RUN) $(call exec,git checkout $*)
$(RUN) $(call exec,git merge --ff --no-edit $(TAG))
$(RUN) $(call exec,git push upstream $*)
$(RUN) git fetch --tags -u --prune upstream $*:$*
$(RUN) git checkout $*
$(RUN) git merge --ff --no-edit $(TAG)
$(RUN) git push upstream $*
endif
# target git-unstash: git stash pop
.PHONY: git-unstash
git-unstash: myos-base
$(eval STATUS ?= 0)
if [ ! $(STATUS) -eq 0 ]; then \
$(RUN) $(call exec,git stash pop); \
fi
git-unstash: $(if $(DOCKER_RUN),myos-base)
$(if $(filter-out 0,$(STATUS)),$(RUN) git stash pop)

View File

@ -1,6 +1,9 @@
##
# RELEASE
RELEASE_BRANCH ?= $(BRANCH)
RELEASE_VERSION ?= $(VERSION)
# target release-check: Define RELEASE_BRANCH and RELEASE_VERSION
.PHONY: release-check
release-check:
@ -13,8 +16,6 @@ ifneq ($(findstring $(firstword $(subst /, ,$(BRANCH))),release),)
$(eval RELEASE_VERSION := $(word 2, $(subst /, ,$(BRANCH))))
endif
endif
$(if $(filter VERSION=%,$(MAKEFLAGS)), $(eval RELEASE_VERSION:=$(VERSION)) $(eval RELEASE_BRANCH := release/$(RELEASE_VERSION)))
$(if $(findstring $(firstword $(subst /, ,$(RELEASE_BRANCH))),release),,$(error Please provide a VERSION or a release BRANCH))
# target release-create: Create release VERSION from upstream/wip branch
.PHONY: release-create

View File

@ -49,6 +49,7 @@ GIT_AUTHOR_NAME ?= $(or $(shell git config user.name 2>/dev/null
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD 2>/dev/null)
GIT_COMMIT ?= $(shell git rev-parse $(BRANCH) 2>/dev/null)
GIT_REPOSITORY ?= $(if $(SUBREPO),$(shell awk -F ' = ' '$$1 ~ /^[[\s\t]]*remote$$/ {print $$2}' .gitrepo 2>/dev/null),$(shell git config --get remote.origin.url 2>/dev/null))
GIT_STATUS ?= $(shell git status -uno --porcelain 2>/dev/null |wc -l)
GIT_TAG ?= $(shell git tag -l --points-at $(BRANCH) 2>/dev/null)
GIT_UPSTREAM_REPOSITORY ?= $(if $(findstring ://,$(GIT_REPOSITORY)),$(call pop,$(call pop,$(GIT_REPOSITORY)))/,$(call pop,$(GIT_REPOSITORY),:):)$(GIT_UPSTREAM_USER)/$(lastword $(subst /, ,$(GIT_REPOSITORY)))
GIT_UPSTREAM_USER ?= $(lastword $(subst /, ,$(call pop,$(MYOS_REPOSITORY))))
@ -80,6 +81,7 @@ RECURSIVE ?= true
RELATIVE ?= $(if $(filter myos,$(MYOS)),./,../)
SHARED ?= $(RELATIVE)shared
SSH_DIR ?= ${HOME}/.ssh
STATUS ?= $(GIT_STATUS)
SUBREPO ?= $(if $(wildcard .gitrepo),$(notdir $(CURDIR)))
TAG ?= $(GIT_TAG)
UID ?= $(shell id -u 2>/dev/null)
@ -127,7 +129,7 @@ include $(wildcard $(ENV_FILE))
ifeq ($(HOST_SYSTEM),DARWIN)
ifneq ($(DOCKER),true)
SED_SUFFIX := '\'\''
SED_SUFFIX := ''
endif
endif
@ -227,7 +229,7 @@ endef
pop = $(patsubst %$(or $(2),/)$(lastword $(subst $(or $(2),/), ,$(1))),%,$(1))
# macro sed: Exec sed script 1 on file 2
sed = $(RUN) $(call exec,sed -i $(SED_SUFFIX) '$(1)' $(2))
sed = $(call env-exec,$(RUN) sed -i $(SED_SUFFIX) '$(1)' $(2))
# macro TIME: Print time elapsed since unixtime 1
TIME = awk '{printf "%02d:%02d:%02d\n",int($$1/3600),int(($$1%3600)/60),int($$1%60)}' \

View File

@ -6,7 +6,7 @@
subrepo-branch-delete: $(if $(DOCKER_RUN),myos-base) subrepo-check
ifneq ($(words $(BRANCH)),0)
$(call exec,[ $$(git ls-remote --heads $(REMOTE) $(BRANCH) 2>/dev/null |wc -l) -eq 1 ]) \
&& $(RUN) $(call exec,git push $(REMOTE) :$(BRANCH))
&& $(call exec,$(RUN) git push $(REMOTE) :$(BRANCH))
endif
# target subrepo-check: Define SUBREPO and REMOTE
@ -34,15 +34,15 @@ subrepo-git-diff: myos-base subrepo-check
# target subrepo-git-fetch: Fetch git remote
.PHONY: subrepo-git-fetch
subrepo-git-fetch: myos-base subrepo-check
$(RUN) $(call exec,git fetch --prune $(REMOTE))
$(call exec,$(RUN) git fetch --prune $(REMOTE))
# target subrepo-tag-create-%: Create tag TAG to reference branch REMOTE/%
.PHONY: subrepo-tag-create-%
subrepo-tag-create-%: myos-base subrepo-check subrepo-git-fetch
ifneq ($(words $(TAG)),0)
$(call exec,[ $$(git ls-remote --tags $(REMOTE) $(TAG) |wc -l) -eq 0 ]) \
|| $(RUN) $(call exec,git push $(REMOTE) :refs/tags/$(TAG))
$(RUN) $(call exec,git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG))
|| $(call exec,$(RUN) git push $(REMOTE) :refs/tags/$(TAG))
$(call exec,$(RUN) git push $(REMOTE) refs/remotes/subrepo/$(SUBREPO)/$*:refs/tags/$(TAG))
endif
# target subrepo-push: Push to subrepo
@ -64,12 +64,12 @@ endif
$(call INFO,subrepo $(SUBREPO) already up to date); \
else \
if [ $(DELETE) -eq 1 ]; then \
$(RUN) $(call exec,git push $(REMOTE) :$(BRANCH)); \
$(RUN) $(call exec,git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH)); \
$(call exec,$(RUN) git push $(REMOTE) :$(BRANCH)); \
$(call exec,$(RUN) git push $(REMOTE) refs/remotes/$(REMOTE)/master:refs/heads/$(BRANCH)); \
fi; \
$(RUN) $(call exec,git subrepo fetch $(SUBREPO) -b $(BRANCH)); \
$(RUN) $(call exec,git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS)); \
$(RUN) $(call exec,git subrepo clean $(SUBREPO)); \
$(call exec,$(RUN) git subrepo fetch $(SUBREPO) -b $(BRANCH)); \
$(call exec,$(RUN) git subrepo push $(SUBREPO) -b $(BRANCH) $(UPDATE_SUBREPO_OPTIONS)); \
$(call exec,$(RUN) git subrepo clean $(SUBREPO)); \
fi
# target subrepos-branch-delete: Fire APPS target
@ -83,7 +83,7 @@ subrepos-tag-create-%: $(APPS) ;
# target subrepos-update: Fire APPS target and push updates to upstream
.PHONY: subrepos-update
subrepos-update: myos-base git-stash $(APPS) git-unstash ## Update subrepos
$(RUN) $(call exec,git push upstream $(BRANCH))
$(call exec,$(RUN) git push upstream $(BRANCH))
# target subrepo-update-%: Call subrepo-update target in folder %
.PHONY: subrepo-update-%