build: use make for building the project (#1304)
parent
2d2c598fa6
commit
23f84642e6
@ -0,0 +1,14 @@
|
||||
{
|
||||
"types": [
|
||||
{ "type": "feat", "section": "Features" },
|
||||
{ "type": "fix", "section": "Bug Fixes" },
|
||||
{ "type": "perf", "section": "Performance improvements" },
|
||||
{ "type": "revert", "section": "Reverts" },
|
||||
{ "type": "refactor", "section": "Refactorings" },
|
||||
{ "type": "build", "section": "Build" },
|
||||
{ "type": "ci", "hidden": true },
|
||||
{ "type": "test", "hidden": true },
|
||||
{ "type": "chore", "hidden": true },
|
||||
{ "type": "docs", "hidden": true }
|
||||
]
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
SHELL := /bin/bash
|
||||
BASE_PATH := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
|
||||
cat $(CURDIR)/.version 2> /dev/null || echo v0)
|
||||
VERSION_HASH = $(shell git rev-parse HEAD)
|
||||
|
||||
BIN = $(BASE_PATH)/bin
|
||||
PATH := $(BIN):$(PATH)
|
||||
export PATH
|
||||
|
||||
# printing
|
||||
V = 0
|
||||
Q = $(if $(filter 1,$V),,@)
|
||||
M = $(shell printf "\033[34;1m▶\033[0m")
|
||||
|
||||
GO = GOGC=off go
|
||||
# go module
|
||||
MODULE = $(shell env GO111MODULE=on $(GO) list -m)
|
||||
|
||||
DATE ?= $(shell date +%FT%T%z)
|
||||
VERSION ?= $(shell git describe --tags --always --match=v* 2> /dev/null || \
|
||||
cat $(CURDIR)/.version 2> /dev/null || echo v0)
|
||||
VERSION_HASH = $(shell git rev-parse HEAD)
|
||||
BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
|
||||
|
||||
LDFLAGS += -X "$(MODULE)/varsion.Version=$(VERSION)" -X "$(MODULE)/varsion.CommitSHA=$(VERSION_HASH)"
|
||||
|
||||
# tools
|
||||
$(BIN):
|
||||
@mkdir -p $@
|
||||
$(BIN)/%: | $(BIN) ; $(info $(M) installing $(PACKAGE)…)
|
||||
$Q env GOBIN=$(BIN) $(GO) install $(PACKAGE)
|
||||
|
||||
GOLANGCI_LINT = $(BIN)/golangci-lint
|
||||
$(BIN)/golangci-lint: PACKAGE=github.com/golangci/golangci-lint/cmd/golangci-lint@v1.37.1
|
||||
|
||||
GOIMPORTS = $(BIN)/goimports
|
||||
$(BIN)/goimports: PACKAGE=golang.org/x/tools/cmd/goimports@v0.1.0
|
||||
|
||||
RICE = $(BIN)/rice
|
||||
$(BIN)/rice: PACKAGE=github.com/GeertJohan/go.rice/rice@v1.0.2
|
||||
|
||||
## build: Build
|
||||
.PHONY: build
|
||||
build: | build-frontend build-backend ; $(info $(M) building…)
|
||||
|
||||
## build-frontend: Build frontend
|
||||
.PHONY: build-frontend
|
||||
build-frontend: | ; $(info $(M) building frontend…)
|
||||
$Q cd frontend && npm ci && npm run build
|
||||
|
||||
## build-backend: Build backend
|
||||
.PHONY: build-backend
|
||||
build-backend: | $(RICE) ; $(info $(M) building backend…)
|
||||
$Q cd ./http && rm -rf rice-box.go && $(RICE) embed-go
|
||||
$Q $(GO) build -ldflags '$(LDFLAGS)' -o filebrowser
|
||||
|
||||
## test: Run all tests
|
||||
.PHONY: test
|
||||
test: | test-frontend test-backend ; $(info $(M) running tests…)
|
||||
|
||||
## test-frontend: Run frontend tests
|
||||
.PHONY: test-frontend
|
||||
test-frontend: | ; $(info $(M) running frontend tests…)
|
||||
|
||||
## test-backend: Run backend tests
|
||||
.PHONY: test-backend
|
||||
test-backend: | $(RICE) ; $(info $(M) running backend tests…)
|
||||
$Q $(GO) test -v ./...
|
||||
|
||||
## lint: Lint
|
||||
.PHONY: lint
|
||||
lint: lint-frontend lint-backend lint-commits | ; $(info $(M) running all linters…)
|
||||
|
||||
## lint-frontend: Lint frontend
|
||||
.PHONY: lint-frontend
|
||||
lint-frontend: | ; $(info $(M) running frontend linters…)
|
||||
$Q cd frontend && npm ci && npm run lint
|
||||
|
||||
## lint-backend: Lint backend
|
||||
.PHONY: lint-backend
|
||||
lint-backend: | $(GOLANGCI_LINT) ; $(info $(M) running backend linters…)
|
||||
$Q $(GOLANGCI_LINT) run
|
||||
|
||||
## lint-commits: Lint commits
|
||||
.PHONY: lint-commits
|
||||
lint-commits: | ; $(info $(M) running commitlint…)
|
||||
$Q ./scripts/commitlint.sh
|
||||
|
||||
## bump-version: Bump app version
|
||||
.PHONY: bump-version
|
||||
bump-version: | ; $(info $(M) creating a new release…)
|
||||
$Q ./scripts/bump_version.sh
|
||||
|
||||
## help: Show this help
|
||||
.PHONY: help
|
||||
help:
|
||||
@sed -n 's/^## //p' $(MAKEFILE_LIST) | column -t -s ':' | sed -e 's/^/ /' | sort
|
@ -0,0 +1,34 @@
|
||||
module.exports = {
|
||||
rules: {
|
||||
'body-leading-blank': [1, 'always'],
|
||||
'body-max-line-length': [2, 'always', 100],
|
||||
'footer-leading-blank': [1, 'always'],
|
||||
'footer-max-line-length': [2, 'always', 100],
|
||||
'header-max-length': [2, 'always', 100],
|
||||
'scope-case': [2, 'always', 'lower-case'],
|
||||
'subject-case': [
|
||||
2,
|
||||
'never',
|
||||
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
|
||||
],
|
||||
'subject-full-stop': [2, 'never', '.'],
|
||||
'type-case': [2, 'always', 'lower-case'],
|
||||
'type-empty': [2, 'never'],
|
||||
'type-enum': [
|
||||
2,
|
||||
'always',
|
||||
[
|
||||
'feat',
|
||||
'fix',
|
||||
'perf',
|
||||
'revert',
|
||||
'refactor',
|
||||
'build',
|
||||
'ci',
|
||||
'test',
|
||||
'chore',
|
||||
'docs',
|
||||
],
|
||||
],
|
||||
},
|
||||
};
|
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if ! [ -x "$(command -v standard-version)" ]; then
|
||||
echo "standard-version is not installed. please run 'npm i -g standard-version'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
standard-version --dry-run --skip
|
||||
read -p "Continue (y/n)? " -n 1 -r
|
||||
echo ;
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
standard-version -s ;
|
||||
fi
|
@ -0,0 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
if ! [ -x "$(command -v commitlint)" ]; then
|
||||
echo "commitlint is not installed. please run 'npm i -g commitlint'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for commit_hash in $(git log --pretty=format:%H origin/master..HEAD); do
|
||||
commitlint -f ${commit_hash}~1 -t ${commit_hash}
|
||||
done
|
@ -1,129 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
set -e
|
||||
|
||||
untracked="(untracked)"
|
||||
REPO=$(cd $(dirname $0); pwd)
|
||||
COMMIT_SHA=$(git rev-parse --short HEAD)
|
||||
ASSETS="false"
|
||||
BINARY="false"
|
||||
RELEASE=""
|
||||
|
||||
debugInfo () {
|
||||
echo "Repo: $REPO"
|
||||
echo "Build assets: $ASSETS"
|
||||
echo "Build binary: $BINARY"
|
||||
echo "Release: $RELEASE"
|
||||
}
|
||||
|
||||
buildAssets () {
|
||||
cd $REPO
|
||||
rm -rf frontend/dist
|
||||
rm -f http/rice-box.go
|
||||
|
||||
cd $REPO/frontend
|
||||
|
||||
if [ "$CI" = "true" ]; then
|
||||
npm ci
|
||||
else
|
||||
npm install
|
||||
fi
|
||||
|
||||
npm run lint
|
||||
npm run build
|
||||
}
|
||||
|
||||
buildBinary () {
|
||||
if ! [ -x "$(command -v rice)" ]; then
|
||||
go install github.com/GeertJohan/go.rice/rice
|
||||
fi
|
||||
|
||||
cd $REPO/http
|
||||
rm -rf rice-box.go
|
||||
rice embed-go
|
||||
|
||||
cd $REPO
|
||||
go build -a -o filebrowser -ldflags "-s -w -X github.com/filebrowser/filebrowser/v2/version.CommitSHA=$COMMIT_SHA"
|
||||
}
|
||||
|
||||
release () {
|
||||
cd $REPO
|
||||
|
||||
echo "👀 Checking semver format"
|
||||
|
||||
if [ $# -ne 1 ]; then
|
||||
echo "❌ This release script requires a single argument corresponding to the semver to be released. See semver.org"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
GREP="grep"
|
||||
if [ -x "$(command -v ggrep)" ]; then
|
||||
GREP="ggrep"
|
||||
fi
|
||||
|
||||
semver=$(echo "$1" | $GREP -P '^v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)')
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Not valid semver format. See semver.org"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "🧼 Tidying up go modules"
|
||||
go mod tidy
|
||||
|
||||
echo "🐑 Creating a new commit for the new release"
|
||||
git commit --allow-empty -am "chore: version $semver"
|
||||
git tag "$1"
|
||||
git push
|
||||
git push --tags origin
|
||||
|
||||
echo "📦 Done! $semver released."
|
||||
}
|
||||
|
||||
usage() {
|
||||
echo "Usage: $0 [-a] [-c] [-b] [-r <string>]" 1>&2;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
DEBUG="false"
|
||||
|
||||
while getopts "bacr:d" o; do
|
||||
case "${o}" in
|
||||
b)
|
||||
ASSETS="true"
|
||||
BINARY="true"
|
||||
;;
|
||||
a)
|
||||
ASSETS="true"
|
||||
;;
|
||||
c)
|
||||
BINARY="true"
|
||||
;;
|
||||
r)
|
||||
RELEASE=${OPTARG}
|
||||
;;
|
||||
d)
|
||||
DEBUG="true"
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
if [ "$DEBUG" = "true" ]; then
|
||||
debugInfo
|
||||
fi
|
||||
|
||||
if [ "$ASSETS" = "true" ]; then
|
||||
buildAssets
|
||||
fi
|
||||
|
||||
if [ "$BINARY" = "true" ]; then
|
||||
buildBinary
|
||||
fi
|
||||
|
||||
if [ "$RELEASE" != "" ]; then
|
||||
release $RELEASE
|
||||
fi
|
Loading…
Reference in new issue