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.

690 lines
26 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
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. ifeq ($(USE_REPO_TEST_DIR),1)
  2. # This rule replaces the whole Makefile when we're trying to use /tmp repository temporary files
  3. location = $(CURDIR)/$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
  4. self := $(location)
  5. %:
  6. @tmpdir=`mktemp --tmpdir -d` ; \
  7. echo Using temporary directory $$tmpdir for test repositories ; \
  8. USE_REPO_TEST_DIR= $(MAKE) -f $(self) --no-print-directory REPO_TEST_DIR=$$tmpdir/ $@ ; \
  9. STATUS=$$? ; rm -r "$$tmpdir" ; exit $$STATUS
  10. else
  11. # This is the "normal" part of the Makefile
  12. DIST := dist
  13. DIST_DIRS := $(DIST)/binaries $(DIST)/release
  14. IMPORT := code.gitea.io/gitea
  15. export GO111MODULE=on
  16. GO ?= go
  17. SED_INPLACE := sed -i
  18. SHASUM ?= shasum -a 256
  19. HAS_GO = $(shell hash $(GO) > /dev/null 2>&1 && echo "GO" || echo "NOGO" )
  20. COMMA := ,
  21. XGO_VERSION := go-1.14.x
  22. MIN_GO_VERSION := 001012000
  23. MIN_NODE_VERSION := 010013000
  24. ifeq ($(HAS_GO), GO)
  25. GOPATH ?= $(shell $(GO) env GOPATH)
  26. export PATH := $(GOPATH)/bin:$(PATH)
  27. CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER=32766
  28. CGO_CFLAGS ?= $(shell $(GO) env CGO_CFLAGS) $(CGO_EXTRA_CFLAGS)
  29. endif
  30. ifeq ($(OS), Windows_NT)
  31. EXECUTABLE ?= gitea.exe
  32. else
  33. EXECUTABLE ?= gitea
  34. UNAME_S := $(shell uname -s)
  35. ifeq ($(UNAME_S),Darwin)
  36. SED_INPLACE := sed -i ''
  37. endif
  38. ifeq ($(UNAME_S),FreeBSD)
  39. SED_INPLACE := sed -i ''
  40. endif
  41. endif
  42. GOFMT ?= gofmt -s
  43. GOFLAGS := -v
  44. EXTRA_GOFLAGS ?=
  45. MAKE_VERSION := $(shell $(MAKE) -v | head -n 1)
  46. MAKE_EVIDENCE_DIR := .make_evidence
  47. ifneq ($(RACE_ENABLED),)
  48. GOTESTFLAGS ?= -race
  49. endif
  50. STORED_VERSION_FILE := VERSION
  51. ifneq ($(DRONE_TAG),)
  52. VERSION ?= $(subst v,,$(DRONE_TAG))
  53. GITEA_VERSION ?= $(VERSION)
  54. else
  55. ifneq ($(DRONE_BRANCH),)
  56. VERSION ?= $(subst release/v,,$(DRONE_BRANCH))
  57. else
  58. VERSION ?= master
  59. endif
  60. STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
  61. ifneq ($(STORED_VERSION),)
  62. GITEA_VERSION ?= $(STORED_VERSION)
  63. else
  64. GITEA_VERSION ?= $(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')
  65. endif
  66. endif
  67. LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
  68. GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell $(GO) list -mod=vendor ./... | grep -v /vendor/)))
  69. FOMANTIC_CONFIGS := semantic.json web_src/fomantic/theme.config.less web_src/fomantic/_site/globals/site.variables
  70. FOMANTIC_DEST := web_src/fomantic/build/semantic.js web_src/fomantic/build/semantic.css
  71. FOMANTIC_DEST_DIR := web_src/fomantic/build
  72. WEBPACK_SOURCES := $(shell find web_src/js web_src/less -type f) $(FOMANTIC_DEST)
  73. WEBPACK_CONFIGS := webpack.config.js
  74. WEBPACK_DEST := public/js/index.js public/css/index.css
  75. WEBPACK_DEST_ENTRIES := public/js public/css public/fonts public/serviceworker.js
  76. BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
  77. BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
  78. SVG_DEST_DIR := public/img/svg
  79. TAGS ?=
  80. TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
  81. TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
  82. GO_DIRS := cmd integrations models modules routers build services vendor
  83. GO_SOURCES := $(wildcard *.go)
  84. GO_SOURCES += $(shell find $(GO_DIRS) -type f -name "*.go" -not -path modules/options/bindata.go -not -path modules/public/bindata.go -not -path modules/templates/bindata.go)
  85. ifeq ($(filter $(TAGS_SPLIT),bindata),bindata)
  86. GO_SOURCES += $(BINDATA_DEST)
  87. endif
  88. GO_SOURCES_OWN := $(filter-out vendor/% %/bindata.go, $(GO_SOURCES))
  89. #To update swagger use: GO111MODULE=on go get -u github.com/go-swagger/go-swagger/cmd/swagger@v0.20.1
  90. SWAGGER := $(GO) run -mod=vendor github.com/go-swagger/go-swagger/cmd/swagger
  91. SWAGGER_SPEC := templates/swagger/v1_json.tmpl
  92. SWAGGER_SPEC_S_TMPL := s|"basePath": *"/api/v1"|"basePath": "{{AppSubUrl}}/api/v1"|g
  93. SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl}}/api/v1"|"basePath": "/api/v1"|g
  94. SWAGGER_NEWLINE_COMMAND := -e '$$a\'
  95. TEST_MYSQL_HOST ?= mysql:3306
  96. TEST_MYSQL_DBNAME ?= testgitea
  97. TEST_MYSQL_USERNAME ?= root
  98. TEST_MYSQL_PASSWORD ?=
  99. TEST_MYSQL8_HOST ?= mysql8:3306
  100. TEST_MYSQL8_DBNAME ?= testgitea
  101. TEST_MYSQL8_USERNAME ?= root
  102. TEST_MYSQL8_PASSWORD ?=
  103. TEST_PGSQL_HOST ?= pgsql:5432
  104. TEST_PGSQL_DBNAME ?= testgitea
  105. TEST_PGSQL_USERNAME ?= postgres
  106. TEST_PGSQL_PASSWORD ?= postgres
  107. TEST_PGSQL_SCHEMA ?= gtestschema
  108. TEST_MSSQL_HOST ?= mssql:1433
  109. TEST_MSSQL_DBNAME ?= gitea
  110. TEST_MSSQL_USERNAME ?= sa
  111. TEST_MSSQL_PASSWORD ?= MwantsaSecurePassword1
  112. .PHONY: all
  113. all: build
  114. include docker/Makefile
  115. .PHONY: help
  116. help:
  117. @echo "Make Routines:"
  118. @echo " - \"\" equivalent to \"build\""
  119. @echo " - build build everything"
  120. @echo " - frontend build frontend files"
  121. @echo " - backend build backend files"
  122. @echo " - clean delete backend and integration files"
  123. @echo " - clean-all delete backend, frontend and integration files"
  124. @echo " - lint lint everything"
  125. @echo " - lint-frontend lint frontend files"
  126. @echo " - lint-backend lint backend files"
  127. @echo " - watch-frontend watch frontend files and continuously rebuild"
  128. @echo " - webpack build webpack files"
  129. @echo " - svg build svg files"
  130. @echo " - fomantic build fomantic files"
  131. @echo " - generate run \"go generate\""
  132. @echo " - fmt format the Go code"
  133. @echo " - generate-swagger generate the swagger spec from code comments"
  134. @echo " - swagger-validate check if the swagger spec is valid"
  135. @echo " - golangci-lint run golangci-lint linter"
  136. @echo " - revive run revive linter"
  137. @echo " - misspell check for misspellings"
  138. @echo " - vet examines Go source code and reports suspicious constructs"
  139. @echo " - test[\#TestSpecificName] run unit test"
  140. @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
  141. @echo " - pr#<index> build and start gitea from a PR with integration test data loaded"
  142. .PHONY: go-check
  143. go-check:
  144. $(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.[0-9.]+' | tr '.' ' ');))
  145. @if [ "$(GO_VERSION)" -lt "$(MIN_GO_VERSION)" ]; then \
  146. echo "Gitea requires Go 1.12 or greater to build. You can get it at https://golang.org/dl/"; \
  147. exit 1; \
  148. fi
  149. .PHONY: git-check
  150. git-check:
  151. @if git lfs >/dev/null 2>&1 ; then : ; else \
  152. echo "Gitea requires git with lfs support to run tests." ; \
  153. exit 1; \
  154. fi
  155. .PHONY: node-check
  156. node-check:
  157. $(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | cut -c2- | tr '.' ' ');))
  158. $(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
  159. @if [ "$(NODE_VERSION)" -lt "$(MIN_NODE_VERSION)" -o "$(NPM_MISSING)" = "1" ]; then \
  160. echo "Gitea requires Node.js 10 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
  161. exit 1; \
  162. fi
  163. .PHONY: clean-all
  164. clean-all: clean
  165. rm -rf $(WEBPACK_DEST_ENTRIES) $(FOMANTIC_DEST_DIR)
  166. .PHONY: clean
  167. clean:
  168. $(GO) clean -i ./...
  169. rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) $(BINDATA_HASH) \
  170. integrations*.test \
  171. integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
  172. integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
  173. integrations/indexers-mssql integrations/mysql.ini integrations/mysql8.ini integrations/pgsql.ini integrations/mssql.ini
  174. .PHONY: fmt
  175. fmt:
  176. $(GOFMT) -w $(GO_SOURCES_OWN)
  177. .PHONY: vet
  178. vet:
  179. # Default vet
  180. $(GO) vet $(GO_PACKAGES)
  181. # Custom vet
  182. $(GO) build -mod=vendor gitea.com/jolheiser/gitea-vet
  183. $(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
  184. .PHONY: $(TAGS_EVIDENCE)
  185. $(TAGS_EVIDENCE):
  186. @mkdir -p $(MAKE_EVIDENCE_DIR)
  187. @echo "$(TAGS)" > $(TAGS_EVIDENCE)
  188. ifneq "$(TAGS)" "$(shell cat $(TAGS_EVIDENCE) 2>/dev/null)"
  189. TAGS_PREREQ := $(TAGS_EVIDENCE)
  190. endif
  191. .PHONY: generate-swagger
  192. generate-swagger:
  193. $(SWAGGER) generate spec -o './$(SWAGGER_SPEC)'
  194. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  195. $(SED_INPLACE) $(SWAGGER_NEWLINE_COMMAND) './$(SWAGGER_SPEC)'
  196. .PHONY: swagger-check
  197. swagger-check: generate-swagger
  198. @diff=$$(git diff '$(SWAGGER_SPEC)'); \
  199. if [ -n "$$diff" ]; then \
  200. echo "Please run 'make generate-swagger' and commit the result:"; \
  201. echo "$${diff}"; \
  202. exit 1; \
  203. fi;
  204. .PHONY: swagger-validate
  205. swagger-validate:
  206. $(SED_INPLACE) '$(SWAGGER_SPEC_S_JSON)' './$(SWAGGER_SPEC)'
  207. $(SWAGGER) validate './$(SWAGGER_SPEC)'
  208. $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
  209. .PHONY: errcheck
  210. errcheck:
  211. @hash errcheck > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  212. GO111MODULE=off $(GO) get -u github.com/kisielk/errcheck; \
  213. fi
  214. errcheck $(GO_PACKAGES)
  215. .PHONY: revive
  216. revive:
  217. GO111MODULE=on $(GO) run -mod=vendor build/lint.go -config .revive.toml -exclude=./vendor/... ./... || exit 1
  218. .PHONY: misspell-check
  219. misspell-check:
  220. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  221. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  222. fi
  223. misspell -error -i unknwon,destory $(GO_SOURCES_OWN)
  224. .PHONY: misspell
  225. misspell:
  226. @hash misspell > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  227. GO111MODULE=off $(GO) get -u github.com/client9/misspell/cmd/misspell; \
  228. fi
  229. misspell -w -i unknwon $(GO_SOURCES_OWN)
  230. .PHONY: fmt-check
  231. fmt-check:
  232. # get all go files and run go fmt on them
  233. @diff=$$($(GOFMT) -d $(GO_SOURCES_OWN)); \
  234. if [ -n "$$diff" ]; then \
  235. echo "Please run 'make fmt' and commit the result:"; \
  236. echo "$${diff}"; \
  237. exit 1; \
  238. fi;
  239. .PHONY: lint
  240. lint: lint-backend lint-frontend
  241. .PHONY: lint-backend
  242. lint-backend: golangci-lint revive vet swagger-check swagger-validate test-vendor
  243. .PHONY: lint-frontend
  244. lint-frontend: node_modules svg-check
  245. npx eslint web_src/js build webpack.config.js
  246. npx stylelint web_src/less
  247. .PHONY: watch-frontend
  248. watch-frontend: node-check $(FOMANTIC_DEST) node_modules
  249. rm -rf $(WEBPACK_DEST_ENTRIES)
  250. NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
  251. .PHONY: test
  252. test:
  253. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
  254. .PHONY: test-check
  255. test-check:
  256. @echo "Checking if tests have changed the source tree...";
  257. @diff=$$(git status -s); \
  258. if [ -n "$$diff" ]; then \
  259. echo "make test has changed files in the source tree:"; \
  260. echo "$${diff}"; \
  261. echo "You should change the tests to create these files in a temporary directory."; \
  262. echo "Do not simply add these files to .gitignore"; \
  263. exit 1; \
  264. fi;
  265. .PHONY: test\#%
  266. test\#%:
  267. $(GO) test -mod=vendor -tags='sqlite sqlite_unlock_notify' -run $(subst .,/,$*) $(GO_PACKAGES)
  268. .PHONY: coverage
  269. coverage:
  270. GO111MODULE=on $(GO) run -mod=vendor build/gocovmerge.go integration.coverage.out $(shell find . -type f -name "coverage.out") > coverage.all
  271. .PHONY: unit-test-coverage
  272. unit-test-coverage:
  273. $(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' -cover -coverprofile coverage.out $(GO_PACKAGES) && echo "\n==>\033[32m Ok\033[m\n" || exit 1
  274. .PHONY: vendor
  275. vendor:
  276. $(GO) mod tidy && $(GO) mod vendor
  277. .PHONY: test-vendor
  278. test-vendor: vendor
  279. @diff=$$(git diff vendor/); \
  280. if [ -n "$$diff" ]; then \
  281. echo "Please run 'make vendor' and commit the result:"; \
  282. echo "$${diff}"; \
  283. exit 1; \
  284. fi;
  285. generate-ini-sqlite:
  286. sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  287. integrations/sqlite.ini.tmpl > integrations/sqlite.ini
  288. .PHONY: test-sqlite
  289. test-sqlite: integrations.sqlite.test generate-ini-sqlite
  290. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test
  291. .PHONY: test-sqlite\#%
  292. test-sqlite\#%: integrations.sqlite.test generate-ini-sqlite
  293. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.run $(subst .,/,$*)
  294. .PHONY: test-sqlite-migration
  295. test-sqlite-migration: migrations.sqlite.test generate-ini-sqlite
  296. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./migrations.sqlite.test
  297. generate-ini-mysql:
  298. sed -e 's|{{TEST_MYSQL_HOST}}|${TEST_MYSQL_HOST}|g' \
  299. -e 's|{{TEST_MYSQL_DBNAME}}|${TEST_MYSQL_DBNAME}|g' \
  300. -e 's|{{TEST_MYSQL_USERNAME}}|${TEST_MYSQL_USERNAME}|g' \
  301. -e 's|{{TEST_MYSQL_PASSWORD}}|${TEST_MYSQL_PASSWORD}|g' \
  302. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  303. integrations/mysql.ini.tmpl > integrations/mysql.ini
  304. .PHONY: test-mysql
  305. test-mysql: integrations.mysql.test generate-ini-mysql
  306. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test
  307. .PHONY: test-mysql\#%
  308. test-mysql\#%: integrations.mysql.test generate-ini-mysql
  309. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.run $(subst .,/,$*)
  310. .PHONY: test-mysql-migration
  311. test-mysql-migration: migrations.mysql.test generate-ini-mysql
  312. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./migrations.mysql.test
  313. generate-ini-mysql8:
  314. sed -e 's|{{TEST_MYSQL8_HOST}}|${TEST_MYSQL8_HOST}|g' \
  315. -e 's|{{TEST_MYSQL8_DBNAME}}|${TEST_MYSQL8_DBNAME}|g' \
  316. -e 's|{{TEST_MYSQL8_USERNAME}}|${TEST_MYSQL8_USERNAME}|g' \
  317. -e 's|{{TEST_MYSQL8_PASSWORD}}|${TEST_MYSQL8_PASSWORD}|g' \
  318. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  319. integrations/mysql8.ini.tmpl > integrations/mysql8.ini
  320. .PHONY: test-mysql8
  321. test-mysql8: integrations.mysql8.test generate-ini-mysql8
  322. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test
  323. .PHONY: test-mysql8\#%
  324. test-mysql8\#%: integrations.mysql8.test generate-ini-mysql8
  325. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./integrations.mysql8.test -test.run $(subst .,/,$*)
  326. .PHONY: test-mysql8-migration
  327. test-mysql8-migration: migrations.mysql8.test generate-ini-mysql8
  328. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql8.ini ./migrations.mysql8.test
  329. generate-ini-pgsql:
  330. sed -e 's|{{TEST_PGSQL_HOST}}|${TEST_PGSQL_HOST}|g' \
  331. -e 's|{{TEST_PGSQL_DBNAME}}|${TEST_PGSQL_DBNAME}|g' \
  332. -e 's|{{TEST_PGSQL_USERNAME}}|${TEST_PGSQL_USERNAME}|g' \
  333. -e 's|{{TEST_PGSQL_PASSWORD}}|${TEST_PGSQL_PASSWORD}|g' \
  334. -e 's|{{TEST_PGSQL_SCHEMA}}|${TEST_PGSQL_SCHEMA}|g' \
  335. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  336. integrations/pgsql.ini.tmpl > integrations/pgsql.ini
  337. .PHONY: test-pgsql
  338. test-pgsql: integrations.pgsql.test generate-ini-pgsql
  339. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test
  340. .PHONY: test-pgsql\#%
  341. test-pgsql\#%: integrations.pgsql.test generate-ini-pgsql
  342. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.run $(subst .,/,$*)
  343. .PHONY: test-pgsql-migration
  344. test-pgsql-migration: migrations.pgsql.test generate-ini-pgsql
  345. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./migrations.pgsql.test
  346. generate-ini-mssql:
  347. sed -e 's|{{TEST_MSSQL_HOST}}|${TEST_MSSQL_HOST}|g' \
  348. -e 's|{{TEST_MSSQL_DBNAME}}|${TEST_MSSQL_DBNAME}|g' \
  349. -e 's|{{TEST_MSSQL_USERNAME}}|${TEST_MSSQL_USERNAME}|g' \
  350. -e 's|{{TEST_MSSQL_PASSWORD}}|${TEST_MSSQL_PASSWORD}|g' \
  351. -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
  352. integrations/mssql.ini.tmpl > integrations/mssql.ini
  353. .PHONY: test-mssql
  354. test-mssql: integrations.mssql.test generate-ini-mssql
  355. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test
  356. .PHONY: test-mssql\#%
  357. test-mssql\#%: integrations.mssql.test generate-ini-mssql
  358. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.run $(subst .,/,$*)
  359. .PHONY: test-mssql-migration
  360. test-mssql-migration: migrations.mssql.test generate-ini-mssql
  361. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./migrations.mssql.test
  362. .PHONY: bench-sqlite
  363. bench-sqlite: integrations.sqlite.test generate-ini-sqlite
  364. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/sqlite.ini ./integrations.sqlite.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  365. .PHONY: bench-mysql
  366. bench-mysql: integrations.mysql.test generate-ini-mysql
  367. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.mysql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  368. .PHONY: bench-mssql
  369. bench-mssql: integrations.mssql.test generate-ini-mssql
  370. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mssql.ini ./integrations.mssql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  371. .PHONY: bench-pgsql
  372. bench-pgsql: integrations.pgsql.test generate-ini-pgsql
  373. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/pgsql.ini ./integrations.pgsql.test -test.cpuprofile=cpu.out -test.run DontRunTests -test.bench .
  374. .PHONY: integration-test-coverage
  375. integration-test-coverage: integrations.cover.test generate-ini-mysql
  376. GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
  377. integrations.mysql.test: git-check $(GO_SOURCES)
  378. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
  379. integrations.mysql8.test: git-check $(GO_SOURCES)
  380. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
  381. integrations.pgsql.test: git-check $(GO_SOURCES)
  382. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
  383. integrations.mssql.test: git-check $(GO_SOURCES)
  384. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
  385. integrations.sqlite.test: git-check $(GO_SOURCES)
  386. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  387. integrations.cover.test: git-check $(GO_SOURCES)
  388. $(GO) test $(GOTESTFLAGS) -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(GO_PACKAGES) | tr ' ' ',') -o integrations.cover.test
  389. .PHONY: migrations.mysql.test
  390. migrations.mysql.test: $(GO_SOURCES)
  391. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
  392. .PHONY: migrations.mysql8.test
  393. migrations.mysql8.test: $(GO_SOURCES)
  394. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
  395. .PHONY: migrations.pgsql.test
  396. migrations.pgsql.test: $(GO_SOURCES)
  397. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
  398. .PHONY: migrations.mssql.test
  399. migrations.mssql.test: $(GO_SOURCES)
  400. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
  401. .PHONY: migrations.sqlite.test
  402. migrations.sqlite.test: $(GO_SOURCES)
  403. $(GO) test $(GOTESTFLAGS) -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
  404. .PHONY: check
  405. check: test
  406. .PHONY: install $(TAGS_PREREQ)
  407. install: $(wildcard *.go)
  408. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
  409. .PHONY: build
  410. build: frontend backend
  411. .PHONY: frontend
  412. frontend: node-check $(FOMANTIC_DEST) $(WEBPACK_DEST)
  413. .PHONY: backend
  414. backend: go-check generate $(EXECUTABLE)
  415. .PHONY: generate
  416. generate: $(TAGS_PREREQ)
  417. CC= GOOS= GOARCH= $(GO) generate -mod=vendor -tags '$(TAGS)' $(GO_PACKAGES)
  418. $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ)
  419. CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
  420. .PHONY: release
  421. release: frontend generate release-windows release-linux release-darwin release-copy release-compress release-sources release-docs release-check
  422. $(DIST_DIRS):
  423. mkdir -p $(DIST_DIRS)
  424. .PHONY: release-windows
  425. release-windows: | $(DIST_DIRS)
  426. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  427. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  428. fi
  429. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets 'windows/*' -out gitea-$(VERSION) .
  430. ifeq ($(CI),drone)
  431. cp /build/* $(DIST)/binaries
  432. endif
  433. .PHONY: release-linux
  434. release-linux: | $(DIST_DIRS)
  435. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  436. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  437. fi
  438. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -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) .
  439. ifeq ($(CI),drone)
  440. cp /build/* $(DIST)/binaries
  441. endif
  442. .PHONY: release-darwin
  443. release-darwin: | $(DIST_DIRS)
  444. @hash xgo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  445. GO111MODULE=off $(GO) get -u src.techknowlogick.com/xgo; \
  446. fi
  447. CGO_CFLAGS="$(CGO_CFLAGS)" GO111MODULE=off xgo -go $(XGO_VERSION) -dest $(DIST)/binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets 'darwin/*' -out gitea-$(VERSION) .
  448. ifeq ($(CI),drone)
  449. cp /build/* $(DIST)/binaries
  450. endif
  451. .PHONY: release-copy
  452. release-copy: | $(DIST_DIRS)
  453. cd $(DIST); for file in `find /build -type f -name "*"`; do cp $${file} ./release/; done;
  454. .PHONY: release-check
  455. release-check: | $(DIST_DIRS)
  456. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "checksumming $${file}" && $(SHASUM) `echo $${file} | sed 's/^..//'` > $${file}.sha256; done;
  457. .PHONY: release-compress
  458. release-compress: | $(DIST_DIRS)
  459. @hash gxz > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  460. GO111MODULE=off $(GO) get -u github.com/ulikunitz/xz/cmd/gxz; \
  461. fi
  462. cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
  463. .PHONY: release-sources
  464. release-sources: | $(DIST_DIRS) node_modules
  465. echo $(VERSION) > $(STORED_VERSION_FILE)
  466. tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
  467. rm -f $(STORED_VERSION_FILE)
  468. .PHONY: release-docs
  469. release-docs: | $(DIST_DIRS) docs
  470. tar -czf $(DIST)/release/gitea-docs-$(VERSION).tar.gz -C ./docs/public .
  471. .PHONY: docs
  472. docs:
  473. @hash hugo > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  474. $(GO) get -u github.com/gohugoio/hugo; \
  475. fi
  476. cd docs; make trans-copy clean build-offline;
  477. node_modules: package-lock.json
  478. npm install --no-save
  479. @touch node_modules
  480. .PHONY: npm-update
  481. npm-update: node-check | node_modules
  482. npx updates -cu
  483. rm -rf node_modules package-lock.json
  484. npm install --package-lock
  485. .PHONY: fomantic
  486. fomantic: $(FOMANTIC_DEST)
  487. $(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) | node_modules
  488. rm -rf $(FOMANTIC_DEST_DIR)
  489. cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
  490. cp -r web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
  491. npx gulp -f node_modules/fomantic-ui/gulpfile.js build
  492. @touch $(FOMANTIC_DEST)
  493. .PHONY: webpack
  494. webpack: $(WEBPACK_DEST)
  495. $(WEBPACK_DEST): $(WEBPACK_SOURCES) $(WEBPACK_CONFIGS) package-lock.json | node_modules
  496. rm -rf $(WEBPACK_DEST_ENTRIES)
  497. npx webpack --hide-modules --display-entrypoints=false
  498. @touch $(WEBPACK_DEST)
  499. .PHONY: svg
  500. svg: node-check | node_modules
  501. rm -rf $(SVG_DEST_DIR)
  502. node build/generate-svg.js
  503. .PHONY: svg-check
  504. svg-check: svg
  505. @diff=$$(git diff $(SVG_DEST_DIR)); \
  506. if [ -n "$$diff" ]; then \
  507. echo "Please run 'make svg' and commit the result:"; \
  508. echo "$${diff}"; \
  509. exit 1; \
  510. fi;
  511. .PHONY: update-translations
  512. update-translations:
  513. mkdir -p ./translations
  514. cd ./translations && curl -L https://crowdin.com/download/project/gitea.zip > gitea.zip && unzip gitea.zip
  515. rm ./translations/gitea.zip
  516. $(SED_INPLACE) -e 's/="/=/g' -e 's/"$$//g' ./translations/*.ini
  517. $(SED_INPLACE) -e 's/\\"/"/g' ./translations/*.ini
  518. mv ./translations/*.ini ./options/locale/
  519. rmdir ./translations
  520. .PHONY: generate-images
  521. generate-images:
  522. $(eval TMPDIR := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gitea-temp'))
  523. mkdir -p $(TMPDIR)/images
  524. inkscape -f $(PWD)/assets/logo.svg -w 880 -h 880 -e $(PWD)/public/img/gitea-lg.png
  525. inkscape -f $(PWD)/assets/logo.svg -w 512 -h 512 -e $(PWD)/public/img/gitea-512.png
  526. inkscape -f $(PWD)/assets/logo.svg -w 192 -h 192 -e $(PWD)/public/img/gitea-192.png
  527. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer1 -e $(TMPDIR)/images/sm-1.png
  528. inkscape -f $(PWD)/assets/logo.svg -w 120 -h 120 -jC -i layer2 -e $(TMPDIR)/images/sm-2.png
  529. composite -compose atop $(TMPDIR)/images/sm-2.png $(TMPDIR)/images/sm-1.png $(PWD)/public/img/gitea-sm.png
  530. inkscape -f $(PWD)/assets/logo.svg -w 200 -h 200 -e $(PWD)/public/img/avatar_default.png
  531. inkscape -f $(PWD)/assets/logo.svg -w 180 -h 180 -e $(PWD)/public/img/favicon.png
  532. inkscape -f $(PWD)/assets/logo.svg -w 128 -h 128 -e $(TMPDIR)/images/128-raw.png
  533. inkscape -f $(PWD)/assets/logo.svg -w 64 -h 64 -e $(TMPDIR)/images/64-raw.png
  534. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer1 -e $(TMPDIR)/images/32-1.png
  535. inkscape -f $(PWD)/assets/logo.svg -w 32 -h 32 -jC -i layer2 -e $(TMPDIR)/images/32-2.png
  536. composite -compose atop $(TMPDIR)/images/32-2.png $(TMPDIR)/images/32-1.png $(TMPDIR)/images/32-raw.png
  537. inkscape -f $(PWD)/assets/logo.svg -w 16 -h 16 -jC -i layer1 -e $(TMPDIR)/images/16-raw.png
  538. zopflipng -m -y $(TMPDIR)/images/128-raw.png $(TMPDIR)/images/128.png
  539. zopflipng -m -y $(TMPDIR)/images/64-raw.png $(TMPDIR)/images/64.png
  540. zopflipng -m -y $(TMPDIR)/images/32-raw.png $(TMPDIR)/images/32.png
  541. zopflipng -m -y $(TMPDIR)/images/16-raw.png $(TMPDIR)/images/16.png
  542. rm -f $(TMPDIR)/images/*-*.png
  543. convert $(TMPDIR)/images/16.png $(TMPDIR)/images/32.png \
  544. $(TMPDIR)/images/64.png $(TMPDIR)/images/128.png \
  545. $(PWD)/public/img/favicon.ico
  546. convert -flatten $(PWD)/public/img/favicon.png $(PWD)/public/img/apple-touch-icon.png
  547. rm -rf $(TMPDIR)/images
  548. $(foreach file, $(shell find public/img -type f -name '*.png' ! -name 'loading.png'),zopflipng -m -y $(file) $(file);)
  549. .PHONY: pr\#%
  550. pr\#%: clean-all
  551. $(GO) run contrib/pr/checkout.go $*
  552. .PHONY: golangci-lint
  553. golangci-lint:
  554. @hash golangci-lint > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
  555. export BINARY="golangci-lint"; \
  556. curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(GOPATH)/bin v1.24.0; \
  557. fi
  558. golangci-lint run --timeout 5m
  559. # This endif closes the if at the top of the file
  560. endif