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.

548 lines
20 KiB

9 years ago
9 years ago
Sign merges, CRUD, Wiki and Repository initialisation with gpg key (#7631) This PR fixes #7598 by providing a configurable way of signing commits across the Gitea instance. Per repository configurability and import/generation of trusted secure keys is not provided by this PR - from a security PoV that's probably impossible to do properly. Similarly web-signing, that is asking the user to sign something, is not implemented - this could be done at a later stage however. ## Features - [x] If commit.gpgsign is set in .gitconfig sign commits and files created through repofiles. (merges should already have been signed.) - [x] Verify commits signed with the default gpg as valid - [x] Signer, Committer and Author can all be different - [x] Allow signer to be arbitrarily different - We still require the key to have an activated email on Gitea. A more complete implementation would be to use a keyserver and mark external-or-unactivated with an "unknown" trust level icon. - [x] Add a signing-key.gpg endpoint to get the default gpg pub key if available - Rather than add a fake web-flow user I've added this as an endpoint on /api/v1/signing-key.gpg - [x] Try to match the default key with a user on gitea - this is done at verification time - [x] Make things configurable? - app.ini configuration done - [x] when checking commits are signed need to check if they're actually verifiable too - [x] Add documentation I have decided that adjusting the docker to create a default gpg key is not the correct thing to do and therefore have not implemented this.
5 years ago
9 years ago
9 years ago
  1. DIST := dist
  2. IMPORT := code.gitea.io/gitea
  3. export GO111MODULE=off
  4. GO ?= go
  5. SED_INPLACE := sed -i
  6. SHASUM ?= shasum -a 256
  7. export PATH := $($(GO) env GOPATH)/bin:$(PATH)
  8. ifeq ($(OS), Windows_NT)
  9. EXECUTABLE ?= gitea.exe
  10. else
  11. EXECUTABLE ?= gitea
  12. UNAME_S := $(shell uname -s)
  13. ifeq ($(UNAME_S),Darwin)
  14. SED_INPLACE := sed -i ''
  15. endif
  16. ifeq ($(UNAME_S),FreeBSD)
  17. SED_INPLACE := sed -i ''
  18. endif
  19. endif
  20. GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
  21. GOFMT ?= gofmt -s
  22. GOFLAGS := -v
  23. EXTRA_GOFLAGS ?=
  24. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  25. ifneq ($(DRONE_TAG),)
  26. VERSION ?= $(subst v,,$(DRONE_TAG))
  27. GITEA_VERSION ?= $(VERSION)
  28. else
  29. ifneq ($(DRONE_BRANCH),)
  30. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  31. else
  32. VERSION ?= master
  33. endif
  34. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  35. endif
  36. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  37. PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)))
  38. GO_SOURCES ?= $(shell find . -name "*.go" -type f)
  39. JS_SOURCES ?= $(shell find web_src/js web_src/css -type f)
  40. CSS_SOURCES ?= $(shell find web_src/less -type f)
  41. JS_DEST := public/js/index.js
  42. CSS_DEST := public/css/index.css
  43. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  44. JS_DEST_DIR := public/js
  45. CSS_DEST_DIR := public/css
  46. FOMANTIC_DEST_DIR := public/fomantic
  47. TAGS ?=
  48. TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp')
  49. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  50. SWAGGER := GO111MODULE=on $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  51. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  52. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  53. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  54. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  55. TEST_MYSQL_HOST ?= mysql:3306
  56. TEST_MYSQL_DBNAME ?= testgitea
  57. TEST_MYSQL_USERNAME ?= root
  58. TEST_MYSQL_PASSWORD ?=
  59. TEST_MYSQL8_HOST ?= mysql8:3306
  60. TEST_MYSQL8_DBNAME ?= testgitea
  61. TEST_MYSQL8_USERNAME ?= root
  62. TEST_MYSQL8_PASSWORD ?=
  63. TEST_PGSQL_HOST ?= pgsql:5432
  64. TEST_PGSQL_DBNAME ?= testgitea
  65. TEST_PGSQL_USERNAME ?= postgres
  66. TEST_PGSQL_PASSWORD ?= postgres
  67. TEST_PGSQL_SCHEMA ?= gtestschema
  68. TEST_MSSQL_HOST ?= mssql:1433
  69. TEST_MSSQL_DBNAME ?= gitea
  70. TEST_MSSQL_USERNAME ?= sa
  71. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  72. # $(call strip-suffix,filename)
  73. strip-suffix = $(firstword $(subst ., ,$(1)))
  74. .PHONY: all
  75. all: build
  76. include docker/Makefile
  77. .PHONY: help
  78. help:
  79. @echo "Make Routines:"
  80. @echo " - \"\" equivalent to \"build\""
  81. @echo " - build creates the entire project"
  82. @echo " - clean delete integration files and build files but not css and js files"
  83. @echo " - clean-all delete all generated files (integration test, build, css and js files)"
  84. @echo " - css rebuild only css files"
  85. @echo " - js rebuild only js files"
  86. @echo " - generate run \"make css js\" and \"go generate\""
  87. @echo " - fmt format the code"
  88. @echo " - generate-swagger generate the swagger spec from code comments"
  89. @echo " - swagger-validate check if the swagger spec is valide"
  90. @echo " - revive run code linter revive"
  91. @echo " - misspell check if a word is written wrong"
  92. @echo " - vet examines Go source code and reports suspicious constructs"
  93. @echo " - test run unit test"
  94. @echo " - test-sqlite run integration test for sqlite"
  95. .PHONY: go-check
  96. go-check:
  97. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?\s' | tr '.' ' ');))
  98. @if [ "$(GO_VERSION)" -lt "001011000" ]; then \
  99. echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
  100. exit 1; \
  101. fi
  102. .PHONY: git-check
  103. git-check:
  104. @if git lfs >/dev/null 2>&1 ; then : ; else \
  105. echo "Gitea requires git with lfs support to run tests." ; \
  106. exit 1; \
  107. fi
  108. .PHONY: node-check
  109. node-check:
  110. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?' | tr '.' ' ');))
  111. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  112. @if [ "$(NODE_VERSION)" -lt "010000000" -o "$(NPM_MISSING)" = "1" ]; then \
  113. echo "Gitea requires Node.js 10.0.0 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  114. exit 1; \
  115. fi
  116. .PHONY: clean-all
  117. clean-all: clean
  118. rm -rf $(JS_DEST_DIR) $(CSS_DEST_DIR) $(FOMANTIC_DEST_DIR)
  119. .PHONY: clean
  120. clean:
  121. $(GO) clean -i ./...
  122. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) \
  123. integrations*.test \
  124. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  125. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  126. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  127. .PHONY: fmt
  128. fmt:
  129. $(GOFMT) -w $(GOFILES)
  130. .PHONY: vet
  131. vet:
  132. $(GO) vet $(PACKAGES)
  133. .PHONY: generate
  134. generate: js css
  135. GO111MODULE=on $(GO) generate -mod=vendor $(PACKAGES)
  136. .PHONY: generate-swagger
  137. generate-swagger:
  138. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  139. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  140. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  141. .PHONY: swagger-check
  142. swagger-check: generate-swagger
  143. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  144. if [ -n "$$diff" ]; then \
  145. echo "Please run 'make generate-swagger' and commit the result:"; \
  146. echo "$${diff}"; \
  147. exit 1; \
  148. fi;
  149. .PHONY: swagger-validate
  150. swagger-validate:
  151. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  152. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  153. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  154. .PHONY: errcheck
  155. errcheck:
  156. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  157. $(GO) get -u github.com/kisielk/errcheck; \
  158. fi
  159. errcheck $(PACKAGES)
  160. .PHONY: revive
  161. revive:
  162. @hash revive > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  163. $(GO) get -u github.com/mgechev/revive; \
  164. fi
  165. revive -config .revive.toml -exclude=./vendor/... ./... || exit 1
  166. .PHONY: misspell-check
  167. misspell-check:
  168. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  169. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  170. fi
  171. misspell -error -i unknwon,destory $(GOFILES)
  172. .PHONY: misspell
  173. misspell:
  174. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  175. $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  176. fi
  177. misspell -w -i unknwon $(GOFILES)
  178. .PHONY: fmt-check
  179. fmt-check:
  180. # get all go files and run go fmt on them
  181. @diff=$$($(GOFMT) -d $(GOFILES)); \
  182. if [ -n "$$diff" ]; then \
  183. echo "Please run 'make fmt' and commit the result:"; \
  184. echo "$${diff}"; \
  185. exit 1; \
  186. fi;
  187. .PHONY: test
  188. test:
  189. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' $(PACKAGES)
  190. .PHONY: test\#%
  191. test\#%:
  192. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $* $(PACKAGES)
  193. .PHONY: coverage
  194. coverage:
  195. @hash gocovmerge > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  196. $(GO) get -u github.com/wadey/gocovmerge; \
  197. fi
  198. gocovmerge integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all;\
  199. .PHONY: unit-test-coverage
  200. unit-test-coverage:
  201. GO111MODULE=on $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  202. .PHONY: vendor
  203. vendor:
  204. GO111MODULE=on $(GO) mod tidy && GO111MODULE=on $(GO) mod vendor
  205. .PHONY: test-vendor
  206. test-vendor: vendor
  207. @diff=$$(git diff vendor/); \
  208. if [ -n "$$diff" ]; then \
  209. echo "Please run 'make vendor' and commit the result:"; \
  210. echo "$${diff}"; \
  211. exit 1; \
  212. fi;
  213. .PHONY: test-sqlite
  214. test-sqlite: integrations.sqlite.test
  215. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  216. .PHONY: test-sqlite\#%
  217. test-sqlite\#%: integrations.sqlite.test
  218. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $*
  219. .PHONY: test-sqlite-migration
  220. test-sqlite-migration: migrations.sqlite.test
  221. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  222. generate-ini-mysql:
  223. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  224. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  225. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  226. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  227. integrations/mysql.ini.tmpl > integrations/mysql.ini
  228. .PHONY: test-mysql
  229. test-mysql: integrations.mysql.test generate-ini-mysql
  230. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  231. .PHONY: test-mysql\#%
  232. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  233. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $*
  234. .PHONY: test-mysql-migration
  235. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  236. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  237. generate-ini-mysql8:
  238. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  239. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  240. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  241. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  242. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  243. .PHONY: test-mysql8
  244. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  245. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  246. .PHONY: test-mysql8\#%
  247. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  248. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $*
  249. .PHONY: test-mysql8-migration
  250. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  251. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  252. generate-ini-pgsql:
  253. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  254. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  255. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  256. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  257. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  258. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  259. .PHONY: test-pgsql
  260. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  261. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  262. .PHONY: test-pgsql\#%
  263. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  264. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $*
  265. .PHONY: test-pgsql-migration
  266. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  267. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  268. generate-ini-mssql:
  269. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  270. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  271. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  272. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  273. integrations/mssql.ini.tmpl > integrations/mssql.ini
  274. .PHONY: test-mssql
  275. test-mssql: integrations.mssql.test generate-ini-mssql
  276. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  277. .PHONY: test-mssql\#%
  278. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  279. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $*
  280. .PHONY: test-mssql-migration
  281. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  282. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  283. .PHONY: bench-sqlite
  284. bench-sqlite: integrations.sqlite.test
  285. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  286. .PHONY: bench-mysql
  287. bench-mysql: integrations.mysql.test generate-ini-mysql
  288. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  289. .PHONY: bench-mssql
  290. bench-mssql: integrations.mssql.test generate-ini-mssql
  291. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  292. .PHONY: bench-pgsql
  293. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  294. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  295. .PHONY: integration-test-coverage
  296. integration-test-coverage: integrations.cover.test generate-ini-mysql
  297. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  298. integrations.mysql.test: git-check $(GO_SOURCES)
  299. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  300. integrations.mysql8.test: git-check $(GO_SOURCES)
  301. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  302. integrations.pgsql.test: git-check $(GO_SOURCES)
  303. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  304. integrations.mssql.test: git-check $(GO_SOURCES)
  305. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  306. integrations.sqlite.test: git-check $(GO_SOURCES)
  307. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  308. integrations.cover.test: git-check $(GO_SOURCES)
  309. GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
  310. .PHONY: migrations.mysql.test
  311. migrations.mysql.test: $(GO_SOURCES)
  312. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  313. .PHONY: migrations.mysql8.test
  314. migrations.mysql8.test: $(GO_SOURCES)
  315. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  316. .PHONY: migrations.pgsql.test
  317. migrations.pgsql.test: $(GO_SOURCES)
  318. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  319. .PHONY: migrations.mssql.test
  320. migrations.mssql.test: $(GO_SOURCES)
  321. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  322. .PHONY: migrations.sqlite.test
  323. migrations.sqlite.test: $(GO_SOURCES)
  324. $(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  325. .PHONY: check
  326. check: test
  327. .PHONY: install
  328. install: $(wildcard *.go)
  329. $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  330. .PHONY: build
  331. build: go-check generate $(EXECUTABLE)
  332. $(EXECUTABLE): $(GO_SOURCES)
  333. GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  334. .PHONY: release
  335. release: generate release-dirs release-windows release-linux release-darwin release-copy release-compress release-check
  336. .PHONY: release-dirs
  337. release-dirs:
  338. mkdir -p $(DIST)/binaries $(DIST)/release
  339. .PHONY: release-windows
  340. release-windows:
  341. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  342. $(GO) get -u src.techknowlogick.com/xgo; \
  343. fi
  344. xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  345. ifeq ($(CI),drone)
  346. cp /build/* $(DIST)/binaries
  347. endif
  348. .PHONY: release-linux
  349. release-linux:
  350. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  351. $(GO) get -u src.techknowlogick.com/xgo; \
  352. fi
  353. xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64,linux/mips64le,linux/mips,linux/mipsle' -out gitea-$(VERSION) .
  354. ifeq ($(CI),drone)
  355. cp /build/* $(DIST)/binaries
  356. endif
  357. .PHONY: release-darwin
  358. release-darwin:
  359. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  360. $(GO) get -u src.techknowlogick.com/xgo; \
  361. fi
  362. xgo -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  363. ifeq ($(CI),drone)
  364. cp /build/* $(DIST)/binaries
  365. endif
  366. .PHONY: release-copy
  367. release-copy:
  368. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  369. .PHONY: release-check
  370. release-check:
  371. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  372. .PHONY: release-compress
  373. release-compress:
  374. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  375. $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  376. fi
  377. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  378. node_modules: package-lock.json
  379. npm install --no-save
  380. .PHONY: npm-update
  381. npm-update: node-check node_modules
  382. npx updates -cu
  383. rm -rf node_modules package-lock.json
  384. npm install --package-lock
  385. .PHONY: js
  386. js: node-check fomantic $(JS_DEST)
  387. $(JS_DEST): node_modules $(JS_SOURCES)
  388. npx eslint web_src/js webpack.config.js
  389. npx webpack
  390. .PHONY: fomantic
  391. fomantic: node-check $(FOMANTIC_DEST_DIR)
  392. $(FOMANTIC_DEST_DIR): node_modules semantic.json web_src/fomantic/theme.config.less
  393. cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
  394. npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  395. .PHONY: css
  396. css: node-check fomantic $(CSS_DEST)
  397. $(CSS_DEST): node_modules $(CSS_SOURCES)
  398. npx stylelint web_src/less
  399. npx lessc web_src/less/index.less public/css/index.css
  400. $(foreach file, $(filter-out web_src/less/themes/_base.less, $(wildcard web_src/less/themes/*)),npx lessc web_src/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)
  401. npx postcss --use autoprefixer --use cssnano --no-map --replace public/css/*
  402. .PHONY: update-translations
  403. update-translations:
  404. mkdir -p ./translations
  405. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  406. rm ./translations/gitea.zip
  407. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  408. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  409. mv ./translations/*.ini ./options/locale/
  410. rmdir ./translations
  411. .PHONY: generate-images
  412. generate-images:
  413. mkdir -p $(TMPDIR)/images
  414. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  415. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  416. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  417. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  418. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  419. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  420. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  421. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  422. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  423. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  424. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  425. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  426. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  427. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  428. zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  429. zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  430. zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  431. zopflipng -m -y $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  432. rm -f $(TMPDIR)/images/*-*.png
  433. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  434. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  435. $(PWD)/public/img/favicon.ico
  436. rm -rf $(TMPDIR)/images
  437. $(foreach file, $(shell find public/img -type f -name '*.png'),zopflipng -m -y $(file) $(file);)
  438. .PHONY: pr
  439. pr:
  440. $(GO) run contrib/pr/checkout.go $(PR)
  441. .PHONY: golangci-lint
  442. golangci-lint:
  443. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  444. export BINARY="golangci-lint"; \
  445. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.20.0; \
  446. fi
  447. golangci-lint run --timeout 5m