all: imp docs, scripts

This commit is contained in:
Ainar Garipov 2024-11-07 18:20:23 +03:00
parent d2724cfaef
commit 35324db80b
10 changed files with 97 additions and 116 deletions

7
.gitignore vendored
View file

@ -1,3 +1,8 @@
# This comment is used to simplify checking local copies of the file. Bump
# this number every time a significant change is made to this file.
#
# AdGuard-Project-Version: 1
# Please, DO NOT put your text editors' temporary files here. The more are # Please, DO NOT put your text editors' temporary files here. The more are
# added, the harder it gets to maintain and manage projects' gitignores. Put # added, the harder it gets to maintain and manage projects' gitignores. Put
# them into your global gitignore file instead. # them into your global gitignore file instead.
@ -8,6 +13,7 @@
# bottom to make sure they take effect. # bottom to make sure they take effect.
*.db *.db
*.log *.log
*.out
*.snap *.snap
*.test *.test
/agh-backup/ /agh-backup/
@ -21,6 +27,7 @@
/launchpad_credentials /launchpad_credentials
/querylog.json* /querylog.json*
/snapcraft_login /snapcraft_login
/test-reports/
AdGuardHome AdGuardHome
AdGuardHome.exe AdGuardHome.exe
AdGuardHome.yaml* AdGuardHome.yaml*

View file

@ -1,14 +1,14 @@
# Keep the Makefile POSIX-compliant. We currently allow hyphens in # Keep the Makefile POSIX-compliant. We currently allow hyphens in
# target names, but that may change in the future. # target names, but that may change in the future.
# #
# See https://pubs.opengroup.org/onlinepubs/9699919799/utilities/make.html. # See https://pubs.opengroup.org/onlinepubs/9799919799/utilities/make.html.
.POSIX: .POSIX:
# This comment is used to simplify checking local copies of the # This comment is used to simplify checking local copies of the
# Makefile. Bump this number every time a significant change is made to # Makefile. Bump this number every time a significant change is made to
# this Makefile. # this Makefile.
# #
# AdGuard-Project-Version: 6 # AdGuard-Project-Version: 9
# Don't name these macros "GO" etc., because GNU Make apparently makes # Don't name these macros "GO" etc., because GNU Make apparently makes
# them exported environment variables with the literal value of # them exported environment variables with the literal value of
@ -22,7 +22,6 @@ VERBOSE.MACRO = $${VERBOSE:-0}
CHANNEL = development CHANNEL = development
CLIENT_DIR = client CLIENT_DIR = client
COMMIT = $$( git rev-parse --short HEAD )
DEPLOY_SCRIPT_PATH = not/a/real/path DEPLOY_SCRIPT_PATH = not/a/real/path
DIST_DIR = dist DIST_DIR = dist
GOAMD64 = v1 GOAMD64 = v1
@ -36,6 +35,7 @@ NPM_FLAGS = --prefix $(CLIENT_DIR)
NPM_INSTALL_FLAGS = $(NPM_FLAGS) --quiet --no-progress --ignore-engines\ NPM_INSTALL_FLAGS = $(NPM_FLAGS) --quiet --no-progress --ignore-engines\
--ignore-optional --ignore-platform --ignore-scripts --ignore-optional --ignore-platform --ignore-scripts
RACE = 0 RACE = 0
REVISION = $${REVISION:-$$(git rev-parse --short HEAD)}
SIGN = 1 SIGN = 1
SIGNER_API_KEY = not-a-real-key SIGNER_API_KEY = not-a-real-key
VERSION = v0.0.0 VERSION = v0.0.0
@ -60,7 +60,6 @@ BUILD_RELEASE_DEPS_1 = go-deps
ENV = env\ ENV = env\
CHANNEL='$(CHANNEL)'\ CHANNEL='$(CHANNEL)'\
COMMIT='$(COMMIT)'\
DEPLOY_SCRIPT_PATH='$(DEPLOY_SCRIPT_PATH)' \ DEPLOY_SCRIPT_PATH='$(DEPLOY_SCRIPT_PATH)' \
DIST_DIR='$(DIST_DIR)'\ DIST_DIR='$(DIST_DIR)'\
GO="$(GO.MACRO)"\ GO="$(GO.MACRO)"\
@ -70,17 +69,19 @@ ENV = env\
GOTOOLCHAIN='$(GOTOOLCHAIN)'\ GOTOOLCHAIN='$(GOTOOLCHAIN)'\
GPG_KEY='$(GPG_KEY)'\ GPG_KEY='$(GPG_KEY)'\
GPG_KEY_PASSPHRASE='$(GPG_KEY_PASSPHRASE)'\ GPG_KEY_PASSPHRASE='$(GPG_KEY_PASSPHRASE)'\
NEXTAPI='$(NEXTAPI)'\
PATH="$${PWD}/bin:$$( "$(GO.MACRO)" env GOPATH )/bin:$${PATH}"\ PATH="$${PWD}/bin:$$( "$(GO.MACRO)" env GOPATH )/bin:$${PATH}"\
RACE='$(RACE)'\ RACE='$(RACE)'\
REVISION='$(REVISION)'\
SIGN='$(SIGN)'\ SIGN='$(SIGN)'\
SIGNER_API_KEY='$(SIGNER_API_KEY)' \ SIGNER_API_KEY='$(SIGNER_API_KEY)' \
NEXTAPI='$(NEXTAPI)'\
VERBOSE="$(VERBOSE.MACRO)"\ VERBOSE="$(VERBOSE.MACRO)"\
VERSION="$(VERSION)"\ VERSION="$(VERSION)"\
# Keep the line above blank. # Keep the line above blank.
ENV_MISC = env\ ENV_MISC = env\
PATH="$${PWD}/bin:$$("$(GO.MACRO)" env GOPATH)/bin:$${PATH}"\
VERBOSE="$(VERBOSE.MACRO)"\ VERBOSE="$(VERBOSE.MACRO)"\
# Keep the line above blank. # Keep the line above blank.
@ -89,6 +90,8 @@ ENV_MISC = env\
# full build. # full build.
build: deps quick-build build: deps quick-build
init: ; git config core.hooksPath ./scripts/hooks
quick-build: js-build go-build quick-build: js-build go-build
deps: js-deps go-deps deps: js-deps go-deps
@ -102,9 +105,6 @@ build-docker: ; $(ENV) "$(SHELL)" ./scripts/make/build-docker.sh
build-release: $(BUILD_RELEASE_DEPS_$(FRONTEND_PREBUILT)) build-release: $(BUILD_RELEASE_DEPS_$(FRONTEND_PREBUILT))
$(ENV) "$(SHELL)" ./scripts/make/build-release.sh $(ENV) "$(SHELL)" ./scripts/make/build-release.sh
clean: ; $(ENV) "$(SHELL)" ./scripts/make/clean.sh
init: ; git config core.hooksPath ./scripts/hooks
js-build: ; $(NPM) $(NPM_FLAGS) run build-prod js-build: ; $(NPM) $(NPM_FLAGS) run build-prod
js-deps: ; $(NPM) $(NPM_INSTALL_FLAGS) ci js-deps: ; $(NPM) $(NPM_INSTALL_FLAGS) ci
js-lint: ; $(NPM) $(NPM_FLAGS) run lint js-lint: ; $(NPM) $(NPM_FLAGS) run lint
@ -127,17 +127,16 @@ go-check: go-tools go-lint go-test
# A quick check to make sure that all operating systems relevant to the # A quick check to make sure that all operating systems relevant to the
# development of the project can be typechecked and built successfully. # development of the project can be typechecked and built successfully.
go-os-check: go-os-check:
env GOOS='darwin' "$(GO.MACRO)" vet ./internal/... $(ENV) GOOS='darwin' "$(GO.MACRO)" vet ./internal/...
env GOOS='freebsd' "$(GO.MACRO)" vet ./internal/... $(ENV) GOOS='freebsd' "$(GO.MACRO)" vet ./internal/...
env GOOS='openbsd' "$(GO.MACRO)" vet ./internal/... $(ENV) GOOS='openbsd' "$(GO.MACRO)" vet ./internal/...
env GOOS='linux' "$(GO.MACRO)" vet ./internal/... $(ENV) GOOS='linux' "$(GO.MACRO)" vet ./internal/...
env GOOS='windows' "$(GO.MACRO)" vet ./internal/... $(ENV) GOOS='windows' "$(GO.MACRO)" vet ./internal/...
openapi-lint: ; cd ./openapi/ && $(YARN) test
openapi-show: ; cd ./openapi/ && $(YARN) start
txt-lint: ; $(ENV) "$(SHELL)" ./scripts/make/txt-lint.sh txt-lint: ; $(ENV) "$(SHELL)" ./scripts/make/txt-lint.sh
md-lint: ; $(ENV_MISC) "$(SHELL)" ./scripts/make/md-lint.sh md-lint: ; $(ENV_MISC) "$(SHELL)" ./scripts/make/md-lint.sh
sh-lint: ; $(ENV_MISC) "$(SHELL)" ./scripts/make/sh-lint.sh sh-lint: ; $(ENV_MISC) "$(SHELL)" ./scripts/make/sh-lint.sh
openapi-lint: ; cd ./openapi/ && $(YARN) test
openapi-show: ; cd ./openapi/ && $(YARN) start

View file

@ -142,12 +142,14 @@
# Install Qemu, create builder. # Install Qemu, create builder.
docker version -f '{{ .Server.Experimental }}' docker version -f '{{ .Server.Experimental }}'
docker buildx rm buildx-builder || : docker buildx rm buildx-builder || :
docker buildx create --name buildx-builder --driver docker-container\ docker buildx create \
--name buildx-builder \
--driver docker-container \
--use --use
docker buildx inspect --bootstrap docker buildx inspect --bootstrap
# Login to DockerHub. # Login to DockerHub.
docker login -u="${bamboo.dockerHubUsername}"\ docker login -u="${bamboo.dockerHubUsername}" \
-p="${bamboo.dockerHubPassword}" -p="${bamboo.dockerHubPassword}"
# Boot the builder. # Boot the builder.
@ -157,13 +159,13 @@
docker info docker info
# Prepare and push the build. # Prepare and push the build.
env\ env \
CHANNEL="${bamboo.channel}"\ CHANNEL="${bamboo.channel}" \
COMMIT="${bamboo.repository.revision.number}"\ REVISION="${bamboo.repository.revision.number}" \
DIST_DIR='dist'\ DIST_DIR='dist' \
DOCKER_IMAGE_NAME='adguard/adguardhome'\ DOCKER_IMAGE_NAME='adguard/adguardhome' \
DOCKER_OUTPUT="type=image,name=adguard/adguardhome,push=true"\ DOCKER_OUTPUT="type=image,name=adguard/adguardhome,push=true" \
VERBOSE='1'\ VERBOSE='1' \
sh ./scripts/make/build-docker.sh sh ./scripts/make/build-docker.sh
'environment': 'environment':
DOCKER_CLI_EXPERIMENTAL=enabled DOCKER_CLI_EXPERIMENTAL=enabled

View file

@ -32,10 +32,10 @@ Required environment:
* `CHANNEL`: release channel, see above. * `CHANNEL`: release channel, see above.
* `COMMIT`: current Git revision.
* `DIST_DIR`: the directory where a release has previously been built. * `DIST_DIR`: the directory where a release has previously been built.
* `REVISION`: current Git revision.
* `VERSION`: release version. * `VERSION`: release version.
Optional environment: Optional environment:
@ -105,18 +105,6 @@ and call `make` with `GOTOOLCHAIN=local`.
### `clean.sh`: Cleanup
Optional environment:
* `GO`: set an alternative name for the Go compiler.
Required environment:
* `DIST_DIR`: the directory where a release has previously been built.
### `go-bench.sh`: Run backend benchmarks ### `go-bench.sh`: Run backend benchmarks
Optional environment: Optional environment:

View file

@ -65,12 +65,11 @@ func main() {
}).Parse(tmplStr) }).Parse(tmplStr)
errors.Check(err) errors.Check(err)
f, err := os.OpenFile( f := errors.Must(os.OpenFile(
"./internal/filtering/servicelist.go", "./internal/filtering/servicelist.go",
os.O_CREATE|os.O_TRUNC|os.O_WRONLY, os.O_CREATE|os.O_TRUNC|os.O_WRONLY,
0o644, 0o644,
) ))
errors.Check(err)
defer slogutil.CloseAndLog(ctx, l, f, slog.LevelError) defer slogutil.CloseAndLog(ctx, l, f, slog.LevelError)
errors.Check(tmpl.Execute(f, hlSvcs)) errors.Check(tmpl.Execute(f, hlSvcs))

View file

@ -15,7 +15,7 @@ set -e -f -u
# Require these to be set. The channel value is validated later. # Require these to be set. The channel value is validated later.
channel="${CHANNEL:?please set CHANNEL}" channel="${CHANNEL:?please set CHANNEL}"
commit="${COMMIT:?please set COMMIT}" commit="${REVISION:?please set REVISION}"
dist_dir="${DIST_DIR:?please set DIST_DIR}" dist_dir="${DIST_DIR:?please set DIST_DIR}"
readonly channel commit dist_dir readonly channel commit dist_dir

View file

@ -1,28 +0,0 @@
#!/bin/sh
verbose="${VERBOSE:-0}"
readonly verbose
if [ "$verbose" -gt '0' ]; then
set -x
fi
set -e -f -u
dist_dir="${DIST_DIR:?please set DIST_DIR}"
sudo_cmd="${SUDO:-}"
readonly dist_dir sudo_cmd
$sudo_cmd rm -f \
./AdGuardHome \
./AdGuardHome.exe \
./coverage.txt \
;
$sudo_cmd rm -f -r \
./bin/ \
./build/static/ \
./client/node_modules/ \
./data/ \
"./${dist_dir}/" \
;

View file

@ -95,16 +95,20 @@ blocklist_imports() {
# method_const is a simple check against the usage of some raw strings and # method_const is a simple check against the usage of some raw strings and
# numbers where one should use named constants. # numbers where one should use named constants.
method_const() { method_const() {
git grep -F \ find . \
-e '"DELETE"' \ -type 'f' \
-e '"GET"' \ -name '*.go' \
-e '"PATCH"' \ -exec \
-e '"POST"' \ 'grep' \
-e '"PUT"' \ '-H' \
-n \ '-e' '"DELETE"' \
-- '*.go' \ '-e' '"GET"' \
| sed -e 's/^\([^[:space:]]\+\)\(.*\)$/\1 http method literal:\2/' \ '-e' '"PATCH"' \
|| exit 0 '-e' '"POST"' \
'-e' '"PUT"' \
'-n' \
'{}' \
';'
} }
# underscores is a simple check against Go filenames with underscores. Add new # underscores is a simple check against Go filenames with underscores. Add new
@ -112,32 +116,36 @@ method_const() {
# use of filenames like client_manager.go. # use of filenames like client_manager.go.
underscores() { underscores() {
underscore_files="$( underscore_files="$(
git ls-files '*_*.go' \ find . \
| grep -F \ -type 'f' \
-e '_bsd.go' \ -name '*_*.go' \
-e '_darwin.go' \ '!' '(' -name '*_bsd.go' \
-e '_freebsd.go' \ -o -name '*_darwin.go' \
-e '_generate.go' \ -o -name '*_freebsd.go' \
-e '_linux.go' \ -o -name '*_generate.go' \
-e '_next.go' \ -o -name '*_linux.go' \
-e '_openbsd.go' \ -o -name '*_next.go' \
-e '_others.go' \ -o -name '*_openbsd.go' \
-e '_test.go' \ -o -name '*_others.go' \
-e '_unix.go' \ -o -name '*_test.go' \
-e '_windows.go' \ -o -name '*_unix.go' \
-v \ -o -name '*_windows.go' \
| sed -e 's/./\t\0/' ')' \
-exec 'printf' '\t%s\n' '{}' ';'
)" )"
readonly underscore_files readonly underscore_files
if [ "$underscore_files" != '' ]; then if [ "$underscore_files" != '' ]; then
echo 'found file names with underscores:' printf \
echo "$underscore_files" 'found file names with underscores:\n%s\n' \
"$underscore_files"
fi fi
} }
# TODO(a.garipov): Add an analyzer to look for `fallthrough`, `goto`, and `new`? # TODO(a.garipov): Add an analyzer to look for `fallthrough`, `goto`, and `new`?
# Checks
run_linter -e blocklist_imports run_linter -e blocklist_imports
run_linter -e method_const run_linter -e method_const
@ -146,8 +154,6 @@ run_linter -e underscores
run_linter -e gofumpt --extra -e -l . run_linter -e gofumpt --extra -e -l .
# TODO(a.garipov): golint is deprecated, find a suitable replacement.
run_linter "${GO:-go}" vet ./... run_linter "${GO:-go}" vet ./...
run_linter govulncheck ./... run_linter govulncheck ./...
@ -216,9 +222,18 @@ run_linter ineffassign ./...
run_linter unparam ./... run_linter unparam ./...
git ls-files -- 'Makefile' '*.conf' '*.go' '*.mod' '*.sh' '*.yaml' '*.yml' \ find . \
| xargs misspell --error \ -type 'f' \
| sed -e 's/^/misspell: /' '(' \
-name 'Makefile' \
-o -name '*.conf' \
-o -name '*.go' \
-o -name '*.mod' \
-o -name '*.sh' \
-o -name '*.yaml' \
-o -name '*.yml' \
')' \
-exec 'misspell' '--error' '{}' '+'
run_linter nilness ./... run_linter nilness ./...
@ -291,4 +306,4 @@ windows: GOOS=windows
' '
readonly staticcheck_matrix readonly staticcheck_matrix
echo "$staticcheck_matrix" | run_linter staticcheck --matrix ./... printf '%s' "$staticcheck_matrix" | run_linter staticcheck --matrix ./...

View file

@ -22,6 +22,7 @@ log() {
version="$(./AdGuardHome_amd64 --version | cut -d ' ' -f 4)" version="$(./AdGuardHome_amd64 --version | cut -d ' ' -f 4)"
if [ "$version" = '' ]; then if [ "$version" = '' ]; then
log 'empty version from ./AdGuardHome_amd64' log 'empty version from ./AdGuardHome_amd64'
exit 1 exit 1
fi fi
readonly version readonly version
@ -51,13 +52,11 @@ for arch in \
>"${snap_dir}/meta/snap.yaml" >"${snap_dir}/meta/snap.yaml"
# TODO(a.garipov): The snapcraft tool will *always* write everything, # TODO(a.garipov): The snapcraft tool will *always* write everything,
# including errors, to stdout. And there doesn't seem to be a way to # including errors, to stdout. And there doesn't seem to be a way to change
# change that. So, save the combined output, but only show it when # that. So, save the combined output, but only show it when snapcraft
# snapcraft actually fails. # actually fails.
set +e set +e
snapcraft_output="$( snapcraft_output="$(snapcraft pack "$snap_dir" --output "$snap_output" 2>&1)"
snapcraft pack "$snap_dir" --output "$snap_output" 2>&1
)"
snapcraft_exit_code="$?" snapcraft_exit_code="$?"
set -e set -e

View file

@ -101,7 +101,7 @@ func main() {
// jsHeader is the header for the generated JavaScript file. It informs the // jsHeader is the header for the generated JavaScript file. It informs the
// reader that the file is generated and disables some style-related eslint // reader that the file is generated and disables some style-related eslint
// errors.Checks. // checks.
const jsHeader = `// Code generated by go run ./scripts/vetted-filters/main.go; DO NOT EDIT. const jsHeader = `// Code generated by go run ./scripts/vetted-filters/main.go; DO NOT EDIT.
/* eslint quote-props: 'off', quotes: 'off', comma-dangle: 'off', semi: 'off' */ /* eslint quote-props: 'off', quotes: 'off', comma-dangle: 'off', semi: 'off' */