You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

1 year ago
  1. #版本檔案
  2. LAST_APP_VERSION_FILE=APP_VERSION
  3. BUILD_VERSION_FILE=BUILD
  4. #版本變數
  5. VERSION:=$(shell cat ../VERSION)
  6. #打包起始版本 -1
  7. INIT_BUILD_VERSION=999
  8. BUILD_VERSION=$(shell echo $(shell cat $(BUILD_VERSION_FILE))+1 | bc)
  9. export APP_VERSION=$(shell cat $(LAST_APP_VERSION_FILE))
  10. #Git
  11. GIT_CMD=git
  12. GIT_BRANCH=$(GIT_CMD) branch
  13. GIT_ADD=$(GIT_CMD) add
  14. GIT_COMMIT=$(GIT_CMD) commit
  15. GIT_PUSH=$(GIT_CMD) push -f
  16. GIT_CURRENT_BRANCH=$$branch
  17. GIT_TAG=$(GIT_CMD) tag
  18. # Pure targets.
  19. #.PHONY: all
  20. all: check_version_file_is_exist check_version add_version write_tag_to_file
  21. #初始化 build version 檔案
  22. init_build_version:
  23. touch $(BUILD_VERSION_FILE)
  24. echo $(INIT_BUILD_VERSION) > $(BUILD_VERSION_FILE)
  25. echo "BUILD_VERSION = " BUILD_VERSION
  26. #初始化 app version
  27. init_app_version:
  28. touch $(LAST_APP_VERSION_FILE)
  29. echo $(VERSION) > $(LAST_APP_VERSION_FILE)
  30. #檢查版本檔案是否存在
  31. check_version_file_is_exist:
  32. ifeq "$(wildcard $(BUILD_VERSION_FILE))" ""
  33. @make init_build_version
  34. endif
  35. ifeq "$(wildcard $(LAST_APP_VERSION_FILE))" ""
  36. @make init_app_version
  37. endif
  38. #檢查版本
  39. check_version:
  40. @if [ $(shell cat $(LAST_APP_VERSION_FILE)) != $(VERSION) ]; then\
  41. make init_app_version;\
  42. make init_build_version;\
  43. fi
  44. add_version:
  45. echo $(BUILD_VERSION) > $(BUILD_VERSION_FILE)
  46. commit_record:
  47. $(GIT_ADD) $(LAST_APP_VERSION_FILE)
  48. $(GIT_ADD) $(BUILD_VERSION_FILE)
  49. $(GIT_COMMIT) -m "auto increment build version $(shell cat BUILD) [CI SKIP]"
  50. $(GIT_PUSH) origin HEAD:"$(GIT_CURRENT_BRANCH)"
  51. add_tag:
  52. $(GIT_TAG) -a v$(shell cat APP_VERSION).$(shell cat BUILD) -m "auto increment build version v$(shell cat APP_VERSION).$(shell cat BUILD)"
  53. $(GIT_PUSH) origin v$(shell cat APP_VERSION).$(shell cat BUILD)
  54. write_tag_to_file:
  55. echo "$(shell cat APP_VERSION).$(shell cat BUILD)" > ../.tags