Skip to content

Commit

Permalink
all: imp docs, scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Nov 7, 2024
1 parent d2724cf commit 35324db
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 116 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -8,6 +13,7 @@
# bottom to make sure they take effect.
*.db
*.log
*.out
*.snap
*.test
/agh-backup/
Expand All @@ -21,6 +27,7 @@
/launchpad_credentials
/querylog.json*
/snapcraft_login
/test-reports/
AdGuardHome
AdGuardHome.exe
AdGuardHome.yaml*
Expand Down
33 changes: 16 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)"\
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
26 changes: 14 additions & 12 deletions bamboo-specs/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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':
Expand Down
16 changes: 2 additions & 14 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions scripts/blocked-services/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion scripts/make/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
28 changes: 0 additions & 28 deletions scripts/make/clean.sh

This file was deleted.

83 changes: 49 additions & 34 deletions scripts/make/go-lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,49 +95,57 @@ 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
# build tags and OS as you go. The main goal of this check is to discourage the
# 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
Expand All @@ -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 ./...
Expand Down Expand Up @@ -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 ./...

Expand Down Expand Up @@ -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 ./...
Loading

0 comments on commit 35324db

Please sign in to comment.