Skip to content

Commit e67c042

Browse files
Add 'watch-backend' (go-gitea#12330)
* Add 'watch-backend' This leverages `air` to watch the backend files and trigger `make backend` automatically when they change. It seems to work rather well together with `watch-frontend`. Fixes: go-gitea#12318 * rework docs to a new section for continuous build Co-authored-by: techknowlogick <techknowlogick@gitea.io>
1 parent bfb25e4 commit e67c042

File tree

4 files changed

+39
-17
lines changed

4 files changed

+39
-17
lines changed

.air.conf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = "."
2+
tmp_dir = ".air"
3+
4+
[build]
5+
cmd = "make backend"
6+
bin = "gitea"
7+
include_ext = ["go", "tmpl"]
8+
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata"]
9+
include_dir = ["cmd", "models", "modules", "options", "routers", "services", "templates"]

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ coverage.all
8181
/public/fonts
8282
/web_src/fomantic/build
8383
/VERSION
84+
/.air
8485

8586
# Snapcraft
8687
snap/.snapcraft/

Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
106106

107107
SVG_DEST_DIR := public/img/svg
108108

109+
AIR_TMP_DIR := .air
110+
109111
TAGS ?=
110112
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
111113
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
@@ -161,6 +163,7 @@ help:
161163
@echo " - lint-frontend lint frontend files"
162164
@echo " - lint-backend lint backend files"
163165
@echo " - watch-frontend watch frontend files and continuously rebuild"
166+
@echo " - watch-backend watch backend files and continuously rebuild"
164167
@echo " - webpack build webpack files"
165168
@echo " - svg build svg files"
166169
@echo " - fomantic build fomantic files"
@@ -306,6 +309,13 @@ watch-frontend: node-check $(FOMANTIC_DEST) node_modules
306309
rm -rf $(WEBPACK_DEST_ENTRIES)
307310
NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress
308311

312+
.PHONY: watch-backend
313+
watch-backend: go-check
314+
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
315+
GO111MODULE=off $(GO) get -u github.com/cosmtrek/air; \
316+
fi
317+
air -c .air.conf
318+
309319
.PHONY: test
310320
test:
311321
$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
@@ -579,7 +589,7 @@ release-compress: | $(DIST_DIRS)
579589
.PHONY: release-sources
580590
release-sources: | $(DIST_DIRS) node_modules
581591
echo $(VERSION) > $(STORED_VERSION_FILE)
582-
tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
592+
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 .
583593
rm -f $(STORED_VERSION_FILE)
584594

585595
.PHONY: release-docs

docs/content/doc/advanced/hacking-on-gitea.en-us.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,23 @@ The simplest recommended way to build from source is:
9191
TAGS="bindata sqlite sqlite_unlock_notify" make build
9292
```
9393

94-
See `make help` for all available `make` tasks. Also see [`.drone.yml`](https://github.com/go-gitea/gitea/blob/master/.drone.yml) to see how our continuous integration works.
94+
The `build` target will execute both `frontend` and `backend` sub-targets. If the `bindata` tag is present, the frontend files will be compiled into the binary. It is recommended to leave out the tag when doing frontend development so that changes will be reflected.
95+
96+
See `make help` for all available `make` targets. Also see [`.drone.yml`](https://github.com/go-gitea/gitea/blob/master/.drone.yml) to see how our continuous integration works.
97+
98+
## Building continuously
99+
100+
Both the `frontend` and `backend` targets can be ran continuously when source files change:
101+
102+
````bash
103+
# in your first terminal
104+
make watch-backend
105+
106+
# in your second terminal
107+
make watch-frontend
108+
````
109+
110+
On macOS, watching all backend source files may hit the default open files limit which can be increased via `ulimit -n 12288` for the current shell or in your shell startup file for all future shells.
95111

96112
### Formatting, code analysis and spell check
97113

@@ -123,26 +139,12 @@ make revive vet misspell-check
123139

124140
### Working on JS and CSS
125141

126-
For simple changes, edit files in `web_src`, run the build and start the server to test:
142+
Either use the `watch-frontend` target mentioned above or just build once:
127143

128144
```bash
129145
make build && ./gitea
130146
```
131147

132-
`make build` runs both `make frontend` and `make backend` which can be run individually as well as long as the `bindata` tag is not used (which compiles frontend files into the binary).
133-
134-
For more involved changes use the `watch-frontend` task to continuously rebuild files when their sources change. The `bindata` tag must be absent. First, build and run the backend:
135-
136-
```bash
137-
make backend && ./gitea
138-
```
139-
140-
With the backend running, open another terminal and run:
141-
142-
```bash
143-
make watch-frontend
144-
```
145-
146148
Before committing, make sure the linters pass:
147149

148150
```bash

0 commit comments

Comments
 (0)