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.

714 lines
26 KiB

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