Skip to content

Commit

Permalink
Add 'watch-backend'
Browse files Browse the repository at this point in the history
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: #12318
  • Loading branch information
silverwind committed Jul 26, 2020
1 parent d0c690f commit d77ef00
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .air.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = "."
tmp_dir = ".air"

[build]
cmd = "make backend"
bin = "gitea"
include_ext = ["go", "tmpl"]
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata"]
include_dir = ["cmd", "models", "modules", "options", "routers", "services", "templates"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ coverage.all
/public/fonts
/web_src/fomantic/build
/VERSION
/.air

# Snapcraft
snap/.snapcraft/
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))

SVG_DEST_DIR := public/img/svg

AIR_TMP_DIR := .air

TAGS ?=
TAGS_SPLIT := $(subst $(COMMA), ,$(TAGS))
TAGS_EVIDENCE := $(MAKE_EVIDENCE_DIR)/tags
Expand Down Expand Up @@ -161,6 +163,7 @@ help:
@echo " - lint-frontend lint frontend files"
@echo " - lint-backend lint backend files"
@echo " - watch-frontend watch frontend files and continuously rebuild"
@echo " - watch-backend watch backend files and continuously rebuild"
@echo " - webpack build webpack files"
@echo " - svg build svg files"
@echo " - fomantic build fomantic files"
Expand Down Expand Up @@ -306,6 +309,13 @@ watch-frontend: node-check $(FOMANTIC_DEST) node_modules
rm -rf $(WEBPACK_DEST_ENTRIES)
NODE_ENV=development npx webpack --hide-modules --display-entrypoints=false --watch --progress

.PHONY: watch-backend
watch-backend: go-check
@hash air > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
GO111MODULE=off $(GO) get -u github.com/cosmtrek/air; \
fi
air -c .air.conf

.PHONY: test
test:
$(GO) test $(GOTESTFLAGS) -mod=vendor -tags='sqlite sqlite_unlock_notify' $(GO_PACKAGES)
Expand Down Expand Up @@ -579,7 +589,7 @@ release-compress: | $(DIST_DIRS)
.PHONY: release-sources
release-sources: | $(DIST_DIRS) node_modules
echo $(VERSION) > $(STORED_VERSION_FILE)
tar --exclude=./$(DIST) --exclude=./.git --exclude=./$(MAKE_EVIDENCE_DIR) --exclude=./node_modules/.cache -czf $(DIST)/release/gitea-src-$(VERSION).tar.gz .
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 .
rm -f $(STORED_VERSION_FILE)

.PHONY: release-docs
Expand Down
8 changes: 8 additions & 0 deletions docs/content/doc/advanced/hacking-on-gitea.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ TAGS="bindata sqlite sqlite_unlock_notify" make build

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.

To continuously watch the backend source files and rebuild when they change, you can use

````bash
make watch-backend
````

On macOS, watching all source files may hit the default open files limit which you can increase using `ulimit -n 12288` for the current shell or in your shell startup file for all shells.

### Formatting, code analysis and spell check

Our continuous integration will reject PRs that are not properly formatted, fail
Expand Down

0 comments on commit d77ef00

Please sign in to comment.