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.

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