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
# added, the harder it gets to maintain and manage projects' gitignores. Put
# them into your global gitignore file instead.
@ -8,6 +13,7 @@
# bottom to make sure they take effect.
*.db
*.log
*.out
*.snap
*.test
/agh-backup/
@ -21,6 +27,7 @@
/launchpad_credentials
/querylog.json*
/snapcraft_login
/test-reports/
AdGuardHome
AdGuardHome.exe
AdGuardHome.yaml*

View File

@ -1,14 +1,14 @@
# Keep the Makefile POSIX-compliant. We currently allow hyphens in
# 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:
# This comment is used to simplify checking local copies of the
# Makefile. Bump this number every time a significant change is made to
# this Makefile.
#
# AdGuard-Project-Version: 6
# AdGuard-Project-Version: 9
# Don't name these macros "GO" etc., because GNU Make apparently makes
# them exported environment variables with the literal value of
@ -22,7 +22,6 @@ VERBOSE.MACRO = $${VERBOSE:-0}
CHANNEL = development
CLIENT_DIR = client
COMMIT = $$( git rev-parse --short HEAD )
DEPLOY_SCRIPT_PATH = not/a/real/path
DIST_DIR = dist
GOAMD64 = v1
@ -36,6 +35,7 @@ NPM_FLAGS = --prefix $(CLIENT_DIR)
NPM_INSTALL_FLAGS = $(NPM_FLAGS) --quiet --no-progress --ignore-engines\
--ignore-optional --ignore-platform --ignore-scripts
RACE = 0
REVISION = $${REVISION:-$$(git rev-parse --short HEAD)}
SIGN = 1
SIGNER_API_KEY = not-a-real-key
VERSION = v0.0.0
@ -60,7 +60,6 @@ BUILD_RELEASE_DEPS_1 = go-deps
ENV = env\
CHANNEL='$(CHANNEL)'\
COMMIT='$(COMMIT)'\
DEPLOY_SCRIPT_PATH='$(DEPLOY_SCRIPT_PATH)' \
DIST_DIR='$(DIST_DIR)'\
GO="$(GO.MACRO)"\
@ -70,17 +69,19 @@ ENV = env\
GOTOOLCHAIN='$(GOTOOLCHAIN)'\
GPG_KEY='$(GPG_KEY)'\
GPG_KEY_PASSPHRASE='$(GPG_KEY_PASSPHRASE)'\
NEXTAPI='$(NEXTAPI)'\
PATH="$${PWD}/bin:$$( "$(GO.MACRO)" env GOPATH )/bin:$${PATH}"\
RACE='$(RACE)'\
REVISION='$(REVISION)'\
SIGN='$(SIGN)'\
SIGNER_API_KEY='$(SIGNER_API_KEY)' \
NEXTAPI='$(NEXTAPI)'\
VERBOSE="$(VERBOSE.MACRO)"\
VERSION="$(VERSION)"\
# Keep the line above blank.
ENV_MISC = env\
PATH="$${PWD}/bin:$$("$(GO.MACRO)" env GOPATH)/bin:$${PATH}"\
VERBOSE="$(VERBOSE.MACRO)"\
# Keep the line above blank.
@ -89,6 +90,8 @@ ENV_MISC = env\
# full build.
build: deps quick-build
init: ; git config core.hooksPath ./scripts/hooks
quick-build: js-build go-build
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))
$(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-deps: ; $(NPM) $(NPM_INSTALL_FLAGS) ci
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
# development of the project can be typechecked and built successfully.
go-os-check:
env GOOS='darwin' "$(GO.MACRO)" vet ./internal/...
env GOOS='freebsd' "$(GO.MACRO)" vet ./internal/...
env GOOS='openbsd' "$(GO.MACRO)" vet ./internal/...
env GOOS='linux' "$(GO.MACRO)" vet ./internal/...
env GOOS='windows' "$(GO.MACRO)" vet ./internal/...
openapi-lint: ; cd ./openapi/ && $(YARN) test
openapi-show: ; cd ./openapi/ && $(YARN) start
$(ENV) GOOS='darwin' "$(GO.MACRO)" vet ./internal/...
$(ENV) GOOS='freebsd' "$(GO.MACRO)" vet ./internal/...
$(ENV) GOOS='openbsd' "$(GO.MACRO)" vet ./internal/...
$(ENV) GOOS='linux' "$(GO.MACRO)" vet ./internal/...
$(ENV) GOOS='windows' "$(GO.MACRO)" vet ./internal/...
txt-lint: ; $(ENV) "$(SHELL)" ./scripts/make/txt-lint.sh
md-lint: ; $(ENV_MISC) "$(SHELL)" ./scripts/make/md-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,13 +142,15 @@
# Install Qemu, create builder.
docker version -f '{{ .Server.Experimental }}'
docker buildx rm buildx-builder || :
docker buildx create --name buildx-builder --driver docker-container\
--use
docker buildx create \
--name buildx-builder \
--driver docker-container \
--use
docker buildx inspect --bootstrap
# Login to DockerHub.
docker login -u="${bamboo.dockerHubUsername}"\
-p="${bamboo.dockerHubPassword}"
docker login -u="${bamboo.dockerHubUsername}" \
-p="${bamboo.dockerHubPassword}"
# Boot the builder.
docker buildx inspect --bootstrap
@ -157,14 +159,14 @@
docker info
# Prepare and push the build.
env\
CHANNEL="${bamboo.channel}"\
COMMIT="${bamboo.repository.revision.number}"\
DIST_DIR='dist'\
DOCKER_IMAGE_NAME='adguard/adguardhome'\
DOCKER_OUTPUT="type=image,name=adguard/adguardhome,push=true"\
VERBOSE='1'\
sh ./scripts/make/build-docker.sh
env \
CHANNEL="${bamboo.channel}" \
REVISION="${bamboo.repository.revision.number}" \
DIST_DIR='dist' \
DOCKER_IMAGE_NAME='adguard/adguardhome' \
DOCKER_OUTPUT="type=image,name=adguard/adguardhome,push=true" \
VERBOSE='1' \
sh ./scripts/make/build-docker.sh
'environment':
DOCKER_CLI_EXPERIMENTAL=enabled
'final-tasks':

View File

@ -32,10 +32,10 @@ Required environment:
* `CHANNEL`: release channel, see above.
* `COMMIT`: current Git revision.
* `DIST_DIR`: the directory where a release has previously been built.
* `REVISION`: current Git revision.
* `VERSION`: release version.
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
Optional environment:

View File

@ -65,12 +65,11 @@ func main() {
}).Parse(tmplStr)
errors.Check(err)
f, err := os.OpenFile(
f := errors.Must(os.OpenFile(
"./internal/filtering/servicelist.go",
os.O_CREATE|os.O_TRUNC|os.O_WRONLY,
0o644,
)
errors.Check(err)
))
defer slogutil.CloseAndLog(ctx, l, f, slog.LevelError)
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.
channel="${CHANNEL:?please set CHANNEL}"
commit="${COMMIT:?please set COMMIT}"
commit="${REVISION:?please set REVISION}"
dist_dir="${DIST_DIR:?please set 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

@ -30,7 +30,7 @@ set -f -u
# packages are banned:
#
# * Package errors is replaced by our own package in the
# github.com/AdguardTeam/golibs module.
# github.com/AdguardTeam/golibs module.
#
# * Packages log and github.com/AdguardTeam/golibs/log are replaced by
# stdlib's new package log/slog and AdGuard's new utilities package
@ -95,16 +95,20 @@ blocklist_imports() {
# method_const is a simple check against the usage of some raw strings and
# numbers where one should use named constants.
method_const() {
git grep -F \
-e '"DELETE"' \
-e '"GET"' \
-e '"PATCH"' \
-e '"POST"' \
-e '"PUT"' \
-n \
-- '*.go' \
| sed -e 's/^\([^[:space:]]\+\)\(.*\)$/\1 http method literal:\2/' \
|| exit 0
find . \
-type 'f' \
-name '*.go' \
-exec \
'grep' \
'-H' \
'-e' '"DELETE"' \
'-e' '"GET"' \
'-e' '"PATCH"' \
'-e' '"POST"' \
'-e' '"PUT"' \
'-n' \
'{}' \
';'
}
# 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.
underscores() {
underscore_files="$(
git ls-files '*_*.go' \
| grep -F \
-e '_bsd.go' \
-e '_darwin.go' \
-e '_freebsd.go' \
-e '_generate.go' \
-e '_linux.go' \
-e '_next.go' \
-e '_openbsd.go' \
-e '_others.go' \
-e '_test.go' \
-e '_unix.go' \
-e '_windows.go' \
-v \
| sed -e 's/./\t\0/'
find . \
-type 'f' \
-name '*_*.go' \
'!' '(' -name '*_bsd.go' \
-o -name '*_darwin.go' \
-o -name '*_freebsd.go' \
-o -name '*_generate.go' \
-o -name '*_linux.go' \
-o -name '*_next.go' \
-o -name '*_openbsd.go' \
-o -name '*_others.go' \
-o -name '*_test.go' \
-o -name '*_unix.go' \
-o -name '*_windows.go' \
')' \
-exec 'printf' '\t%s\n' '{}' ';'
)"
readonly underscore_files
if [ "$underscore_files" != '' ]; then
echo 'found file names with underscores:'
echo "$underscore_files"
printf \
'found file names with underscores:\n%s\n' \
"$underscore_files"
fi
}
# TODO(a.garipov): Add an analyzer to look for `fallthrough`, `goto`, and `new`?
# Checks
run_linter -e blocklist_imports
run_linter -e method_const
@ -146,8 +154,6 @@ run_linter -e underscores
run_linter -e gofumpt --extra -e -l .
# TODO(a.garipov): golint is deprecated, find a suitable replacement.
run_linter "${GO:-go}" vet ./...
run_linter govulncheck ./...
@ -216,9 +222,18 @@ run_linter ineffassign ./...
run_linter unparam ./...
git ls-files -- 'Makefile' '*.conf' '*.go' '*.mod' '*.sh' '*.yaml' '*.yml' \
| xargs misspell --error \
| sed -e 's/^/misspell: /'
find . \
-type 'f' \
'(' \
-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 ./...
@ -291,4 +306,4 @@ windows: GOOS=windows
'
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)"
if [ "$version" = '' ]; then
log 'empty version from ./AdGuardHome_amd64'
exit 1
fi
readonly version
@ -51,13 +52,11 @@ for arch in \
>"${snap_dir}/meta/snap.yaml"
# TODO(a.garipov): The snapcraft tool will *always* write everything,
# including errors, to stdout. And there doesn't seem to be a way to
# change that. So, save the combined output, but only show it when
# snapcraft actually fails.
# including errors, to stdout. And there doesn't seem to be a way to change
# that. So, save the combined output, but only show it when snapcraft
# actually fails.
set +e
snapcraft_output="$(
snapcraft pack "$snap_dir" --output "$snap_output" 2>&1
)"
snapcraft_output="$(snapcraft pack "$snap_dir" --output "$snap_output" 2>&1)"
snapcraft_exit_code="$?"
set -e

View File

@ -101,7 +101,7 @@ func main() {
// jsHeader is the header for the generated JavaScript file. It informs the
// 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.
/* eslint quote-props: 'off', quotes: 'off', comma-dangle: 'off', semi: 'off' */