Skip to content

Commit dd36827

Browse files
committed
Add Node.js build dep, remove built js/css files
- Added Node.js as build dependency and removes build files from git. - Added version checks for both Go and Node.js. - Overhauled the js/css make target to only run when needed. - Merged the `generate` make target into `build` as per suggestion. Fixes: #6782 Fixes: #9216
1 parent e80fe20 commit dd36827

13 files changed

+92
-1427
lines changed

.drone.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,10 @@ steps:
5656

5757
- name: pre-build
5858
pull: always
59-
image: webhippie/nodejs:latest
59+
image: node:10 # this step is kept at the lowest version of node that we support
6060
commands:
6161
- make css
6262
- make js
63-
- bash -c '[ -z "$(git status --porcelain public/js public/css)" ] || (echo "Generated js/css files do not match" && git status --porcelain public/js public/css && exit 1)'
6463

6564
- name: build-without-gcc
6665
pull: always
@@ -69,6 +68,7 @@ steps:
6968
GO111MODULE: on
7069
GOPROXY: off
7170
commands:
71+
- curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt -y install nodejs
7272
- go build -mod=vendor -o gitea_no_gcc # test if build succeeds without the sqlite tag
7373

7474
- name: build-linux-386
@@ -80,12 +80,14 @@ steps:
8080
GOOS: linux
8181
GOARCH: 386
8282
commands:
83+
- curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt -y install nodejs
8384
- go build -mod=vendor -o gitea_linux_386 # test if compatible with 32 bit
8485

8586
- name: build
8687
pull: always
8788
image: golang:1.13
8889
commands:
90+
- curl -sL https://deb.nodesource.com/setup_12.x | bash - && apt -y install nodejs
8991
- make clean
9092
- make generate
9193
- make golangci-lint

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ coverage.all
6969
/modules/indexer/issues/indexers
7070
routers/repo/authorized_keys
7171
/yarn.lock
72+
/public/js
73+
/public/css
7274

7375
# Snapcraft
7476
snap/.snapcraft/
@@ -78,4 +80,4 @@ prime/
7880
*.snap
7981
*.snap-build
8082
*_source.tar.bz2
81-
.DS_Store
83+
.DS_Store

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ARG TAGS="sqlite sqlite_unlock_notify"
1111
ENV TAGS "bindata $TAGS"
1212

1313
#Build deps
14-
RUN apk --no-cache add build-base git
14+
RUN apk --no-cache add build-base git nodejs npm
1515

1616
#Setup repo
1717
COPY . ${GOPATH}/src/code.gitea.io/gitea

Makefile

+60-31
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ else
1818
endif
1919
endif
2020

21-
BINDATA := modules/{options,public,templates}/bindata.go
2221
GOFILES := $(shell find . -name "*.go" -type f ! -path "./vendor/*" ! -path "*/bindata.go")
2322
GOFMT ?= gofmt -s
2423

@@ -42,7 +41,17 @@ endif
4241
LDFLAGS := $(LDFLAGS) -X "main.MakeVersion=$(MAKE_VERSION)" -X "main.Version=$(GITEA_VERSION)" -X "main.Tags=$(TAGS)"
4342

4443
PACKAGES ?= $(filter-out code.gitea.io/gitea/integrations/migration-test,$(filter-out code.gitea.io/gitea/integrations,$(shell GO111MODULE=on $(GO) list -mod=vendor ./... | grep -v /vendor/)))
45-
SOURCES ?= $(shell find . -name "*.go" -type f)
44+
45+
GO_SOURCES ?= $(shell find . -name "*.go" -type f)
46+
JS_SOURCES ?= $(shell find web_src/js web_src/css -type f)
47+
CSS_SOURCES ?= $(shell find web_src/less -type f)
48+
49+
JS_DEST := public/js/index.js
50+
CSS_DEST := public/css/index.css
51+
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
52+
53+
JS_DEST_DIR := public/js
54+
CSS_DEST_DIR := public/css
4655

4756
TAGS ?=
4857

@@ -80,10 +89,31 @@ all: build
8089

8190
include docker/Makefile
8291

92+
.PHONY: go-check
93+
go-check:
94+
$(eval GO_VERSION := $(shell printf "%03d%03d%03d" $(shell go version | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?\s' | tr '.' ' ');))
95+
@if [ "$(GO_VERSION)" -lt "001011000" ]; then \
96+
echo "Gitea requires Go 1.11.0 or greater to build. You can get it at https://golang.org/dl/"; \
97+
exit 1; \
98+
fi
99+
100+
.PHONY: node-check
101+
node-check:
102+
$(eval NODE_VERSION := $(shell printf "%03d%03d%03d" $(shell node -v | grep -Eo '[0-9]+\.?[0-9]+?\.?[0-9]?' | tr '.' ' ');))
103+
$(eval NPM_MISSING := $(shell hash npm > /dev/null 2>&1 || echo 1))
104+
@if [ "$(NODE_VERSION)" -lt "010000000" -o "$(NPM_MISSING)" = "1" ]; then \
105+
echo "Gitea requires Node.js 10.0.0 or greater and npm to build. You can get it at https://nodejs.org/en/download/"; \
106+
exit 1; \
107+
fi
108+
109+
.PHONY: clean-all
110+
clean-all: clean
111+
rm -rf $(JS_DEST_DIR) $(CSS_DEST_DIR)
112+
83113
.PHONY: clean
84114
clean:
85115
$(GO) clean -i ./...
86-
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA) \
116+
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA_DEST) \
87117
integrations*.test \
88118
integrations/gitea-integration-pgsql/ integrations/gitea-integration-mysql/ integrations/gitea-integration-mysql8/ integrations/gitea-integration-sqlite/ \
89119
integrations/gitea-integration-mssql/ integrations/indexers-mysql/ integrations/indexers-mysql8/ integrations/indexers-pgsql integrations/indexers-sqlite \
@@ -309,42 +339,42 @@ bench-pgsql: integrations.pgsql.test generate-ini-pgsql
309339
integration-test-coverage: integrations.cover.test generate-ini-mysql
310340
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
311341

312-
integrations.mysql.test: $(SOURCES)
342+
integrations.mysql.test: $(GO_SOURCES)
313343
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql.test
314344

315-
integrations.mysql8.test: $(SOURCES)
345+
integrations.mysql8.test: $(GO_SOURCES)
316346
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mysql8.test
317347

318-
integrations.pgsql.test: $(SOURCES)
348+
integrations.pgsql.test: $(GO_SOURCES)
319349
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.pgsql.test
320350

321-
integrations.mssql.test: $(SOURCES)
351+
integrations.mssql.test: $(GO_SOURCES)
322352
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.mssql.test
323353

324-
integrations.sqlite.test: $(SOURCES)
354+
integrations.sqlite.test: $(GO_SOURCES)
325355
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
326356

327-
integrations.cover.test: $(SOURCES)
357+
integrations.cover.test: $(GO_SOURCES)
328358
GO111MODULE=on $(GO) test -mod=vendor -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
329359

330360
.PHONY: migrations.mysql.test
331-
migrations.mysql.test: $(SOURCES)
361+
migrations.mysql.test: $(GO_SOURCES)
332362
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql.test
333363

334364
.PHONY: migrations.mysql8.test
335-
migrations.mysql8.test: $(SOURCES)
365+
migrations.mysql8.test: $(GO_SOURCES)
336366
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mysql8.test
337367

338368
.PHONY: migrations.pgsql.test
339-
migrations.pgsql.test: $(SOURCES)
369+
migrations.pgsql.test: $(GO_SOURCES)
340370
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.pgsql.test
341371

342372
.PHONY: migrations.mssql.test
343-
migrations.mssql.test: $(SOURCES)
373+
migrations.mssql.test: $(GO_SOURCES)
344374
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.mssql.test
345375

346376
.PHONY: migrations.sqlite.test
347-
migrations.sqlite.test: $(SOURCES)
377+
migrations.sqlite.test: $(GO_SOURCES)
348378
$(GO) test -c code.gitea.io/gitea/integrations/migration-test -o migrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
349379

350380
.PHONY: check
@@ -354,10 +384,16 @@ check: test
354384
install: $(wildcard *.go)
355385
$(GO) install -v -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)'
356386

387+
.PHONY: go
388+
go: go-check $(EXECUTABLE)
389+
390+
.PHONY: go-all
391+
go-all: go-check generate go
392+
357393
.PHONY: build
358-
build: $(EXECUTABLE)
394+
build: js css go-all
359395

360-
$(EXECUTABLE): $(SOURCES)
396+
$(EXECUTABLE): $(GO_SOURCES)
361397
GO111MODULE=on $(GO) build -mod=vendor $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@
362398

363399
.PHONY: release
@@ -412,33 +448,26 @@ release-compress:
412448
fi
413449
cd $(DIST)/release/; for file in `find . -type f -name "*"`; do echo "compressing $${file}" && gxz -k -9 $${file}; done;
414450

415-
npm-check:
416-
@hash npm > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
417-
echo "Please install Node.js 8.x or greater with npm"; \
418-
exit 1; \
419-
fi;
420-
@hash npx > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
421-
echo "Please install Node.js 8.x or greater with npm"; \
422-
exit 1; \
423-
fi;
424-
425-
.PHONY: npm
426-
npm: npm-check
451+
node_modules: package-lock.json
427452
npm install --no-save
428453

429454
.PHONY: npm-update
430-
npm-update: npm-check
455+
npm-update: node-check node_modules
431456
npx updates -cu
432457
rm -rf node_modules package-lock.json
433458
npm install --package-lock
434459

435460
.PHONY: js
436-
js: npm
461+
js: node-check $(JS_DEST)
462+
463+
$(JS_DEST): node_modules $(JS_SOURCES)
437464
npx eslint web_src/js webpack.config.js
438465
npx webpack
439466

440467
.PHONY: css
441-
css: npm
468+
css: node-check $(CSS_DEST)
469+
470+
$(CSS_DEST): node_modules $(CSS_SOURCES)
442471
npx stylelint web_src/less
443472
npx lessc --clean-css="--s0 -b" web_src/less/index.less public/css/index.css
444473
$(foreach file, $(filter-out web_src/less/themes/_base.less, $(wildcard web_src/less/themes/*)),npx lessc --clean-css="--s0 -b" web_src/less/themes/$(notdir $(file)) > public/css/theme-$(notdir $(call strip-suffix,$(file))).css;)

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

+10-8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ environment variable and to add the go bin directory or directories
2323
`${GOPATH//://bin:}/bin` to the `$PATH`. See the Go wiki entry for
2424
[GOPATH](https://github.com/golang/go/wiki/GOPATH).
2525

26+
Next, [install Node.js with npm](https://nodejs.org/en/download/) which is
27+
required to build the JavaScript and CSS files. The minimum supported Node.js
28+
version is 10 and the latest LTS version is recommended.
29+
2630
You will also need make.
2731
<a href='{{< relref "doc/advanced/make.en-us.md" >}}'>(See here how to get Make)</a>
2832

@@ -98,7 +102,7 @@ from source</a>.
98102
The simplest recommended way to build from source is:
99103

100104
```bash
101-
TAGS="bindata sqlite sqlite_unlock_notify" make generate build
105+
TAGS="bindata sqlite sqlite_unlock_notify" make build
102106
```
103107

104108
However, there are a number of additional make tasks you should be aware of.
@@ -136,19 +140,17 @@ You should run revive, vet and spell-check on the code with:
136140
make revive vet misspell-check
137141
```
138142

139-
### Updating CSS
140-
141-
To generate the CSS, you need [Node.js](https://nodejs.org/) 8.0 or greater with npm. We use [less](http://lesscss.org/) and [postcss](https://postcss.org) to generate our CSS. Do **not** edit the files in `public/css` directly, as they are generated from `lessc` from the files in `public/less`.
143+
### Working on CSS
142144

143-
Edit files in `public/less`, and then run the linter and build the CSS files via:
145+
Edit files in `web_src/less` and run the linter and build the CSS files via:
144146

145147
```bash
146148
make css
147149
```
148150

149-
### Updating JS
151+
### Working on JS
150152

151-
To generate the JS files, you need [Node.js](https://nodejs.org/) 8.0 or greater with npm. Edit files in `public/js`, run the linter and build the JS files via:
153+
Edit files in `web_src/js`, run the linter and build the JS files via:
152154

153155
```bash
154156
make js
@@ -235,7 +237,7 @@ Unit tests will not and cannot completely test Gitea alone. Therefore, we
235237
have written integration tests; however, these are database dependent.
236238

237239
```bash
238-
TAGS="bindata sqlite sqlite_unlock_notify" make generate build test-sqlite
240+
TAGS="bindata sqlite sqlite_unlock_notify" make build test-sqlite
239241
```
240242

241243
will run the integration tests in an sqlite environment. Other database tests

docs/content/doc/installation/from-source.en-us.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ environment variable and to add the go bin directory or directories
2121
`${GOPATH//://bin:}/bin` to the `$PATH`. See the Go wiki entry for
2222
[GOPATH](https://github.com/golang/go/wiki/GOPATH).
2323

24+
Next, [install Node.js with npm](https://nodejs.org/en/download/) which is
25+
required to build the JavaScript and CSS files. The minimum supported Node.js
26+
version is 10 and the latest LTS version is recommended.
27+
2428
**Note**: When executing make tasks that require external tools, like
2529
`make misspell-check`, Gitea will automatically download and build these as
2630
necessary. To be able to use these, you must have the `"$GOPATH/bin"` directory
@@ -75,9 +79,12 @@ git checkout v{{< version >}} # or git checkout pr-xyz
7579

7680
## Build
7781

78-
Since all required libraries are already bundled in the Gitea source, it's
79-
possible to build Gitea with no additional downloads apart from Make
80-
<a href='{{< relref "doc/advanced/make.en-us.md" >}}'>(See here how to get Make)</a>.
82+
To build from source, the following programs must be present on the system:
83+
84+
- `go` 1.11.0 or higher, see [here](https://golang.org/dl/)
85+
- `node` 10.0.0 or higher with `npm`, see [here](https://nodejs.org/en/download/)
86+
- `make`, see <a href='{{< relref "doc/advanced/make.en-us.md" >}}'>here</a>
87+
8188
Various [make tasks](https://github.com/go-gitea/gitea/blob/master/Makefile)
8289
are provided to keep the build process as simple as possible.
8390

@@ -93,19 +100,18 @@ Depending on requirements, the following build tags can be included.
93100

94101
Bundling assets into the binary using the `bindata` build tag can make
95102
development and testing easier, but is not ideal for a production deployment.
96-
To include assets, they must be built separately using the `generate` make
97-
task e.g.:
103+
To include assets, add the `bindata` tag:
98104

99105
```bash
100-
TAGS="bindata" make generate build
106+
TAGS="bindata" make build
101107
```
102108

103109
In the default release build of our continuous integration system, the build
104110
tags are: `TAGS="bindata sqlite sqlite_unlock_notify"`. The simplest
105111
recommended way to build from source is therefore:
106112

107113
```bash
108-
TAGS="bindata sqlite sqlite_unlock_notify" make generate build
114+
TAGS="bindata sqlite sqlite_unlock_notify" make build
109115
```
110116

111117
## Test

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"license": "MIT",
33
"private": true,
44
"engines": {
5-
"node": ">=8"
5+
"node": ">=10"
66
},
77
"devDependencies": {
88
"@babel/core": "7.7.2",

0 commit comments

Comments
 (0)