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.

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