Skip to content

Commit 23f8464

Browse files
authored
build: use make for building the project (filebrowser#1304)
1 parent 2d2c598 commit 23f8464

23 files changed

+218
-194
lines changed

.circleci/config.yml

+21-43
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,39 @@
1-
version: 2
1+
version: 2.1
2+
references:
3+
base_container: &base_container
4+
docker:
5+
- image: filebrowser/builder:v1.1.0
26
jobs:
37
lint:
4-
docker:
5-
- image: golangci/golangci-lint:v1.31.0
8+
<<: *base_container
69
steps:
710
- checkout
8-
- run: golangci-lint run -v
9-
build-node:
10-
docker:
11-
- image: circleci/node
12-
steps:
13-
- checkout
14-
- run:
15-
name: "Build"
16-
command: ./wizard.sh -a
17-
- run:
18-
name: "Cleanup"
19-
command: rm -rf frontend/node_modules
20-
- persist_to_workspace:
21-
root: .
22-
paths:
23-
- '*'
11+
- run: make lint
2412
test:
25-
docker:
26-
- image: circleci/golang:1.15.2
13+
<<: *base_container
2714
steps:
2815
- checkout
2916
- run:
3017
name: "Test"
31-
command: go test ./...
32-
build-go:
33-
docker:
34-
- image: circleci/golang:1.15.2
18+
command: make test
19+
build:
20+
<<: *base_container
3521
steps:
36-
- attach_workspace:
37-
at: '~/project'
22+
- checkout
3823
- run:
39-
name: "Compile"
40-
command: GOOS=linux GOARCH=amd64 ./wizard.sh -c
24+
name: "Build"
25+
command: make build
4126
- run:
4227
name: "Cleanup"
4328
command: |
44-
rm -rf frontend/build
45-
git checkout -- go.sum # TODO: why is it being changed?
29+
rm -rf frontend/node_modules
30+
rm -rf bin/
4631
- persist_to_workspace:
4732
root: .
4833
paths:
4934
- '*'
5035
release:
51-
docker:
52-
- image: circleci/golang:1.15.2
36+
<<: *base_container
5337
steps:
5438
- attach_workspace:
5539
at: '~/project'
@@ -69,22 +53,16 @@ workflows:
6953
filters:
7054
tags:
7155
only: /.*/
72-
- build-node:
73-
filters:
74-
tags:
75-
only: /.*/
76-
- build-go:
56+
- build:
7757
filters:
7858
tags:
7959
only: /.*/
80-
requires:
81-
- build-node
82-
- lint
83-
- test
8460
- release:
8561
context: deploy
8662
requires:
87-
- build-go
63+
- build
64+
- test
65+
- lint
8866
filters:
8967
tags:
9068
only: /^v.*/

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ yarn-error.log*
2828
*.njsproj
2929
*.sln
3030
*.sw*
31+
bin/
32+
build/

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ linters:
6363
- goconst
6464
- gocritic
6565
- gocyclo
66-
- gofmt
6766
- goimports
6867
- golint
6968
- gomnd

.versionrc

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"types": [
3+
{ "type": "feat", "section": "Features" },
4+
{ "type": "fix", "section": "Bug Fixes" },
5+
{ "type": "perf", "section": "Performance improvements" },
6+
{ "type": "revert", "section": "Reverts" },
7+
{ "type": "refactor", "section": "Refactorings" },
8+
{ "type": "build", "section": "Build" },
9+
{ "type": "ci", "hidden": true },
10+
{ "type": "test", "hidden": true },
11+
{ "type": "chore", "hidden": true },
12+
{ "type": "docs", "hidden": true }
13+
]
14+
}

Makefile

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
SHELL := /bin/bash
2+
BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
3+
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
4+
cat $(CURDIR)/.version 2> /dev/null || echo v0)
5+
VERSION_HASH = $(shell git rev-parse HEAD)
6+
7+
BIN = $(BASE_PATH)/bin
8+
PATH := $(BIN):$(PATH)
9+
export PATH
10+
11+
# printing
12+
V = 0
13+
Q = $(if $(filter 1,$V),,@)
14+
M = $(shell printf "\033[34;1m▶\033[0m")
15+
16+
GO = GOGC=off go
17+
# go module
18+
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
19+
20+
DATE ?= $(shell date +%FT%T%z)
21+
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
22+
cat $(CURDIR)/.version 2> /dev/null || echo v0)
23+
VERSION_HASH = $(shell git rev-parse HEAD)
24+
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
25+
26+
LDFLAGS += -X "$(MODULE)/varsion.Version=$(VERSION)" -X "$(MODULE)/varsion.CommitSHA=$(VERSION_HASH)"
27+
28+
# tools
29+
$(BIN):
30+
@mkdir -p $@
31+
$(BIN)/%: | $(BIN) ; $(info $(M) installing $(PACKAGE)…)
32+
$Q env GOBIN=$(BIN) $(GO) install $(PACKAGE)
33+
34+
GOLANGCI_LINT = $(BIN)/golangci-lint
35+
$(BIN)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
36+
37+
GOIMPORTS = $(BIN)/goimports
38+
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports@v0.1.0
39+
40+
RICE = $(BIN)/rice
41+
$(BIN)/rice: PACKAGE=github.com/GeertJohan/go.rice/rice@v1.0.2
42+
43+
## build: Build
44+
.PHONY: build
45+
build: | build-frontend build-backend ; $(info $(M) building…)
46+
47+
## build-frontend: Build frontend
48+
.PHONY: build-frontend
49+
build-frontend: | ; $(info $(M) building frontend…)
50+
$Q cd frontend && npm ci && npm run build
51+
52+
## build-backend: Build backend
53+
.PHONY: build-backend
54+
build-backend: | $(RICE) ; $(info $(M) building backend…)
55+
$Q cd ./http && rm -rf rice-box.go && $(RICE) embed-go
56+
$Q $(GO) build -ldflags '$(LDFLAGS)' -o filebrowser
57+
58+
## test: Run all tests
59+
.PHONY: test
60+
test: | test-frontend test-backend ; $(info $(M) running tests…)
61+
62+
## test-frontend: Run frontend tests
63+
.PHONY: test-frontend
64+
test-frontend: | ; $(info $(M) running frontend tests…)
65+
66+
## test-backend: Run backend tests
67+
.PHONY: test-backend
68+
test-backend: | $(RICE) ; $(info $(M) running backend tests…)
69+
$Q $(GO) test -v ./...
70+
71+
## lint: Lint
72+
.PHONY: lint
73+
lint: lint-frontend lint-backend lint-commits | ; $(info $(M) running all linters…)
74+
75+
## lint-frontend: Lint frontend
76+
.PHONY: lint-frontend
77+
lint-frontend: | ; $(info $(M) running frontend linters…)
78+
$Q cd frontend && npm ci && npm run lint
79+
80+
## lint-backend: Lint backend
81+
.PHONY: lint-backend
82+
lint-backend: | $(GOLANGCI_LINT) ; $(info $(M) running backend linters…)
83+
$Q $(GOLANGCI_LINT) run
84+
85+
## lint-commits: Lint commits
86+
.PHONY: lint-commits
87+
lint-commits: | ; $(info $(M) running commitlint…)
88+
$Q ./scripts/commitlint.sh
89+
90+
## bump-version: Bump app version
91+
.PHONY: bump-version
92+
bump-version: | ; $(info $(M) creating a new release…)
93+
$Q ./scripts/bump_version.sh
94+
95+
## help: Show this help
96+
.PHONY: help
97+
help:
98+
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /' | sort

auth/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func (a JSONAuth) Auth(r *http.Request, sto users.Store, root string) (*users.Us
4040

4141
// If ReCaptcha is enabled, check the code.
4242
if a.ReCaptcha != nil && len(a.ReCaptcha.Secret) > 0 {
43-
ok, err := a.ReCaptcha.Ok(cred.ReCaptcha) //nolint:shadow
43+
ok, err := a.ReCaptcha.Ok(cred.ReCaptcha) //nolint:govet
4444

4545
if err != nil {
4646
return nil, err

cmd/cmds_add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var cmdsAddCmd = &cobra.Command{
1414
Use: "add <event> <command>",
1515
Short: "Add a command to run on a specific event",
1616
Long: `Add a command to run on a specific event.`,
17-
Args: cobra.MinimumNArgs(2), //nolint:mnd
17+
Args: cobra.MinimumNArgs(2), //nolint:gomnd
1818
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
1919
s, err := d.store.Settings.Get()
2020
checkErr(err)

cmd/cmds_rm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can also specify an optional parameter (index_end) so
2323
you can remove all commands from 'index' to 'index_end',
2424
including 'index_end'.`,
2525
Args: func(cmd *cobra.Command, args []string) error {
26-
if err := cobra.RangeArgs(2, 3)(cmd, args); err != nil { //nolint:mnd
26+
if err := cobra.RangeArgs(2, 3)(cmd, args); err != nil { //nolint:gomnd
2727
return err
2828
}
2929

@@ -43,7 +43,7 @@ including 'index_end'.`,
4343
i, err := strconv.Atoi(args[1])
4444
checkErr(err)
4545
f := i
46-
if len(args) == 3 { //nolint:mnd
46+
if len(args) == 3 { //nolint:gomnd
4747
f, err = strconv.Atoi(args[2])
4848
checkErr(err)
4949
}

cmd/root.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,15 @@ user created with the credentials from options "username" and "password".`,
152152
err = os.Chmod(server.Socket, os.FileMode(socketPerm))
153153
checkErr(err)
154154
case server.TLSKey != "" && server.TLSCert != "":
155-
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey) //nolint:shadow
155+
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey) //nolint:govet
156156
checkErr(err)
157-
listener, err = tls.Listen("tcp", adr, &tls.Config{Certificates: []tls.Certificate{cer}}) //nolint:shadow
157+
listener, err = tls.Listen("tcp", adr, &tls.Config{
158+
MinVersion: tls.VersionTLS12,
159+
Certificates: []tls.Certificate{cer}},
160+
)
158161
checkErr(err)
159162
default:
160-
listener, err = net.Listen("tcp", adr) //nolint:shadow
163+
listener, err = net.Listen("tcp", adr)
161164
checkErr(err)
162165
}
163166

cmd/rule_rm.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ including 'index_end'.`,
4444
i, err := strconv.Atoi(args[0])
4545
checkErr(err)
4646
f := i
47-
if len(args) == 2 { //nolint:mnd
47+
if len(args) == 2 { //nolint:gomnd
4848
f, err = strconv.Atoi(args[1])
4949
checkErr(err)
5050
}

cmd/users_add.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var usersAddCmd = &cobra.Command{
1515
Use: "add <username> <password>",
1616
Short: "Create a new user",
1717
Long: `Create a new user and add it to the database.`,
18-
Args: cobra.ExactArgs(2), //nolint:mnd
18+
Args: cobra.ExactArgs(2), //nolint:gomnd
1919
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
2020
s, err := d.store.Settings.Get()
2121
checkErr(err)

cmd/users_import.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ list or set it to 0.`,
6767
// with the new username. If there is, print an error and cancel the
6868
// operation
6969
if user.Username != onDB.Username {
70-
if conflictuous, err := d.store.Users.Get("", user.Username); err == nil { //nolint:shadow
70+
if conflictuous, err := d.store.Users.Get("", user.Username); err == nil { //nolint:govet
7171
checkErr(usernameConflictError(user.Username, conflictuous.ID, user.ID))
7272
}
7373
}

cmd/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func dbExists(path string) (bool, error) {
7272
d := filepath.Dir(path)
7373
_, err = os.Stat(d)
7474
if os.IsNotExist(err) {
75-
if err := os.MkdirAll(d, 0700); err != nil { //nolint:shadow
75+
if err := os.MkdirAll(d, 0700); err != nil { //nolint:govet
7676
return false, err
7777
}
7878
return false, nil

commitlint.config.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
module.exports = {
2+
rules: {
3+
'body-leading-blank': [1, 'always'],
4+
'body-max-line-length': [2, 'always', 100],
5+
'footer-leading-blank': [1, 'always'],
6+
'footer-max-line-length': [2, 'always', 100],
7+
'header-max-length': [2, 'always', 100],
8+
'scope-case': [2, 'always', 'lower-case'],
9+
'subject-case': [
10+
2,
11+
'never',
12+
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
13+
],
14+
'subject-full-stop': [2, 'never', '.'],
15+
'type-case': [2, 'always', 'lower-case'],
16+
'type-empty': [2, 'never'],
17+
'type-enum': [
18+
2,
19+
'always',
20+
[
21+
'feat',
22+
'fix',
23+
'perf',
24+
'revert',
25+
'refactor',
26+
'build',
27+
'ci',
28+
'test',
29+
'chore',
30+
'docs',
31+
],
32+
],
33+
},
34+
};

files/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewFileInfo(opts FileOptions) (*FileInfo, error) {
7979

8080
if opts.Expand {
8181
if file.IsDir {
82-
if err := file.readListing(opts.Checker, opts.ReadHeader); err != nil { //nolint:shadow
82+
if err := file.readListing(opts.Checker, opts.ReadHeader); err != nil { //nolint:govet
8383
return nil, err
8484
}
8585
return file, nil

0 commit comments

Comments
 (0)