You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 26 kB

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