From 23ff182d1f8df2978785772bc58cf0ebfd2aeb0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=B4=9C=C9=B4=E1=B4=8B=C9=B4=E1=B4=A1=E1=B4=8F=C9=B4?= Date: Sat, 29 Aug 2020 21:05:55 +0800 Subject: [PATCH] chore: use Task as main build tool (#6297) --- CHANGELOG.md | 1 + Taskfile.yml | 68 +++++++++++++++++++++++++++++++++++ docs/dev/local_development.md | 15 ++++---- 3 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 Taskfile.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index b37330ec6..0f5a2c33f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ All notable changes to Gogs are documented in this file. - The default branch has been changed to `main`. [#6285](https://github.com/gogs/gogs/pull/6285) - MSSQL as database backend is deprecated, installation page no longer shows it as an option. Existing installations and manually craft configuration file continue to work. [#6295](https://github.com/gogs/gogs/pull/6295) +- Use [Task](https://github.com/go-task/task) as the default build tool for development. [#6297](https://github.com/gogs/gogs/pull/6297) ### Fixed diff --git a/Taskfile.yml b/Taskfile.yml new file mode 100644 index 000000000..160c48f12 --- /dev/null +++ b/Taskfile.yml @@ -0,0 +1,68 @@ +version: '3' + +tasks: + web: + deps: [build] + cmds: + - ./gogs web + sources: + - gogs.go + - internal/**/*.go + + build: + cmds: + - go build -v + -ldflags ' + -X "{{.PKG_PATH}}.BuildTime={{.BUILD_TIME}}" + -X "{{.PKG_PATH}}.BuildCommit={{.BUILD_COMMIT}}" + ' + -tags '{{.TAGS}}' + -trimpath -o gogs + vars: + PKG_PATH: gogs.io/gogs/internal/conf + BUILD_TIME: + sh: date -u '+%Y-%m-%d %I:%M:%S %Z' + BUILD_COMMIT: + sh: git rev-parse HEAD + + generate: + deps: [clean] + cmds: + - go generate internal/assets/conf/conf.go + - go generate internal/assets/templates/templates.go + - go generate internal/assets/public/public.go + + test: + cmds: + - go test -cover -race ./... + + clean: + cmds: + - find . -name "*.DS_Store" -type f -delete + + release: + deps: [build] + cmds: + - rm -rf {{.RELEASE_GOGS}} + - mkdir -p {{.RELEASE_GOGS}} + - cp -r gogs LICENSE README.md README_ZH.md scripts {{.RELEASE_GOGS}} + - cd {{.RELEASE_ROOT}} && zip -r gogs.$(NOW).zip "gogs" + vars: + RELEASE_ROOT: release + RELEASE_GOGS: release/gogs + + less: + cmds: + - lessc --clean-css --source-map "public/less/gogs.less" public/css/gogs.min.css + + fixme: + cmds: + - grep -rnw "FIXME" internal + + todo: + cmds: + - grep -rnw "TODO" internal + + legacy: + cmds: + - grep -rnw "\(LEGACY\|Deprecated\)" internal diff --git a/docs/dev/local_development.md b/docs/dev/local_development.md index f542809b0..07756f04e 100644 --- a/docs/dev/local_development.md +++ b/docs/dev/local_development.md @@ -25,7 +25,7 @@ Gogs has the following dependencies: - [Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) (v1.8.3 or higher) - [Go](https://golang.org/doc/install) (v1.14 or higher) - [Less.js](http://lesscss.org/usage/#command-line-usage-installing) -- [GNU Make](https://www.gnu.org/software/make/) +- [Task](https://github.com/go-task/task) - Database upon your choice (pick one, we choose PostgreSQL in this document): - [PostgreSQL](https://wiki.postgresql.org/wiki/Detailed_installation_guides) (v9.6 or higher) - [MySQL](https://dev.mysql.com/downloads/mysql/) with `ENGINE=InnoDB` (v5.7 or higher) @@ -38,7 +38,7 @@ Gogs has the following dependencies: 1. Install dependencies: ```bash - brew install go postgresql git go-bindata npm + brew install go postgresql git go-bindata npm go-task/tap/go-task npm install -g less npm install -g less-plugin-clean-css ``` @@ -78,6 +78,7 @@ Gogs has the following dependencies: npm install -g less # Watch out, it is NOT github.com/go-bindata/go-bindata! go get -u github.com/kevinburke/go-bindata/... + go get go-task/task/cmd/task ``` 1. Configure startup services: @@ -130,21 +131,23 @@ Create a `custom/conf/app.ini` file inside the repository and put the following ```ini [database] -DB_TYPE = postgres +TYPE = postgres HOST = 127.0.0.1:5432 NAME = gogs USER = gogs -PASSWD = +PASSWORD = SSL_MODE = disable ``` ## Step 5: Start the server +The following command will start the web server and automatically recompile and restart the server if any Go files changed: + ```bash -make web +task web --watch ``` -You would have to re-run this command after changing Go files, or any file under `conf/`, `template/` and `public/` directories. +**NOTE** If you changed any file under `conf/`, `template/` or `public/` directory, be sure to run `task generate` afterwards! ## Other nice things