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.

179 lines
5.5KB

  1. ###
  2. # Creates and publishes a new release
  3. #
  4. # Defaults to building version 'v1.0.0'. If you want to create and publish
  5. # another release, pass the 'version' environment variable.
  6. #
  7. # Requirements:
  8. # - Target 'sign'
  9. # Requires OpenSSL and a RSA key to sign the release archive at
  10. # '~/.nextcloud/certificates/$(app_name).key'
  11. # - Target 'verify'
  12. # Requires OpenSSL and a RSA public key to verify the release archive at
  13. # '~/.nextcloud/certificates/$(app_name).pub'
  14. # - Targets 'github-release' and 'github-upload'
  15. # Requires https://github.com/aktau/github-release and a 'github-token'
  16. # file at '~/.nextcloud/github-token' with an GitHub API token, e.g.
  17. # deadbeefc001cafebaadf00dabad1deadeadcode
  18. # - Target 'publish'
  19. # Requires a 'curlrc' file at '~/.nextcloud/curlrc' with an appropiate
  20. # Authentication header for the Nextcloud App Store, e.g.
  21. # header = "Authorization: Token [NEXTCLOUD_API_TOKEN]"
  22. #
  23. version?=v1.0.0
  24. prerelease?=false
  25. nocheck?=false
  26. verify?=$(build_dir)/$(archive)
  27. app_name=cms_pico
  28. app_title=Pico CMS for Nextcloud
  29. build_dir=$(CURDIR)/build
  30. cert_dir=$(HOME)/.nextcloud/certificates
  31. curlrc=$(HOME)/.nextcloud/curlrc
  32. archive=$(app_name)-$(version).tar.gz
  33. export=$(app_name)-export.tar.gz
  34. signature=$(app_name)-$(version).tar.gz.sig
  35. github_owner=nextcloud
  36. github_repo=cms_pico
  37. github_branch=master
  38. github_token:=$(shell cat "$(HOME)/.nextcloud/github-token")
  39. download_url=https://github.com/$(github_owner)/$(github_repo)/releases/download/$(version)/$(archive)
  40. publish_url=https://apps.nextcloud.com/api/v1/apps/releases
  41. appinfo=./appinfo/info.xml
  42. appinfo_version:=$(shell sed -ne 's/^.*<version>\(.*\)<\/version>.*$$/\1/p' "$(CURDIR)/$(appinfo)")
  43. git_version:=$(shell git describe --exact-match --tags HEAD 2> /dev/null)
  44. all: build
  45. clean:
  46. rm -rf "$(build_dir)"
  47. clean-build:
  48. rm -rf "$(build_dir)/$(app_name)"
  49. rm -f "$(build_dir)/$(archive)"
  50. clean-export:
  51. rm -f "$(build_dir)/$(export)"
  52. check:
  53. @:
  54. ifneq (v$(appinfo_version),$(version))
  55. $(error Version mismatch: Building $(version), but $(appinfo) indicates v$(appinfo_version))
  56. endif
  57. ifeq ($(git_version),)
  58. $(error Version mismatch: Building $(version), but no Git tag found)
  59. endif
  60. ifneq ($(git_version),$(version))
  61. $(error Version mismatch: Building $(version), but Git tag indicates $(git_version))
  62. endif
  63. lazy-check:
  64. @:
  65. ifeq ($(or $(filter v$(appinfo_version) latest,$(version)), $(filter true,$(nocheck))),)
  66. $(error Version mismatch: Building $(version), but $(appinfo) indicates v$(appinfo_version))
  67. endif
  68. check-git:
  69. GIT_STATUS="$$(git status --porcelain)" && [ -z "$$GIT_STATUS" ]
  70. check-composer:
  71. composer update --no-suggest --no-dev --dry-run 2>&1 \
  72. | grep --quiet '^Nothing to install or update$$'
  73. composer:
  74. composer install --no-suggest --no-dev --prefer-dist --optimize-autoloader
  75. build: lazy-check clean-build composer
  76. mkdir -p "$(build_dir)"
  77. rsync -a \
  78. --exclude="/.github" \
  79. --exclude="/.idea" \
  80. --exclude="/.tx" \
  81. --exclude="/appdata/plugins/.gitignore" \
  82. --exclude="/appdata/themes/.gitignore" \
  83. --exclude="/appdata_public/*" \
  84. --exclude="/build" \
  85. --exclude="/l10n/.gitignore" \
  86. --exclude="/nextcloud" \
  87. --exclude="/screenshots" \
  88. --exclude="/tests" \
  89. --exclude="/vendor/picocms/pico/index.php" \
  90. --exclude="/vendor/picocms/pico/index.php.dist" \
  91. --exclude="/.gitattributes" \
  92. --exclude="/.gitignore" \
  93. --exclude="/.phpcs.xml" \
  94. --exclude="/.scrutinizer.yml" \
  95. --exclude="/composer.json" \
  96. --exclude="/composer.lock" \
  97. --exclude="/Makefile" \
  98. --exclude="/*.phar" \
  99. --exclude=".git" \
  100. ./ "$(build_dir)/$(app_name)/"
  101. tar cfz "$(build_dir)/$(archive)" \
  102. -C "$(build_dir)" "$(app_name)"
  103. export: clean-export
  104. mkdir -p "$(build_dir)"
  105. git archive --prefix "$(app_name)/" -o "$(build_dir)/$(export)" HEAD
  106. sign: build
  107. openssl dgst -sha512 \
  108. -sign "$(cert_dir)/$(app_name).key" \
  109. "$(build_dir)/$(archive)" \
  110. | openssl base64 -A > "$(build_dir)/$(signature)"
  111. verify:
  112. openssl base64 -A -d \
  113. < "$(verify).sig" \
  114. | openssl dgst -sha512 \
  115. -verify "$(cert_dir)/$(app_name).pub" \
  116. -signature /dev/stdin \
  117. "$(verify)"
  118. github-release: export GITHUB_TOKEN=$(github_token)
  119. github-release: check
  120. github-release release \
  121. --user "$(github_owner)" \
  122. --repo "$(github_repo)" \
  123. --tag "$(version)" \
  124. --target "$(github_branch)" \
  125. --name "$(version)" \
  126. --description "$(app_title) $(version)" \
  127. $(if $(filter true,$(prerelease)),--pre-release,)
  128. github-upload: export GITHUB_TOKEN=$(github_token)
  129. github-upload: check check-git check-composer build github-release
  130. github-release upload \
  131. --user "$(github_owner)" \
  132. --repo "$(github_repo)" \
  133. --tag "$(version)" \
  134. --name "$(archive)" \
  135. --file "$(build_dir)/$(archive)"
  136. publish: check check-git check-composer sign github-upload
  137. php -r 'echo json_encode([ "download" => $$_SERVER["argv"][1], "signature" => file_get_contents($$_SERVER["argv"][2]), "nightly" => !!$$_SERVER["argv"][3] ]);' \
  138. "$(download_url)" "$(build_dir)/$(signature)" "$(if $(filter true,$(prerelease)),1,0)" \
  139. | curl -K "$(curlrc)" \
  140. -H "Content-Type: application/json" -d "@-" \
  141. -X POST "$(publish_url)"
  142. github-release-dev: prerelease=true
  143. github-release-dev: github-release
  144. github-upload-dev: prerelease=true
  145. github-upload-dev: github-upload
  146. publish-dev: prerelease=true
  147. publish-dev: publish
  148. .PHONY: all \
  149. clean clean-build clean-export \
  150. check lazy-check \
  151. check-git check-composer \
  152. composer build export \
  153. sign verify \
  154. github-release github-release-dev \
  155. github-upload github-upload-dev \
  156. publish publish-dev