2022-09-08 02:40:17 +10:00
# This is the Coder Makefile. The build directory for most tasks is `build/`.
#
# These are the targets you're probably looking for:
# - clean
# - build-fat: builds all "fat" binaries for all architectures
# - build-slim: builds all "slim" binaries (no frontend or slim binaries
# embedded) for all architectures
# - release: simulate a release (mostly, does not push images)
# - build/coder(-slim)?_${os}_${arch}(.exe)?: build a single fat binary
# - build/coder_${os}_${arch}.(zip|tar.gz): build a release archive
# - build/coder_linux_${arch}.(apk|deb|rpm): build a release Linux package
# - build/coder_${version}_linux_${arch}.tag: build a release Linux Docker image
# - build/coder_helm.tgz: build a release Helm chart
.DEFAULT_GOAL := build-fat
2022-05-02 14:04:45 -05:00
2022-06-18 14:47:10 -05:00
# Use a single bash shell for each job, and immediately exit on failure
SHELL := bash
2022-09-08 02:40:17 +10:00
.SHELLFLAGS := -ceu
2022-06-18 14:47:10 -05:00
.ONESHELL :
2026-03-09 23:07:33 +02:00
# When MAKE_TIMED=1, replace SHELL with a wrapper that prints
2026-03-12 12:13:55 +02:00
# elapsed wall-clock time for each recipe. pre-commit and pre-push
# set this on their sub-makes so every parallel job reports its
# duration. Ad-hoc usage: make MAKE_TIMED=1 test
2026-03-09 23:07:33 +02:00
ifdef MAKE_TIMED
SHELL := $( CURDIR) /scripts/lib/timed-shell.sh
.SHELLFLAGS = $@ -ceu
export MAKE_TIMED
2026-03-12 11:16:31 +02:00
export MAKE_LOGDIR
2026-03-09 23:07:33 +02:00
endif
2022-06-18 14:47:10 -05:00
# This doesn't work on directories.
# See https://stackoverflow.com/questions/25752543/make-delete-on-error-for-directory-targets
.DELETE_ON_ERROR :
2026-03-05 13:58:10 +02:00
# Protect git-tracked generated files from deletion on interrupt.
# .DELETE_ON_ERROR is desirable for most targets but for files that
# are committed to git and serve as inputs to other rules, deletion
# is worse than a stale file — `git restore` is the recovery path.
.PRECIOUS : \
coderd /database /dump .sql \
coderd /database /querier .go \
coderd /database /unique_constraint .go \
coderd /database /dbmetrics /querymetrics .go \
coderd /database /dbauthz /dbauthz .go \
2026-03-05 22:32:18 +02:00
coderd /database /dbmock /dbmock .go \
coderd /database /pubsub /psmock /psmock .go \
agent /agentcontainers /acmock /acmock .go \
coderd /httpmw /loggermw /loggermock /loggermock .go \
codersdk /workspacesdk /agentconnmock /agentconnmock .go \
tailnet /tailnettest /coordinatormock .go \
tailnet /tailnettest /coordinateemock .go \
tailnet /tailnettest /workspaceupdatesprovidermock .go \
tailnet /tailnettest /subscriptionmock .go \
2026-05-22 09:11:37 +02:00
coderd /aibridged /aibridgedmock /clientmock .go \
coderd /aibridged /aibridgedmock /poolmock .go \
2026-03-05 22:32:18 +02:00
tailnet /proto /tailnet .pb .go \
agent /proto /agent .pb .go \
agent /agentsocket /proto /agentsocket .pb .go \
agent /boundarylogproxy /codec /boundary .pb .go \
provisionersdk /proto /provisioner .pb .go \
provisionerd /proto /provisionerd .pb .go \
vpn /vpn .pb .go \
2026-05-22 09:11:37 +02:00
coderd /aibridged /proto /aibridged .pb .go \
2026-03-05 13:58:10 +02:00
site /src /api /typesGenerated .ts \
site /e 2e /provisionerGenerated .ts \
site /src /api /chatModelOptionsGenerated .json \
site /src /api /rbacresourcesGenerated .ts \
site /src /api /countriesGenerated .ts \
site /src /theme /icons .json \
examples /examples .gen .json \
docs /manifest .json \
docs /admin /integrations /prometheus .md \
docs /admin /security /audit -logs .md \
2026-08-03 14:33:01 -04:00
docs /admin /setup /configuration -reference .md \
2026-03-05 13:58:10 +02:00
docs /reference /cli /index .md \
coderd /apidoc /swagger .json \
coderd /rbac /object_gen .go \
coderd /rbac /scopes_constants_gen .go \
codersdk /rbacresources_gen .go \
codersdk /apikey_scopes_gen .go
2026-03-05 22:32:18 +02:00
# atomic_write runs a command, captures stdout into a temp file, and
# atomically replaces $@. An optional second argument is a formatting
# command that receives the temp file path as its argument.
# Usage: $(call atomic_write,GENERATE_CMD[,FORMAT_CMD])
define atomic_write
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && \
$( 1) > " $$ tmpfile" && \
$(if $( 2) ,$( 2) " $$ tmpfile" && ) \
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
endef
2026-04-15 12:59:07 +10:00
# CLI doc generation reflects over the assembled CLI tree. Track command
# definitions plus the top-level SDK types they expose in help text and flag
# values, without pulling in unrelated generated sources.
CLIDOC_SRC_FILES := \
$( shell find ./cli ./enterprise/cli -type f -name '*.go' -not -name '*_test.go' ) \
$( wildcard codersdk/*.go) \
$( wildcard buildinfo/*.go)
CLIDOCGEN_INPUTS := \
$( wildcard scripts/clidocgen/*.go) \
2026-07-08 11:39:45 -04:00
$( filter-out %_test.go,$( wildcard scripts/docgenenv/*.go)) \
2026-04-15 12:59:07 +10:00
scripts/clidocgen/command.tpl \
$( CLIDOC_SRC_FILES)
2026-05-06 11:57:36 +10:00
# Helper binaries that import repo packages need their compile-time inputs on
# the binary target. Most generated outputs keep these binaries as order-only
# prereqs, so stale binaries otherwise survive source changes.
RBAC_GO_FILES := \
$( wildcard coderd/rbac/*.go) \
$( wildcard coderd/rbac/policy/*.go)
DBDUMP_INPUTS := \
$( wildcard coderd/database/migrations/*.go) \
$( wildcard coderd/database/migrations/*.sql)
# Exclude generated RBAC files to avoid cycles with typegen outputs. The
# output rules still order generated RBAC prerequisites where needed.
TYPEGEN_RBAC_GO_FILES := \
$( filter-out coderd/rbac/%_gen.go,$( wildcard coderd/rbac/*.go)) \
$( wildcard coderd/rbac/policy/*.go)
TYPEGEN_INPUTS := \
$( wildcard scripts/typegen/*.go) \
$( wildcard scripts/typegen/*.gotmpl) \
$( wildcard scripts/typegen/*.tstmpl) \
$( TYPEGEN_RBAC_GO_FILES) \
$( wildcard coderd/util/strings/*.go) \
codersdk/countries.go
2026-04-09 16:04:06 +02:00
# Helper binary targets. Built with go build -o to avoid caching
# link-stage executables in GOCACHE. Each binary is a real Make
# target so parallel -j builds serialize correctly instead of
# racing on the same output path.
2026-05-06 11:57:36 +10:00
_gen/bin/apitypings : $( wildcard scripts /apitypings /*.go ) $( wildcard codersdk /*.go ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/apitypings
2026-05-06 11:57:36 +10:00
_gen/bin/auditdocgen : $( wildcard scripts /auditdocgen /*.go ) $( wildcard enterprise /audit /*.go ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/auditdocgen
2026-05-06 11:57:36 +10:00
_gen/bin/check-scopes : $( wildcard scripts /check -scopes /*.go ) $( RBAC_GO_FILES ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/check-scopes
2026-04-15 12:59:07 +10:00
# clidocgen reflects over the full CLI tree, so it must rebuild when its
# command definitions, flag types, or embedded template change.
_gen/bin/clidocgen : $( CLIDOCGEN_INPUTS ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/clidocgen
2026-08-03 14:33:01 -04:00
# configdocgen reflects over codersdk.DeploymentValues to produce the
# configuration reference page.
_gen/bin/configdocgen : $( wildcard scripts /configdocgen /*.go ) $( wildcard codersdk /*.go ) | _gen
@mkdir -p _gen/bin
go build -o $@ ./scripts/configdocgen
2026-05-06 11:57:36 +10:00
_gen/bin/dbdump : $( wildcard coderd /database /gen /dump /*.go ) $( DBDUMP_INPUTS ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./coderd/database/gen/dump
_gen/bin/examplegen : $( wildcard scripts /examplegen /*.go ) | _gen
@mkdir -p _gen/bin
go build -o $@ ./scripts/examplegen
_gen/bin/gensite : $( wildcard scripts /gensite /*.go ) | _gen
@mkdir -p _gen/bin
go build -o $@ ./scripts/gensite
2026-05-06 11:57:36 +10:00
_gen/bin/apikeyscopesgen : $( wildcard scripts /apikeyscopesgen /*.go ) $( RBAC_GO_FILES ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/apikeyscopesgen
2026-07-14 20:36:27 +01:00
_gen/bin/aibridgepricesgen : $( wildcard scripts /aibridgepricesgen /*.go ) scripts /aibridgepricesgen /curation .json | _gen
2026-05-08 16:45:14 -04:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/aibridgepricesgen
2026-04-09 16:04:06 +02:00
_gen/bin/metricsdocgen : $( wildcard scripts /metricsdocgen /*.go ) | _gen
@mkdir -p _gen/bin
go build -o $@ ./scripts/metricsdocgen
_gen/bin/metricsdocgen-scanner : $( wildcard scripts /metricsdocgen /scanner /*.go ) | _gen
@mkdir -p _gen/bin
go build -o $@ ./scripts/metricsdocgen/scanner
2026-04-22 00:11:09 +10:00
_gen/bin/modeloptionsgen : $( wildcard scripts /modeloptionsgen /*.go ) $( wildcard codersdk /*.go ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/modeloptionsgen
2026-05-06 11:57:36 +10:00
_gen/bin/typegen : $( TYPEGEN_INPUTS ) | _gen
2026-04-09 16:04:06 +02:00
@mkdir -p _gen/bin
go build -o $@ ./scripts/typegen
2026-03-05 22:32:18 +02:00
# Shared temp directory for atomic writes. Lives at the project root
# so all targets share the same filesystem, and is gitignored.
# Order-only prerequisite: recipes that need it depend on | _gen
_gen :
mkdir -p _gen
2022-09-08 02:40:17 +10:00
# Don't print the commands in the file unless you specify VERBOSE. This is
# essentially the same as putting "@" at the start of each line.
ifndef VERBOSE
.SILENT :
endif
2022-02-10 20:32:00 -08:00
2022-09-08 02:40:17 +10:00
# Create the output directories if they do not exist.
$( shell mkdir -p build site /out /bin )
2022-05-02 14:04:45 -05:00
2022-09-08 02:40:17 +10:00
GOOS := $( shell go env GOOS)
GOARCH := $( shell go env GOARCH)
GOOS_BIN_EXT := $(if $( filter windows, $( GOOS)) ,.exe,)
VERSION := $( shell ./scripts/version.sh)
2025-06-11 23:06:31 +10:00
POSTGRES_VERSION ?= 17
POSTGRES_IMAGE ?= us-docker.pkg.dev/coder-v2-images-public/public/postgres:$( POSTGRES_VERSION)
2026-09-08 09:53:17 -07:00
# CI test jobs set this to "none": nothing reads the statement log there.
TEST_POSTGRES_LOG_STATEMENT ?= all
2022-09-08 02:40:17 +10:00
2026-03-12 12:13:55 +02:00
# Limit parallel Make jobs in pre-commit/pre-push. Defaults to
# nproc/4 (min 2) since test, lint, and build targets have internal
# parallelism. Override: make pre-push PARALLEL_JOBS=8
2026-03-09 19:26:34 +02:00
PARALLEL_JOBS ?= $( shell n = $$ ( nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 8) ; echo $$ (( n / 4 > 2 ? n / 4 : 2 )))
2026-03-10 08:54:32 -07:00
# Use the highest ZSTD compression level in release builds to
# minimize artifact size. For non-release CI builds (e.g. main
# branch preview), use multithreaded level 6 which is ~99% faster
# at the cost of ~30% larger archives.
ifeq ( $( CODER_RELEASE ) ,true)
2022-09-16 18:36:11 +03:00
ZSTDFLAGS := -22 --ultra
2022-09-17 02:03:16 +10:00
else
2026-03-10 08:54:32 -07:00
ZSTDFLAGS := -6 -T0
2022-09-17 02:03:16 +10:00
endif
2022-09-16 18:36:11 +03:00
2022-12-19 14:41:36 +02:00
# Common paths to exclude from find commands, this rule is written so
# that it can be it can be used in a chain of AND statements (meaning
# you can simply write `find . $(FIND_EXCLUSIONS) -name thing-i-want`).
# Note, all find statements should be written with `.` or `./path` as
# the search path so that these exclusions match.
FIND_EXCLUSIONS = \
2026-03-06 16:56:11 +02:00
-not \( \( -path '*/.git/*' -o -path './build/*' -o -path './vendor/*' -o -path './.coderv2/*' -o -path '*/node_modules/*' -o -path '*/out/*' -o -path './coderd/apidoc/*' -o -path '*/.next/*' -o -path '*/.terraform/*' -o -path './_gen/*' \) -prune \)
2026-03-17 15:34:03 +02:00
2022-11-09 18:39:42 +02:00
# Source files used for make targets, evaluated on use.
2023-07-06 10:59:08 +03:00
GO_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.go' -not -name '*_test.go' )
2026-03-17 15:34:03 +02:00
2022-11-09 18:39:42 +02:00
# All the shell files in the repo, excluding ignored files.
2023-06-14 13:17:16 -05:00
SHELL_SRC_FILES := $( shell find . $( FIND_EXCLUSIONS) -type f -name '*.sh' )
2022-11-09 18:39:42 +02:00
2026-01-15 14:17:16 +02:00
MIGRATION_FILES := $( shell find ./coderd/database/migrations/ -maxdepth 1 $( FIND_EXCLUSIONS) -type f -name '*.sql' )
FIXTURE_FILES := $( shell find ./coderd/database/migrations/testdata/fixtures/ $( FIND_EXCLUSIONS) -type f -name '*.sql' )
2024-05-10 16:35:59 +02:00
# Ensure we don't use the user's git configs which might cause side-effects
GIT_FLAGS = GIT_CONFIG_GLOBAL = /dev/null GIT_CONFIG_SYSTEM = /dev/null
2022-09-08 02:40:17 +10:00
# All ${OS}_${ARCH} combos we build for. Windows binaries have the .exe suffix.
OS_ARCHES := \
linux_amd64 linux_arm64 linux_armv7 \
darwin_amd64 darwin_arm64 \
windows_amd64.exe windows_arm64.exe
# Archive formats and their corresponding ${OS}_${ARCH} combos.
ARCHIVE_TAR_GZ := linux_amd64 linux_arm64 linux_armv7
ARCHIVE_ZIP := \
darwin_amd64 darwin_arm64 \
windows_amd64 windows_arm64
# All package formats we build and the ${OS}_${ARCH} combos we build them for.
PACKAGE_FORMATS := apk deb rpm
PACKAGE_OS_ARCHES := linux_amd64 linux_armv7 linux_arm64
# All architectures we build Docker images for (Linux only).
DOCKER_ARCHES := amd64 arm64 armv7
# Computed variables based on the above.
CODER_SLIM_BINARIES := $( addprefix build/coder-slim_$( VERSION) _,$( OS_ARCHES))
CODER_FAT_BINARIES := $( addprefix build/coder_$( VERSION) _,$( OS_ARCHES))
CODER_ALL_BINARIES := $( CODER_SLIM_BINARIES) $( CODER_FAT_BINARIES)
CODER_TAR_GZ_ARCHIVES := $( foreach os_arch, $( ARCHIVE_TAR_GZ) , build/coder_$( VERSION) _$( os_arch) .tar.gz)
CODER_ZIP_ARCHIVES := $( foreach os_arch, $( ARCHIVE_ZIP) , build/coder_$( VERSION) _$( os_arch) .zip)
CODER_ALL_ARCHIVES := $( CODER_TAR_GZ_ARCHIVES) $( CODER_ZIP_ARCHIVES)
CODER_ALL_PACKAGES := $( foreach os_arch, $( PACKAGE_OS_ARCHES) , $( addprefix build/coder_$( VERSION) _$( os_arch) .,$( PACKAGE_FORMATS)))
CODER_ARCH_IMAGES := $( foreach arch, $( DOCKER_ARCHES) , build/coder_$( VERSION) _linux_$( arch) .tag)
CODER_ARCH_IMAGES_PUSHED := $( addprefix push/, $( CODER_ARCH_IMAGES))
CODER_MAIN_IMAGE := build/coder_$( VERSION) _linux.tag
CODER_SLIM_NOVERSION_BINARIES := $( addprefix build/coder-slim_,$( OS_ARCHES))
CODER_FAT_NOVERSION_BINARIES := $( addprefix build/coder_,$( OS_ARCHES))
CODER_ALL_NOVERSION_IMAGES := $( foreach arch, $( DOCKER_ARCHES) , build/coder_linux_$( arch) .tag) build/coder_linux.tag
CODER_ALL_NOVERSION_IMAGES_PUSHED := $( addprefix push/, $( CODER_ALL_NOVERSION_IMAGES))
2023-01-16 11:43:37 -06:00
# If callers are only building Docker images and not the packages and archives,
# we can skip those prerequisites as they are not actually required and only
# specified to avoid concurrent write failures.
ifdef DOCKER_IMAGE_NO_PREREQUISITES
CODER_ARCH_IMAGE_PREREQUISITES :=
else
CODER_ARCH_IMAGE_PREREQUISITES := \
build/coder_$( VERSION) _%.apk \
build/coder_$( VERSION) _%.deb \
build/coder_$( VERSION) _%.rpm \
build/coder_$( VERSION) _%.tar.gz
endif
2022-09-08 02:40:17 +10:00
clean :
2023-09-29 13:08:17 -06:00
rm -rf build/ site/build/ site/out/
2026-04-09 16:04:06 +02:00
rm -rf _gen/bin
2025-02-24 10:43:03 -07:00
mkdir -p build/
2023-09-29 13:08:17 -06:00
git restore site/out/
2022-09-08 02:40:17 +10:00
.PHONY : clean
build-slim : $( CODER_SLIM_BINARIES )
.PHONY : build -slim
build-fat build-full build : $( CODER_FAT_BINARIES )
.PHONY : build -fat build -full build
release : $( CODER_FAT_BINARIES ) $( CODER_ALL_ARCHIVES ) $( CODER_ALL_PACKAGES ) $( CODER_ARCH_IMAGES ) build /coder_helm_ $( VERSION ) .tgz
.PHONY : release
2022-12-15 18:36:37 +02:00
build/coder-slim_$(VERSION)_checksums.sha1 : site /out /bin /coder .sha 1
cp " $<" " $@ "
site/out/bin/coder.sha1 : $( CODER_SLIM_BINARIES )
2022-09-08 02:40:17 +10:00
pushd ./site/out/bin
openssl dgst -r -sha1 coder-* | tee coder.sha1
popd
build/coder-slim_$(VERSION).tar : build /coder -slim_ $( VERSION ) _checksums .sha 1 $( CODER_SLIM_BINARIES )
pushd ./site/out/bin
tar cf "../../../build/ $( @F) " coder-*
popd
2022-12-21 22:59:49 +02:00
# delete the uncompressed binaries from the embedded dir
rm -f site/out/bin/coder-*
2022-12-15 18:36:37 +02:00
site/out/bin/coder.tar.zst : build /coder -slim_ $( VERSION ) .tar .zst
cp " $<" " $@ "
build/coder-slim_$(VERSION).tar.zst : build /coder -slim_ $( VERSION ) .tar
2022-09-16 18:36:11 +03:00
zstd $( ZSTDFLAGS) \
2022-09-08 02:40:17 +10:00
--force \
--long \
--no-progress \
-o "build/coder-slim_ $( VERSION) .tar.zst" \
"build/coder-slim_ $( VERSION) .tar"
# Redirect from version-less targets to the versioned ones. There is a similar
# target for slim binaries below.
#
# Called like this:
# make build/coder_linux_amd64
# make build/coder_windows_amd64.exe
$(CODER_FAT_NOVERSION_BINARIES) : build /coder_ %: build /coder_ $( VERSION ) _ %
rm -f " $@ "
ln " $<" " $@ "
# Same as above, but for slim binaries.
#
# Called like this:
# make build/coder-slim_linux_amd64
# make build/coder-slim_windows_amd64.exe
$(CODER_SLIM_NOVERSION_BINARIES) : build /coder -slim_ %: build /coder -slim_ $( VERSION ) _ %
rm -f " $@ "
ln " $<" " $@ "
# "fat" binaries always depend on the site and the compressed slim binaries.
$(CODER_FAT_BINARIES) : \
site /out /index .html \
site /out /bin /coder .sha 1 \
site /out /bin /coder .tar .zst
# This is a handy block that parses the target to determine whether it's "slim"
# or "fat", which OS was specified and which architecture was specified.
#
# It populates the following variables: mode, os, arch_ext, arch, ext (without
# dot).
define get-mode-os-arch-ext =
mode = " $$ ([[ " $@ " = build/coder-slim* ]] && echo " slim" || echo " fat")"
os = " $$ (echo $@ | cut -d_ -f3)"
arch_ext = " $$ (echo $@ | cut -d_ -f4)"
if [[ " $$ arch_ext" == *.* ]] ; then
arch = " $$ (echo $$ arch_ext | cut -d. -f1)"
ext = " $$ {arch_ext#*.}"
else
arch = " $$ arch_ext"
ext = ""
fi
endef
# This task handles all builds, for both "fat" and "slim" binaries. It parses
# the target name to get the metadata for the build, so it must be specified in
# this format:
# build/coder(-slim)?_${version}_${os}_${arch}(.exe)?
#
# You should probably use the non-version targets above instead if you're
# calling this manually.
$(CODER_ALL_BINARIES) : go .mod go .sum \
2022-11-09 18:39:42 +02:00
$( GO_SRC_FILES ) \
2024-04-26 11:52:53 -04:00
$( shell find ./examples /templates ) \
site /static /error .html
2022-09-08 02:40:17 +10:00
$( get-mode-os-arch-ext)
if [[ " $$ os" != "windows" ]] && [[ " $$ ext" != "" ]] ; then
echo "ERROR: Invalid build binary extension" 1>& 2
exit 1
fi
if [[ " $$ os" == "windows" ]] && [[ " $$ ext" != exe ]] ; then
echo "ERROR: Windows binaries must have an .exe extension." 1>& 2
exit 1
fi
build_args =( \
--os " $$ os" \
--arch " $$ arch" \
2022-06-18 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
--output " $@ " \
)
if [ " $$ mode" == "slim" ] ; then
build_args +=( --slim)
fi
2022-06-18 14:47:10 -05:00
2022-09-08 02:40:17 +10:00
./scripts/build_go.sh " $$ {build_args[@]}"
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
if [[ " $$ mode" == "slim" ]] ; then
dot_ext = ""
if [[ " $$ ext" != "" ]] ; then
dot_ext = ". $$ ext"
fi
2022-06-18 14:47:10 -05:00
2022-09-08 02:40:17 +10:00
cp " $@ " "./site/out/bin/coder- $$ os- $$ arch $$ dot_ext"
2025-07-09 11:53:27 +02:00
if [[ " $$ {CODER_SIGN_GPG:-0}" == "1" ]] ; then
cp " $@ .asc" "./site/out/bin/coder- $$ os- $$ arch $$ dot_ext.asc"
fi
2022-09-08 02:40:17 +10:00
fi
# This task builds all archives. It parses the target name to get the metadata
# for the build, so it must be specified in this format:
# build/coder_${version}_${os}_${arch}.${format}
#
# The following OS/arch/format combinations are supported:
# .tar.gz: linux_amd64, linux_arm64, linux_armv7
# .zip: darwin_amd64, darwin_arm64, windows_amd64, windows_arm64
#
# This depends on all fat binaries because it's difficult to do dynamic
# dependencies due to the .exe requirement on Windows. These targets are
# typically only used during release anyways.
$(CODER_ALL_ARCHIVES) : $( CODER_FAT_BINARIES )
$( get-mode-os-arch-ext)
bin_ext = ""
if [[ " $$ os" == "windows" ]] ; then
bin_ext = ".exe"
fi
./scripts/archive.sh \
--format " $$ ext" \
--os " $$ os" \
--output " $@ " \
"build/coder_ $( VERSION) _ $$ {os}_ $$ {arch} $$ {bin_ext}"
# This task builds all packages. It parses the target name to get the metadata
# for the build, so it must be specified in this format:
# build/coder_${version}_linux_${arch}.${format}
#
# Supports apk, deb, rpm for all linux targets.
#
# This depends on all Linux fat binaries and archives because it's difficult to
# do dynamic dependencies due to the extensions in the filenames. These targets
# are typically only used during release anyways.
#
# Packages need to run after the archives are built, otherwise they cause tar
# errors like "file changed as we read it".
CODER_PACKAGE_DEPS := $( foreach os_arch, $( PACKAGE_OS_ARCHES) , build/coder_$( VERSION) _$( os_arch) build/coder_$( VERSION) _$( os_arch) .tar.gz)
$(CODER_ALL_PACKAGES) : $( CODER_PACKAGE_DEPS )
$( get-mode-os-arch-ext)
./scripts/package.sh \
--arch " $$ arch" \
--format " $$ ext" \
2022-06-18 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
--output " $@ " \
"build/coder_ $( VERSION) _ $$ {os}_ $$ {arch}"
2022-06-18 14:47:10 -05:00
2022-10-26 00:19:54 +10:00
# This task builds a Windows amd64 installer. Depends on makensis.
build/coder_$(VERSION)_windows_amd64_installer.exe : build /coder_ $( VERSION ) _windows_amd 64.exe
./scripts/build_windows_installer.sh \
--version " $( VERSION) " \
--output " $@ " \
" $<"
2022-09-08 02:40:17 +10:00
# Redirect from version-less Docker image targets to the versioned ones.
#
# Called like this:
# make build/coder_linux_amd64.tag
$(CODER_ALL_NOVERSION_IMAGES) : build /coder_ %: build /coder_ $( VERSION ) _ %
.PHONY : $( CODER_ALL_NOVERSION_IMAGES )
# Redirect from version-less push Docker image targets to the versioned ones.
#
# Called like this:
# make push/build/coder_linux_amd64.tag
$(CODER_ALL_NOVERSION_IMAGES_PUSHED) : push /build /coder_ %: push /build /coder_ $( VERSION ) _ %
.PHONY : $( CODER_ALL_NOVERSION_IMAGES_PUSHED )
# This task builds all Docker images. It parses the target name to get the
# metadata for the build, so it must be specified in this format:
# build/coder_${version}_${os}_${arch}.tag
#
# Supports linux_amd64, linux_arm64, linux_armv7.
#
# Images need to run after the archives and packages are built, otherwise they
# cause errors like "file changed as we read it".
2023-01-16 11:43:37 -06:00
$(CODER_ARCH_IMAGES) : build /coder_ $( VERSION ) _ %.tag : build /coder_ $( VERSION ) _ % $( CODER_ARCH_IMAGE_PREREQUISITES )
2022-09-08 02:40:17 +10:00
$( get-mode-os-arch-ext)
image_tag = " $$ (./scripts/image_tag.sh --arch " $$ arch" --version " $( VERSION) ")"
./scripts/build_docker.sh \
--arch " $$ arch" \
--target " $$ image_tag" \
2022-06-18 14:47:10 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
"build/coder_ $( VERSION) _ $$ {os}_ $$ {arch}"
2022-01-18 13:13:19 -08:00
2022-09-08 02:40:17 +10:00
echo " $$ image_tag" > " $@ "
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
# Multi-arch Docker image. This requires all architecture-specific images to be
# built AND pushed.
$(CODER_MAIN_IMAGE) : $( CODER_ARCH_IMAGES_PUSHED )
image_tag = " $$ (./scripts/image_tag.sh --version " $( VERSION) ")"
./scripts/build_docker_multiarch.sh \
--target " $$ image_tag" \
2022-09-01 14:58:23 -05:00
--version " $( VERSION) " \
2022-09-08 02:40:17 +10:00
$( foreach img, $^, " $$ (cat " $( img:push/%= %) ")" )
2022-09-01 14:58:23 -05:00
2022-09-08 02:40:17 +10:00
echo " $$ image_tag" > " $@ "
# Push a Docker image.
$(CODER_ARCH_IMAGES_PUSHED) : push /%: %
image_tag = " $$ (cat " $<")"
docker push " $$ image_tag"
.PHONY : $( CODER_ARCH_IMAGES_PUSHED )
# Push the multi-arch Docker manifest.
push/$(CODER_MAIN_IMAGE) : $( CODER_MAIN_IMAGE )
image_tag = " $$ (cat " $<")"
docker manifest push " $$ image_tag"
.PHONY : push /$( CODER_MAIN_IMAGE )
2023-08-16 16:26:38 +04:00
# Helm charts that are available
2026-07-22 17:42:42 +02:00
charts = coder provisioner ai-gateway
2023-08-16 16:26:38 +04:00
2022-09-08 02:40:17 +10:00
# Shortcut for Helm chart package.
2023-08-16 16:26:38 +04:00
$(foreach chart,$(charts),build/$(chart)_helm.tgz) : build /%_helm .tgz : build /%_helm_ $( VERSION ) .tgz
2022-09-08 02:40:17 +10:00
rm -f " $@ "
ln " $<" " $@ "
# Helm chart package.
2023-08-16 16:26:38 +04:00
$(foreach chart,$(charts),build/$(chart)_helm_$(VERSION).tgz) : build /%_helm_ $( VERSION ) .tgz :
2022-09-08 02:40:17 +10:00
./scripts/helm.sh \
2022-09-01 14:58:23 -05:00
--version " $( VERSION) " \
2023-08-16 16:26:38 +04:00
--chart $* \
2022-09-08 02:40:17 +10:00
--output " $@ "
2022-09-01 14:58:23 -05:00
2025-03-21 15:33:07 +02:00
node_modules/.installed : package .json pnpm -lock .yaml
2025-01-03 05:37:25 -08:00
./scripts/pnpm_install.sh
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 15:33:07 +02:00
offlinedocs/node_modules/.installed : offlinedocs /package .json offlinedocs /pnpm -lock .yaml
( cd offlinedocs/ && ../scripts/pnpm_install.sh)
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 15:33:07 +02:00
site/node_modules/.installed : site /package .json site /pnpm -lock .yaml
( cd site/ && ../scripts/pnpm_install.sh)
touch " $@ "
2025-01-03 05:37:25 -08:00
2025-03-21 17:16:17 +02:00
scripts/apidocgen/node_modules/.installed : scripts /apidocgen /package .json scripts /apidocgen /pnpm -lock .yaml
( cd scripts/apidocgen && ../../scripts/pnpm_install.sh)
touch " $@ "
2025-01-14 11:30:39 -07:00
SITE_GEN_FILES := \
site/src/api/typesGenerated.ts \
site/src/api/rbacresourcesGenerated.ts \
site/src/api/countriesGenerated.ts \
2026-03-03 16:29:58 -05:00
site/src/api/chatModelOptionsGenerated.json \
2025-01-14 11:30:39 -07:00
site/src/theme/icons.json
site/out/index.html : \
site /node_modules /.installed \
site /static /install .sh \
$( SITE_GEN_FILES ) \
$( shell find ./site $( FIND_EXCLUSIONS ) -type f \( -name '*.ts ' -o -name '*.tsx ' \))
2025-01-03 12:27:26 -08:00
cd site/
2024-02-27 10:45:57 -07:00
# prevents this directory from getting to big, and causing "too much data" errors
rm -rf out/assets/
2023-08-02 13:28:16 -05:00
pnpm build
2022-01-05 09:20:56 -06:00
2025-01-03 05:37:25 -08:00
offlinedocs/out/index.html : offlinedocs /node_modules /.installed $( shell find ./offlinedocs $( FIND_EXCLUSIONS ) -type f ) $( shell find ./docs $( FIND_EXCLUSIONS ) -type f | sed 's : :\\ :g ')
2025-01-03 12:27:26 -08:00
cd offlinedocs/
2023-08-02 13:28:16 -05:00
../scripts/pnpm_install.sh
pnpm export
2023-07-19 13:57:57 -03:00
build/coder_docs_$(VERSION).tgz : offlinedocs /out /index .html
tar -czf " $@ " -C offlinedocs/out .
2022-09-08 02:40:17 +10:00
install : build /coder_ $( VERSION ) _ $( GOOS ) _ $( GOARCH )$( GOOS_BIN_EXT )
install_dir = " $$ (go env GOPATH)/bin"
output_file = " $$ {install_dir}/coder $( GOOS_BIN_EXT) "
mkdir -p " $$ install_dir"
cp " $<" " $$ output_file"
.PHONY : install
2026-03-17 15:34:03 +02:00
# Only wildcard the go files in the develop directory to avoid rebuilds
# when project files are changd. Technically changes to some imports may
# not be detected, but it's unlikely to cause any issues.
build/.bin/develop : go .mod go .sum $( wildcard scripts /develop /*.go )
2026-03-16 16:13:57 +02:00
CGO_ENABLED = 0 go build -o $@ ./scripts/develop
2024-04-05 11:45:32 -06:00
BOLD := $( shell tput bold 2>/dev/null)
GREEN := $( shell tput setaf 2 2>/dev/null)
2026-03-12 11:16:31 +02:00
RED := $( shell tput setaf 1 2>/dev/null)
YELLOW := $( shell tput setaf 3 2>/dev/null)
DIM := $( shell tput dim 2>/dev/null || tput setaf 8 2>/dev/null)
2024-04-05 11:45:32 -06:00
RESET := $( shell tput sgr0 2>/dev/null)
2024-03-05 16:31:22 -07:00
2025-01-03 18:12:59 +05:00
fmt : fmt /ts fmt /go fmt /terraform fmt /shfmt fmt /biome fmt /markdown
2022-09-08 02:40:17 +10:00
.PHONY : fmt
2022-01-05 09:20:56 -06:00
2026-03-20 17:05:44 +02:00
# Subset of fmt that does not require Go or Node toolchains.
fmt-light : fmt /shfmt fmt /terraform fmt /markdown
.PHONY : fmt -light
2023-02-18 18:32:09 -06:00
fmt/go :
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.go ]] && ! grep -q "DO NOT EDIT" " $( FILE) " ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/go $( RESET) $( FILE) " ; \
2026-01-08 15:36:03 +04:00
./scripts/format_go_file.sh " $( FILE) " ; \
2025-07-03 18:51:23 +02:00
fi
else
2024-09-24 21:39:34 +10:00
go mod tidy
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/go$(RESET)"
2023-02-18 18:32:09 -06:00
# VS Code users should check out
# https://github.com/mvdan/gofumpt#visual-studio-code
2024-12-30 12:56:22 +02:00
find . $( FIND_EXCLUSIONS) -type f -name '*.go' -print0 | \
2025-07-03 11:28:00 -06:00
xargs -0 grep -E --null -L '^// Code generated .* DO NOT EDIT\.$$' | \
2026-01-08 15:36:03 +04:00
xargs -0 ./scripts/format_go_file.sh
2025-07-03 18:51:23 +02:00
endif
2023-02-18 18:32:09 -06:00
.PHONY : fmt /go
2025-01-03 05:37:25 -08:00
fmt/ts : site /node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single TypeScript/JavaScript file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.ts ]] || [[ " $( FILE) " == *.tsx ]] || [[ " $( FILE) " == *.js ]] || [[ " $( FILE) " == *.jsx ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/ts $( RESET) $( FILE) " ; \
( cd site/ && pnpm exec biome format --write "../ $( FILE) " ) ; \
fi
else
2024-08-15 13:26:29 -06:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/ts$(RESET)"
2024-03-05 16:31:22 -07:00
cd site
2024-08-15 13:26:29 -06:00
# Avoid writing files in CI to reduce file write activity
ifdef CI
pnpm run check --linter-enabled = false
else
pnpm run check : fix
endif
2025-07-03 18:51:23 +02:00
endif
2024-08-15 13:26:29 -06:00
.PHONY : fmt /ts
2024-03-05 16:31:22 -07:00
2025-01-03 05:37:25 -08:00
fmt/biome : site /node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single file with biome
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.ts ]] || [[ " $( FILE) " == *.tsx ]] || [[ " $( FILE) " == *.js ]] || [[ " $( FILE) " == *.jsx ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/biome $( RESET) $( FILE) " ; \
( cd site/ && pnpm exec biome format --write "../ $( FILE) " ) ; \
fi
else
2025-01-03 18:12:59 +05:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/biome$(RESET)"
2025-01-03 12:27:26 -08:00
cd site/
2022-01-03 18:54:27 -08:00
# Avoid writing files in CI to reduce file write activity
ifdef CI
2023-08-02 13:28:16 -05:00
pnpm run format : check
2022-01-03 18:54:27 -08:00
else
2024-03-05 16:31:22 -07:00
pnpm run format
2022-01-03 18:54:27 -08:00
endif
2025-07-03 18:51:23 +02:00
endif
2025-01-03 18:12:59 +05:00
.PHONY : fmt /biome
2022-01-03 18:54:27 -08:00
2022-04-11 16:06:15 -05:00
fmt/terraform : $( wildcard *.tf )
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single Terraform file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.tf ]] || [[ " $( FILE) " == *.tfvars ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/terraform $( RESET) $( FILE) " ; \
terraform fmt " $( FILE) " ; \
fi
else
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/terraform$(RESET)"
2022-04-11 16:06:15 -05:00
terraform fmt -recursive
2025-07-03 18:51:23 +02:00
endif
2022-05-02 14:04:45 -05:00
.PHONY : fmt /terraform
2022-04-11 16:06:15 -05:00
2022-11-09 18:39:42 +02:00
fmt/shfmt : $( SHELL_SRC_FILES )
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single shell script
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.sh ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/shfmt $( RESET) $( FILE) " ; \
shfmt -w " $( FILE) " ; \
fi
else
2024-03-05 16:31:22 -07:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/shfmt$(RESET)"
2022-05-27 20:15:19 +03:00
# Only do diff check in CI, errors on diff.
ifdef CI
2022-11-09 18:39:42 +02:00
shfmt -d $( SHELL_SRC_FILES )
2022-05-27 20:15:19 +03:00
else
2022-11-09 18:39:42 +02:00
shfmt -w $( SHELL_SRC_FILES )
2022-05-27 20:15:19 +03:00
endif
2025-07-03 18:51:23 +02:00
endif
2022-06-18 14:47:10 -05:00
.PHONY : fmt /shfmt
2022-05-27 20:15:19 +03:00
2025-01-03 05:37:25 -08:00
fmt/markdown : node_modules /.installed
2025-07-03 18:51:23 +02:00
ifdef FILE
# Format single markdown file
if [[ -f " $( FILE) " ]] && [[ " $( FILE) " == *.md ]] ; then \
echo " $( GREEN) ==> $( RESET) $( BOLD) fmt/markdown $( RESET) $( FILE) " ; \
pnpm exec markdown-table-formatter " $( FILE) " ; \
fi
else
2025-01-03 18:12:59 +05:00
echo "$(GREEN)==>$(RESET) $(BOLD)fmt/markdown$(RESET)"
pnpm format-docs
2025-07-03 18:51:23 +02:00
endif
2025-01-03 18:12:59 +05:00
.PHONY : fmt /markdown
2026-02-02 05:32:09 -08:00
# Note: we don't run zizmor in the lint target because it takes a while.
# GitHub Actions linters are run in a separate CI job (lint-actions) that only
# triggers when workflow files change, so we skip them here when CI=true.
LINT_ACTIONS_TARGETS := $(if $( CI) ,,lint/actions/actionlint)
2026-08-05 14:45:45 -04:00
lint : lint /shellcheck lint /go lint /ts lint /examples lint /helm lint /site -icons lint /markdown lint /docs -html lint /check -scopes lint /migrations lint /bootstrap lint /architecture lint /emdash lint /agents lint /mise -versions $( LINT_ACTIONS_TARGETS )
2022-06-18 14:47:10 -05:00
.PHONY : lint
2022-05-27 20:15:19 +03:00
2026-06-01 15:55:19 +02:00
# Fast lint subset for lightweight hooks. Some targets use mise-managed tools.
lint-light : lint /shellcheck lint /markdown lint /helm lint /bootstrap lint /migrations lint /actions /actionlint lint /typos lint /emdash lint /mise -versions
2026-03-20 17:05:44 +02:00
.PHONY : lint -light
2023-07-23 16:27:11 -05:00
lint/site-icons :
./scripts/check_site_icons.sh
.PHONY : lint /site -icons
2025-01-03 05:37:25 -08:00
lint/ts : site /node_modules /.installed
2025-01-03 12:27:26 -08:00
cd site/
2024-08-15 13:26:29 -06:00
pnpm lint
2023-06-12 12:09:54 -05:00
.PHONY : lint /ts
2026-08-03 19:49:22 +02:00
# Cap cold-cache golangci-lint on high-core hosts to stay below memory limits.
GO_LINT_CONCURRENCY := $( shell n = $$ ( nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 1) ; echo $$ (( n < 8 ? n : 8 )))
GO_LINT_MEMLIMIT ?= 8GiB
2022-05-27 20:15:19 +03:00
lint/go :
2026-08-03 19:49:22 +02:00
GOMEMLIMIT = " $$ {GOMEMLIMIT:- $( GO_LINT_MEMLIMIT) }" golangci-lint run --concurrency= " $( GO_LINT_CONCURRENCY) "
2026-06-01 15:55:19 +02:00
paralleltestctx -custom-funcs= "testutil.Context,chatdTestContext" ./...
2026-04-17 00:07:30 +10:00
go run ./scripts/intxcheck ./...
2022-05-27 20:15:19 +03:00
.PHONY : lint /go
2026-04-09 16:04:06 +02:00
lint/examples : | _gen /bin /examplegen
_gen/bin/examplegen -lint
2024-03-14 16:49:44 +02:00
.PHONY : lint /examples
2022-05-27 20:15:19 +03:00
# Use shfmt to determine the shell files, takes editorconfig into consideration.
2022-11-09 18:39:42 +02:00
lint/shellcheck : $( SHELL_SRC_FILES )
2022-09-08 02:40:17 +10:00
echo "--- shellcheck"
2022-11-09 18:39:42 +02:00
shellcheck --external-sources $( SHELL_SRC_FILES)
2022-06-18 14:47:10 -05:00
.PHONY : lint /shellcheck
2022-03-28 14:21:00 -06:00
2026-03-06 13:09:56 +01:00
lint/bootstrap :
bash scripts/check_bootstrap_quotes.sh
.PHONY : lint /bootstrap
2026-04-21 13:55:24 +03:00
lint/emdash :
bash scripts/check_emdash.sh
.PHONY : lint /emdash
2026-08-05 14:45:45 -04:00
# Fails when docs Markdown contains invalid inline HTML the docs site drops or
# mangles: swallowed angle-bracket placeholders (e.g. <region>), void-element
# end tags (</br>), capitalized or unregistered component tags (e.g. <Image>),
# and unclosed container tags.
lint/docs-html :
echo "--- check for invalid inline HTML in docs"
go run ./scripts/docshtmlcheck
.PHONY : lint /docs -html
2026-05-11 17:27:29 +02:00
lint/architecture :
./scripts/check_architecture.sh
.PHONY : lint /architecture
lint/agents :
./scripts/check_agents_structure.sh
.PHONY : lint /agents
2026-03-06 13:09:56 +01:00
2023-06-12 12:09:54 -05:00
lint/helm :
2025-01-03 12:27:26 -08:00
cd helm/
2023-06-12 12:09:54 -05:00
make lint
.PHONY : lint /helm
2025-01-03 05:37:25 -08:00
lint/markdown : node_modules /.installed
2025-01-03 18:12:59 +05:00
pnpm lint-docs
.PHONY : lint /markdown
2025-08-21 22:14:43 +10:00
lint/actions : lint /actions /actionlint lint /actions /zizmor
.PHONY : lint /actions
lint/actions/actionlint :
2026-07-31 02:42:49 +02:00
mise exec "go:github.com/rhysd/actionlint/cmd/actionlint" -- actionlint
2025-08-21 22:14:43 +10:00
.PHONY : lint /actions /actionlint
2026-06-01 15:55:19 +02:00
# zizmor uses GH_TOKEN to fetch imported workflows from GitHub; without it,
# external action references are skipped silently.
2025-08-21 22:14:43 +10:00
lint/actions/zizmor :
2026-06-01 15:55:19 +02:00
@set -euo pipefail; \
if [ -z " $$ {GH_TOKEN:-}" ] && command -v gh >/dev/null 2>& 1; then \
GH_TOKEN = " $$ (gh auth token 2>/dev/null || true)" ; \
export GH_TOKEN; \
fi ; \
mise exec zizmor -- zizmor \
2025-08-21 22:14:43 +10:00
--strict-collection \
--persona= regular \
.
.PHONY : lint /actions /zizmor
2025-09-24 18:06:16 +02:00
2026-06-01 15:55:19 +02:00
lint/mise-versions :
./scripts/check_mise_versions.sh
.PHONY : lint /mise -versions
2025-09-24 18:06:16 +02:00
# Verify api_key_scope enum contains all RBAC <resource>:<action> values.
2026-04-09 16:04:06 +02:00
lint/check-scopes : coderd /database /dump .sql | _gen /bin /check -scopes
_gen/bin/check-scopes
2025-09-24 18:06:16 +02:00
.PHONY : lint /check -scopes
2025-08-21 22:14:43 +10:00
2026-01-15 14:17:16 +02:00
# Verify migrations do not hardcode the public schema.
lint/migrations :
./scripts/check_pg_schema.sh "Migrations" $( MIGRATION_FILES)
./scripts/check_pg_schema.sh "Fixtures" $( FIXTURE_FILES)
.PHONY : lint /migrations
2026-06-01 15:55:19 +02:00
lint/typos :
typos --config .github/workflows/typos.toml
2026-03-06 16:56:11 +02:00
.PHONY : lint /typos
2026-06-22 14:14:31 -04:00
# Vale (prose linter).
#
# Invoked through `mise exec` like actionlint and zizmor above, so the
# version pinned in mise.toml ("aqua:errata-ai/vale") is the single source
# of truth and mise downloads the right OS/arch build. Always pass the full
# aqua key: the bare `vale` short name ignores the pin and resolves to the
# latest release.
# `vale sync` pulls the packages listed in .vale.ini's Packages directive
# into StylesPath (docs/.style/styles/). The .vale-synced sentinel makes
# sync idempotent across `make lint/prose` calls and lets warm checkouts
# skip the re-sync entirely. Make rebuilds this target when `.vale.ini`
# changes.
docs/.style/.vale-synced : .vale .ini
@echo " $( GREEN) ==> $( RESET) $( BOLD) vale sync $( RESET) "
mise exec "aqua:errata-ai/vale" -- vale sync
@touch $@
# Vale exits non-zero only on error-level alerts. `--no-exit` keeps the
# target green while the un-overridden Google error-level rules still
# produce a baseline error count; real failures (bad config, missing
# files) still propagate. Once the baseline error count reaches zero, drop
# `--no-exit` and surface error-level violations as real failures. See
# DOCS-40.
lint/prose : docs /.style /.vale -synced
@echo " $( GREEN) ==> $( RESET) $( BOLD) lint/prose $( RESET) "
mise exec "aqua:errata-ai/vale" -- vale --no-exit docs/
.PHONY : lint /prose
2026-03-12 12:13:55 +02:00
# pre-commit and pre-push mirror CI checks locally.
2026-03-06 16:56:11 +02:00
#
2026-03-12 12:13:55 +02:00
# pre-commit runs checks that don't need external services (Docker,
2026-03-11 17:44:19 +01:00
# Playwright). This is the git pre-commit hook default since Docker
# and browser issues in the local environment would otherwise block
2026-03-06 16:56:11 +02:00
# all commits.
#
2026-03-12 12:13:55 +02:00
# pre-push adds heavier checks: Go tests, JS tests, and site build.
2026-09-08 12:04:16 +03:00
# Storybook tests are deliberately excluded: the vitest browser run
# has repeatedly stalled or failed for developers running pre-push,
# and PR #24703's serialization did not fix it. Storybook stays
# covered by the storybook job in CI (storybook:build plus Pixel
# snapshots) on every PR.
2026-03-12 12:13:55 +02:00
# The pre-push hook is allowlisted, see scripts/githooks/pre-push.
#
2026-03-11 17:44:19 +01:00
# pre-commit uses two phases: gen+fmt first, then lint+build. This
2026-04-09 16:04:06 +02:00
# avoids races where gen creates temporary .go files that lint's
# find-based checks pick up. Within each phase, targets run in
2026-03-11 17:44:19 +01:00
# parallel via -j. It fails if any tracked files have unstaged
# changes afterward.
2026-03-06 16:56:11 +02:00
define check-unstaged
unstaged = " $$ (git diff --name-only)"
if [[ -n $$ unstaged ]] ; then
2026-03-12 11:16:31 +02:00
echo " $( RED) ✗ check unstaged changes $( RESET) "
echo " $$ unstaged" | sed 's/^/ - /'
echo ""
echo " $( DIM) Verify generated changes are correct before staging: $( RESET) "
echo " $( DIM) git diff $( RESET) "
echo " $( DIM) git add -u && git commit $( RESET) "
2026-03-06 16:56:11 +02:00
exit 1
fi
2026-03-12 11:16:31 +02:00
endef
define check-untracked
2026-03-06 16:56:11 +02:00
untracked = $$ ( git ls-files --other --exclude-standard)
if [[ -n $$ untracked ]] ; then
2026-03-12 11:16:31 +02:00
echo " $( YELLOW) ? check untracked files $( RESET) "
echo " $$ untracked" | sed 's/^/ - /'
echo ""
echo " $( DIM) Review if these should be committed or added to .gitignore. $( RESET) "
2026-03-06 16:56:11 +02:00
fi
endef
pre-commit :
2026-03-09 19:26:34 +02:00
start = $$ ( date +%s)
2026-03-12 11:16:31 +02:00
logdir = $$ ( mktemp -d " $$ {TMPDIR:-/tmp}/coder-pre-commit.XXXXXX" )
echo " $( BOLD) pre-commit $( RESET) ( $$ logdir)"
echo "gen + fmt:"
$( MAKE) --no-print-directory -j$( PARALLEL_JOBS) MAKE_TIMED = 1 MAKE_LOGDIR = $$ logdir gen fmt
2026-03-06 16:56:11 +02:00
$( check-unstaged)
2026-03-12 11:16:31 +02:00
echo "lint + build:"
$( MAKE) --no-print-directory -j$( PARALLEL_JOBS) MAKE_TIMED = 1 MAKE_LOGDIR = $$ logdir \
2026-03-06 16:56:11 +02:00
lint \
lint/typos \
build/coder-slim_$( GOOS) _$( GOARCH)$( GOOS_BIN_EXT)
$( check-unstaged)
2026-03-12 11:16:31 +02:00
$( check-untracked)
rm -rf $$ logdir
echo " $( GREEN) ✓ pre-commit passed $( RESET) ( $$ (( $$ (date +%s) - $$ start ))s)"
2026-03-06 16:56:11 +02:00
.PHONY : pre -commit
2026-03-20 17:05:44 +02:00
# Lightweight pre-commit for changes that don't touch Go or
# TypeScript. Skips gen, lint/go, lint/ts, fmt/go, fmt/ts, and
# the binary build. Used by the pre-commit hook when only docs,
# shell, terraform, helm, or other fast-to-check files changed.
pre-commit-light :
start = $$ ( date +%s)
logdir = $$ ( mktemp -d " $$ {TMPDIR:-/tmp}/coder-pre-commit-light.XXXXXX" )
echo " $( BOLD) pre-commit-light $( RESET) ( $$ logdir)"
echo "fmt:"
$( MAKE) --no-print-directory -j$( PARALLEL_JOBS) MAKE_TIMED = 1 MAKE_LOGDIR = $$ logdir fmt-light
$( check-unstaged)
echo "lint:"
$( MAKE) --no-print-directory -j$( PARALLEL_JOBS) MAKE_TIMED = 1 MAKE_LOGDIR = $$ logdir lint-light
$( check-unstaged)
$( check-untracked)
rm -rf $$ logdir
echo " $( GREEN) ✓ pre-commit-light passed $( RESET) ( $$ (( $$ (date +%s) - $$ start ))s)"
.PHONY : pre -commit -light
2026-03-12 12:13:55 +02:00
pre-push :
start = $$ ( date +%s)
logdir = $$ ( mktemp -d " $$ {TMPDIR:-/tmp}/coder-pre-push.XXXXXX" )
echo " $( BOLD) pre-push $( RESET) ( $$ logdir)"
echo "test + build site:"
$( MAKE) --no-print-directory -j$( PARALLEL_JOBS) MAKE_TIMED = 1 MAKE_LOGDIR = $$ logdir \
test \
test-js \
site/out/index.html
rm -rf $$ logdir
echo " $( GREEN) ✓ pre-push passed $( RESET) ( $$ (( $$ (date +%s) - $$ start ))s)"
.PHONY : pre -push
2026-03-06 16:56:11 +02:00
offlinedocs/check : offlinedocs /node_modules /.installed
cd offlinedocs/
pnpm format:check
pnpm lint
pnpm export
.PHONY : offlinedocs /check
2023-07-06 10:59:08 +03:00
# All files generated by the database should be added here, and this can be used
# as a target for jobs that need to run after the database is generated.
DB_GEN_FILES := \
2025-01-13 13:08:16 +02:00
coderd/database/dump.sql \
2023-07-06 10:59:08 +03:00
coderd/database/querier.go \
coderd/database/unique_constraint.go \
2026-03-05 13:58:10 +02:00
coderd/database/dbmetrics/querymetrics.go \
2023-07-06 10:59:08 +03:00
coderd/database/dbauthz/dbauthz.go \
coderd/database/dbmock/dbmock.go
2024-11-18 10:54:11 +04:00
TAILNETTEST_MOCKS := \
tailnet/tailnettest/coordinatormock.go \
tailnet/tailnettest/coordinateemock.go \
tailnet/tailnettest/workspaceupdatesprovidermock.go \
tailnet/tailnettest/subscriptionmock.go
2025-09-25 15:40:25 +02:00
AIBRIDGED_MOCKS := \
2026-05-22 09:11:37 +02:00
coderd/aibridged/aibridgedmock/clientmock.go \
coderd/aibridged/aibridgedmock/poolmock.go
2025-09-25 15:40:25 +02:00
2024-12-30 11:45:06 +02:00
GEN_FILES := \
2023-10-30 12:14:45 +04:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2025-11-21 13:09:27 +02:00
agent/agentsocket/proto/agentsocket.pb.go \
2026-03-03 09:13:11 -07:00
agent/boundarylogproxy/codec/boundary.pb.go \
2022-09-08 02:40:17 +10:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2024-10-02 16:45:13 +10:00
vpn/vpn.pb.go \
2026-05-22 09:11:37 +02:00
coderd/aibridged/proto/aibridged.pb.go \
2025-01-14 11:30:39 -07:00
$( DB_GEN_FILES) \
$( SITE_GEN_FILES) \
2023-04-11 08:57:23 -05:00
coderd/rbac/object_gen.go \
2024-05-15 11:09:42 -05:00
codersdk/rbacresources_gen.go \
2025-09-24 18:40:36 +02:00
coderd/rbac/scopes_constants_gen.go \
2025-09-26 11:43:32 +02:00
codersdk/apikey_scopes_gen.go \
2024-10-05 08:52:04 -07:00
docs/admin/integrations/prometheus.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
2026-08-03 14:33:01 -04:00
docs/admin/setup/configuration-reference.md \
2023-01-03 15:11:13 +02:00
coderd/apidoc/swagger.json \
2025-03-21 17:16:17 +02:00
docs/manifest.json \
2024-05-22 13:45:47 -04:00
provisioner/terraform/testdata/version \
2026-03-05 13:58:10 +02:00
scripts/metricsdocgen/generated_metrics \
2023-09-04 20:15:29 +03:00
site/e2e/provisionerGenerated.ts \
2024-01-22 11:07:50 +04:00
examples/examples.gen.json \
2024-11-18 10:54:11 +04:00
$( TAILNETTEST_MOCKS) \
2025-02-10 11:29:30 +00:00
coderd/database/pubsub/psmock/psmock.go \
2025-03-18 13:00:21 +00:00
agent/agentcontainers/acmock/acmock.go \
2025-04-08 10:30:05 +02:00
agent/agentcontainers/dcspec/dcspec_gen.go \
2025-08-20 10:00:44 +01:00
coderd/httpmw/loggermw/loggermock/loggermock.go \
2025-09-25 15:40:25 +02:00
codersdk/workspacesdk/agentconnmock/agentconnmock.go \
$( AIBRIDGED_MOCKS)
2025-01-14 11:30:39 -07:00
2024-12-30 11:45:06 +02:00
# all gen targets should be added here and to gen/mark-fresh
2026-05-25 17:02:13 +01:00
# Set GEN_SKIP_GOLDEN=1 to skip gen/golden-files (which needs Docker to
# start PostgreSQL via testcontainers).
GEN_SKIP_GOLDEN ?=
gen : gen /db $( if $( GEN_SKIP_GOLDEN ) ,,gen /golden -files ) $( GEN_FILES )
2022-09-08 02:40:17 +10:00
.PHONY : gen
2024-12-31 15:47:47 +02:00
gen/db : $( DB_GEN_FILES )
.PHONY : gen /db
2026-07-14 20:36:27 +01:00
# Patched snapshot of the models.dev catalog. Fetched once per
# gen/aibridge-prices run, with upstream corrections applied by
# overrides.jq; both prices.json and the frontend known-models catalog are
# generated from this single snapshot. Phony so each invocation refreshes it.
_gen/models-dev.json : | _gen
set -o pipefail; $( call atomic_write,curl -fsSL https://models.dev/api.json | jq -f scripts/aibridgepricesgen/overrides.jq)
.PHONY : _gen /models -dev .json
# Refresh the AI Bridge pricing seed file from the patched models.dev
# snapshot. Kept out of `make gen` because the output depends on live
# upstream data. Phony so each invocation regenerates.
coderd/aibridge/prices/data/prices.json : _gen /bin /aibridgepricesgen _gen /models -dev .json | _gen
2026-05-08 16:45:14 -04:00
@mkdir -p $( dir $@ )
2026-07-14 20:36:27 +01:00
$( call atomic_write,_gen/bin/aibridgepricesgen -upstream _gen/models-dev.json)
2026-05-08 16:45:14 -04:00
.PHONY : coderd /aibridge /prices /data /prices .json
2026-07-14 20:36:27 +01:00
# Frontend known-models catalog, generated from the same patched models.dev
# snapshot joined with the editorial curation in
# scripts/aibridgepricesgen/curation.json. Kept out of `make gen` for the
# same live-upstream-data reason as prices.json.
2026-09-08 11:34:51 +07:00
site/src/modules/aiModels/knownModels/knownModelsGenerated.json : _gen /bin /aibridgepricesgen _gen /models -dev .json | _gen
2026-07-14 20:36:27 +01:00
$( call atomic_write,_gen/bin/aibridgepricesgen -format= catalog -upstream _gen/models-dev.json,./scripts/biome_format.sh)
2026-09-08 11:34:51 +07:00
.PHONY : site /src /modules /aiModels /knownModels /knownModelsGenerated .json
2026-07-14 20:36:27 +01:00
gen/aibridge-prices : \
coderd /aibridge /prices /data /prices .json \
2026-09-08 11:34:51 +07:00
site /src /modules /aiModels /knownModels /knownModelsGenerated .json
2026-05-08 16:45:14 -04:00
.PHONY : gen /aibridge -prices
2025-03-21 15:04:30 +02:00
gen/golden-files : \
2025-10-24 16:18:16 +02:00
agent /unit /testdata /.gen -golden \
2025-03-21 15:04:30 +02:00
cli /testdata /.gen -golden \
coderd /.gen -golden \
coderd /notifications /.gen -golden \
enterprise /cli /testdata /.gen -golden \
enterprise /tailnet /testdata /.gen -golden \
helm /coder /tests /testdata /.gen -golden \
helm /provisioner /tests /testdata /.gen -golden \
2026-07-22 17:42:42 +02:00
helm /ai -gateway /tests /testdata /.gen -golden \
2025-03-21 15:04:30 +02:00
provisioner /terraform /testdata /.gen -golden \
tailnet /testdata /.gen -golden
.PHONY : gen /golden -files
2022-09-08 02:40:17 +10:00
# Mark all generated files as fresh so make thinks they're up-to-date. This is
# used during releases so we don't run generation scripts.
gen/mark-fresh :
2023-01-03 15:11:13 +02:00
files = "\
2023-10-30 12:14:45 +04:00
tailnet/proto/tailnet.pb.go \
agent/proto/agent.pb.go \
2023-01-03 15:11:13 +02:00
provisionersdk/proto/provisioner.pb.go \
provisionerd/proto/provisionerd.pb.go \
2025-11-21 13:09:27 +02:00
agent/agentsocket/proto/agentsocket.pb.go \
2026-03-03 09:13:11 -07:00
agent/boundarylogproxy/codec/boundary.pb.go \
2024-10-02 16:45:13 +10:00
vpn/vpn.pb.go \
2026-05-22 09:11:37 +02:00
coderd/aibridged/proto/aibridged.pb.go \
2023-08-25 10:10:15 +04:00
coderd/database/dump.sql \
2026-03-05 13:58:10 +02:00
coderd/database/querier.go \
coderd/database/unique_constraint.go \
coderd/database/dbmetrics/querymetrics.go \
coderd/database/dbauthz/dbauthz.go \
coderd/database/dbmock/dbmock.go \
coderd/database/pubsub/psmock/psmock.go \
2023-01-03 15:11:13 +02:00
site/src/api/typesGenerated.ts \
2023-04-11 08:57:23 -05:00
coderd/rbac/object_gen.go \
2024-07-02 16:29:00 +02:00
codersdk/rbacresources_gen.go \
2025-09-24 18:40:36 +02:00
coderd/rbac/scopes_constants_gen.go \
2026-03-05 13:58:10 +02:00
codersdk/apikey_scopes_gen.go \
2024-07-23 05:07:52 -10:00
site/src/api/rbacresourcesGenerated.ts \
2024-11-15 23:35:21 +05:30
site/src/api/countriesGenerated.ts \
2026-03-03 16:29:58 -05:00
site/src/api/chatModelOptionsGenerated.json \
2024-10-05 08:52:04 -07:00
docs/admin/integrations/prometheus.md \
docs/reference/cli/index.md \
docs/admin/security/audit-logs.md \
2026-08-03 14:33:01 -04:00
docs/admin/setup/configuration-reference.md \
2023-01-03 15:11:13 +02:00
coderd/apidoc/swagger.json \
2025-03-21 17:16:17 +02:00
docs/manifest.json \
2023-08-18 10:50:43 +02:00
site/e2e/provisionerGenerated.ts \
2023-10-06 13:46:37 -06:00
site/src/theme/icons.json \
2023-09-04 20:15:29 +03:00
examples/examples.gen.json \
2026-03-05 13:58:10 +02:00
scripts/metricsdocgen/generated_metrics \
2024-11-18 10:54:11 +04:00
$( TAILNETTEST_MOCKS) \
2025-02-10 12:45:44 +00:00
agent/agentcontainers/acmock/acmock.go \
2025-03-18 13:00:21 +00:00
agent/agentcontainers/dcspec/dcspec_gen.go \
2025-04-15 13:27:23 +02:00
coderd/httpmw/loggermw/loggermock/loggermock.go \
2025-08-20 10:00:44 +01:00
codersdk/workspacesdk/agentconnmock/agentconnmock.go \
2025-09-25 15:40:25 +02:00
$( AIBRIDGED_MOCKS) \
2024-10-03 21:09:52 -05:00
"
2022-09-08 02:40:17 +10:00
for file in $$ files; do
echo " $$ file"
if [ ! -f " $$ file" ] ; then
echo "File ' $$ file' does not exist"
exit 1
fi
# touch sets the mtime of the file to the current time
2025-01-03 12:27:26 -08:00
touch " $$ file"
2022-09-08 02:40:17 +10:00
done
.PHONY : gen /mark -fresh
# Runs migrations to output a dump of the database schema after migrations are
# applied.
2026-05-06 11:57:36 +10:00
coderd/database/dump.sql : coderd /database /gen /dump /main .go $( DBDUMP_INPUTS ) | _gen /bin /dbdump
2026-04-09 16:04:06 +02:00
_gen/bin/dbdump
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-09-08 02:40:17 +10:00
# Generates Go code for querying the database.
2023-10-17 14:41:35 -06:00
# coderd/database/queries.sql.go
# coderd/database/models.go
2026-03-05 13:58:10 +02:00
#
# NOTE: grouped target (&:) ensures generate.sh runs only once even
# with -j and all outputs are considered produced together. These
# files are all written by generate.sh (via sqlc and scripts/dbgen).
coderd/database/querier.go \
coderd/database/unique_constraint.go \
coderd/database/dbmetrics/querymetrics.go \
coderd/database/dbauthz/dbauthz.go & : \
coderd /database /sqlc .yaml \
coderd /database /dump .sql \
$( wildcard coderd /database /queries /*.sql )
SKIP_DUMP_SQL = 1 ./coderd/database/generate.sh
touch coderd/database/querier.go coderd/database/unique_constraint.go coderd/database/dbmetrics/querymetrics.go coderd/database/dbauthz/dbauthz.go
2022-09-08 02:40:17 +10:00
2023-06-13 13:57:43 -05:00
coderd/database/dbmock/dbmock.go : coderd /database /db .go coderd /database /querier .go
2023-05-23 12:06:33 +04:00
go generate ./coderd/database/dbmock/
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-05-23 12:06:33 +04:00
2024-05-16 13:42:42 -05:00
coderd/database/pubsub/psmock/psmock.go : coderd /database /pubsub /pubsub .go
go generate ./coderd/database/pubsub/psmock
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-05-16 13:42:42 -05:00
2025-02-10 11:29:30 +00:00
agent/agentcontainers/acmock/acmock.go : agent /agentcontainers /containers .go
go generate ./agent/agentcontainers/acmock/
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-02-10 11:29:30 +00:00
2025-04-15 13:27:23 +02:00
coderd/httpmw/loggermw/loggermock/loggermock.go : coderd /httpmw /loggermw /logger .go
go generate ./coderd/httpmw/loggermw/loggermock/
2025-04-08 10:30:05 +02:00
touch " $@ "
2025-08-20 10:00:44 +01:00
codersdk/workspacesdk/agentconnmock/agentconnmock.go : codersdk /workspacesdk /agentconn .go
go generate ./codersdk/workspacesdk/agentconnmock/
2026-04-01 12:28:47 -04:00
./scripts/format_go_file.sh " $@ "
2025-08-20 10:00:44 +01:00
touch " $@ "
2026-05-22 09:11:37 +02:00
$(AIBRIDGED_MOCKS) : coderd /aibridged /client .go coderd /aibridged /pool .go
go generate ./coderd/aibridged/aibridgedmock/
2025-09-25 15:40:25 +02:00
touch " $@ "
2025-03-24 13:41:45 +02:00
agent/agentcontainers/dcspec/dcspec_gen.go : \
node_modules /.installed \
agent /agentcontainers /dcspec /devContainer .base .schema .json \
agent /agentcontainers /dcspec /gen .sh \
agent /agentcontainers /dcspec /doc .go
DCSPEC_QUIET = true go generate ./agent/agentcontainers/dcspec/
2025-03-21 15:33:07 +02:00
touch " $@ "
2025-03-18 13:00:21 +00:00
2024-11-18 10:54:11 +04:00
$(TAILNETTEST_MOCKS) : tailnet /coordinator .go tailnet /service .go
2024-01-22 11:07:50 +04:00
go generate ./tailnet/tailnettest/
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-01-22 11:07:50 +04:00
2023-10-30 12:14:45 +04:00
tailnet/proto/tailnet.pb.go : tailnet /proto /tailnet .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2023-10-30 12:14:45 +04:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./tailnet/proto/tailnet.proto
agent/proto/agent.pb.go : agent /proto /agent .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2023-10-30 12:14:45 +04:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./agent/proto/agent.proto
2026-03-04 21:18:17 +04:00
agent/agentsocket/proto/agentsocket.pb.go : agent /agentsocket /proto /agentsocket .proto agent /proto /agent .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2025-11-21 13:09:27 +02:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./agent/agentsocket/proto/agentsocket.proto
2022-05-02 13:23:13 -05:00
provisionersdk/proto/provisioner.pb.go : provisionersdk /proto /provisioner .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2022-01-29 17:52:14 -06:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./provisionersdk/proto/provisioner.proto
2022-01-18 13:13:19 -08:00
2022-09-08 02:40:17 +10:00
provisionerd/proto/provisionerd.pb.go : provisionerd /proto /provisionerd .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2022-09-08 02:40:17 +10:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
./provisionerd/proto/provisionerd.proto
2022-05-02 13:23:13 -05:00
2024-10-01 19:40:42 +04:00
vpn/vpn.pb.go : vpn /vpn .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2024-10-01 19:40:42 +04:00
--go_out= . \
--go_opt= paths = source_relative \
./vpn/vpn.proto
2026-03-03 09:13:11 -07:00
agent/boundarylogproxy/codec/boundary.pb.go : agent /boundarylogproxy /codec /boundary .proto agent /proto /agent .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2026-03-03 09:13:11 -07:00
--go_out= . \
--go_opt= paths = source_relative \
./agent/boundarylogproxy/codec/boundary.proto
2026-05-22 09:11:37 +02:00
coderd/aibridged/proto/aibridged.pb.go : coderd /aibridged /proto /aibridged .proto
2026-03-05 22:32:18 +02:00
./scripts/atomic_protoc.sh \
2025-09-24 09:05:04 +02:00
--go_out= . \
--go_opt= paths = source_relative \
--go-drpc_out= . \
--go-drpc_opt= paths = source_relative \
2026-05-22 09:11:37 +02:00
./coderd/aibridged/proto/aibridged.proto
2025-09-24 09:05:04 +02:00
2026-05-06 11:57:36 +10:00
site/src/api/typesGenerated.ts : site /node_modules /.installed $( wildcard scripts /apitypings /*) \
$( shell find ./codersdk $( FIND_EXCLUSIONS ) -type f -name '*.go ') \
$( wildcard coderd /healthcheck /health /*.go ) \
$( wildcard codersdk /healthsdk /*.go ) | _gen _gen /bin /apitypings
2026-04-09 16:04:06 +02:00
$( call atomic_write,_gen/bin/apitypings,./scripts/biome_format.sh)
2022-03-28 14:14:40 -05:00
2025-01-03 05:37:25 -08:00
site/e2e/provisionerGenerated.ts : site /node_modules /.installed provisionerd /proto /provisionerd .pb .go provisionersdk /proto /provisioner .pb .go
2025-03-21 15:33:07 +02:00
( cd site/ && pnpm run gen:provisioner)
touch " $@ "
2023-08-18 10:50:43 +02:00
2026-04-09 16:04:06 +02:00
site/src/theme/icons.json : site /node_modules /.installed $( wildcard scripts /gensite /*) $( wildcard site /static /icon /*) | _gen _gen /bin /gensite
2026-03-05 22:32:18 +02:00
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && \
2026-04-09 16:04:06 +02:00
_gen/bin/gensite -icons " $$ tmpfile" && \
2026-03-05 13:58:10 +02:00
./scripts/biome_format.sh " $$ tmpfile" && \
2026-03-05 22:32:18 +02:00
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
2023-10-06 13:46:37 -06:00
2026-04-09 16:04:06 +02:00
examples/examples.gen.json : scripts /examplegen /main .go examples /examples .go $( shell find ./examples /templates ) | _gen _gen /bin /examplegen
$( call atomic_write,_gen/bin/examplegen)
2023-09-04 20:15:29 +03:00
2026-04-09 16:04:06 +02:00
coderd/rbac/object_gen.go : scripts /typegen /rbacobject .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go | _gen _gen /bin /typegen
$( call atomic_write,_gen/bin/typegen rbac object)
2025-03-21 15:33:07 +02:00
touch " $@ "
2024-05-15 11:09:42 -05:00
2026-04-09 16:04:06 +02:00
# NOTE: depends on object_gen.go because the generator build
# compiles coderd/rbac which includes it.
2026-03-05 13:58:10 +02:00
coderd/rbac/scopes_constants_gen.go : scripts /typegen /scopenames .gotmpl scripts /typegen /main .go coderd /rbac /policy /policy .go \
2026-04-09 16:04:06 +02:00
coderd /rbac /object_gen .go | _gen _gen /bin /typegen
2026-03-05 22:32:18 +02:00
# Write to a temp file first to avoid truncating the package
# during build since the generator imports the rbac package.
2026-04-09 16:04:06 +02:00
$( call atomic_write,_gen/bin/typegen rbac scopenames)
2025-09-24 18:40:36 +02:00
touch " $@ "
2026-03-05 13:58:10 +02:00
# NOTE: depends on object_gen.go and scopes_constants_gen.go because
2026-04-09 16:04:06 +02:00
# the generator build compiles coderd/rbac which includes both.
2026-03-05 13:58:10 +02:00
codersdk/rbacresources_gen.go : scripts /typegen /codersdk .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go \
2026-04-09 16:04:06 +02:00
coderd /rbac /object_gen .go coderd /rbac /scopes_constants_gen .go | _gen _gen /bin /typegen
2026-03-05 22:32:18 +02:00
# Write to a temp file to avoid truncating the target, which
# would break the codersdk package and any parallel build targets.
2026-04-09 16:04:06 +02:00
$( call atomic_write,_gen/bin/typegen rbac codersdk)
2025-03-21 15:33:07 +02:00
touch " $@ "
2023-04-11 08:57:23 -05:00
2026-03-05 13:58:10 +02:00
# NOTE: depends on object_gen.go and scopes_constants_gen.go because
2026-04-09 16:04:06 +02:00
# the generator build compiles coderd/rbac which includes both.
2026-03-05 13:58:10 +02:00
codersdk/apikey_scopes_gen.go : scripts /apikeyscopesgen /main .go coderd /rbac /scopes_catalog .go coderd /rbac /scopes .go \
2026-04-09 16:04:06 +02:00
coderd /rbac /object_gen .go coderd /rbac /scopes_constants_gen .go | _gen _gen /bin /apikeyscopesgen
2025-09-26 11:56:34 +02:00
# Generate SDK constants for external API key scopes.
2026-04-09 16:04:06 +02:00
$( call atomic_write,_gen/bin/apikeyscopesgen)
2025-09-26 11:43:32 +02:00
touch " $@ "
2026-03-05 13:58:10 +02:00
# NOTE: depends on object_gen.go and scopes_constants_gen.go because
2026-04-09 16:04:06 +02:00
# the generator build compiles coderd/rbac which includes both.
2026-03-05 13:58:10 +02:00
site/src/api/rbacresourcesGenerated.ts : site /node_modules /.installed scripts /typegen /codersdk .gotmpl scripts /typegen /main .go coderd /rbac /object .go coderd /rbac /policy /policy .go \
2026-04-09 16:04:06 +02:00
coderd /rbac /object_gen .go coderd /rbac /scopes_constants_gen .go | _gen _gen /bin /typegen
$( call atomic_write,_gen/bin/typegen rbac typescript,./scripts/biome_format.sh)
2024-11-15 23:35:21 +05:30
2026-04-09 16:04:06 +02:00
site/src/api/countriesGenerated.ts : site /node_modules /.installed scripts /typegen /countries .tstmpl scripts /typegen /main .go codersdk /countries .go | _gen _gen /bin /typegen
$( call atomic_write,_gen/bin/typegen countries,./scripts/biome_format.sh)
2024-07-23 05:07:52 -10:00
2026-04-09 16:04:06 +02:00
site/src/api/chatModelOptionsGenerated.json : scripts /modeloptionsgen /main .go codersdk /chats .go | _gen _gen /bin /modeloptionsgen
$( call atomic_write,_gen/bin/modeloptionsgen | tail -n +2,./scripts/biome_format.sh)
2026-03-03 16:29:58 -05:00
2026-04-09 16:04:06 +02:00
scripts/metricsdocgen/generated_metrics : $( GO_SRC_FILES ) | _gen _gen /bin /metricsdocgen -scanner
$( call atomic_write,_gen/bin/metricsdocgen-scanner)
2026-02-13 12:31:33 +00:00
2026-04-09 16:04:06 +02:00
docs/admin/integrations/prometheus.md : node_modules /.installed scripts /metricsdocgen /main .go scripts /metricsdocgen /metrics scripts /metricsdocgen /generated_metrics | _gen _gen /bin /metricsdocgen
2026-03-05 22:32:18 +02:00
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && cp " $@ " " $$ tmpfile" && \
2026-04-09 16:04:06 +02:00
_gen/bin/metricsdocgen --prometheus-doc-file= " $$ tmpfile" && \
2026-03-05 13:58:10 +02:00
pnpm exec markdownlint-cli2 --fix " $$ tmpfile" && \
pnpm exec markdown-table-formatter " $$ tmpfile" && \
2026-03-05 22:32:18 +02:00
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
2022-11-30 17:39:51 +01:00
2026-04-15 12:59:07 +10:00
docs/reference/cli/index.md : node_modules /.installed examples /examples .gen .json _gen /bin /clidocgen | _gen
2026-03-05 22:32:18 +02:00
tmpdir = $$ ( mktemp -d -p _gen) && \
tmpdir = $$ ( realpath " $$ tmpdir" ) && \
2026-03-05 13:58:10 +02:00
mkdir -p " $$ tmpdir/docs/reference/cli" && \
cp docs/manifest.json " $$ tmpdir/docs/manifest.json" && \
2026-04-09 16:04:06 +02:00
CI = true DOCS_DIR = " $$ tmpdir/docs" _gen/bin/clidocgen && \
2026-03-05 13:58:10 +02:00
pnpm exec markdownlint-cli2 --fix " $$ tmpdir/docs/reference/cli/*.md" && \
pnpm exec markdown-table-formatter " $$ tmpdir/docs/reference/cli/*.md" && \
2026-03-05 22:32:18 +02:00
for f in " $$ tmpdir/docs/reference/cli/" *.md; do mv " $$ f" "docs/reference/cli/ $$ (basename " $$ f")" ; done && \
2026-03-05 13:58:10 +02:00
rm -rf " $$ tmpdir"
2023-01-27 15:10:40 -03:00
2026-04-09 16:04:06 +02:00
docs/admin/security/audit-logs.md : node_modules /.installed coderd /database /querier .go scripts /auditdocgen /main .go enterprise /audit /table .go coderd /rbac /object_gen .go | _gen _gen /bin /auditdocgen
2026-03-05 22:32:18 +02:00
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && cp " $@ " " $$ tmpfile" && \
2026-04-09 16:04:06 +02:00
_gen/bin/auditdocgen --audit-doc-file= " $$ tmpfile" && \
2026-03-05 13:58:10 +02:00
pnpm exec markdownlint-cli2 --fix " $$ tmpfile" && \
pnpm exec markdown-table-formatter " $$ tmpfile" && \
2026-03-05 22:32:18 +02:00
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
2023-01-26 18:12:12 -05:00
2026-08-03 14:33:01 -04:00
docs/admin/setup/configuration-reference.md : node_modules /.installed $( wildcard scripts /configdocgen /*.go ) $( wildcard codersdk /*.go ) _gen /bin /configdocgen | _gen
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && \
_gen/bin/configdocgen --out= " $$ tmpfile" && \
pnpm exec markdownlint-cli2 --fix " $$ tmpfile" && \
pnpm exec markdown-table-formatter " $$ tmpfile" && \
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
2025-03-21 17:16:17 +02:00
coderd/apidoc/.gen : \
node_modules /.installed \
scripts /apidocgen /node_modules /.installed \
$( wildcard coderd /*.go ) \
$( wildcard enterprise /coderd /*.go ) \
$( wildcard codersdk /*.go ) \
$( wildcard enterprise /wsproxy /wsproxysdk /*.go ) \
2026-05-20 13:09:11 -04:00
$( wildcard coderd /workspaceconnwatcher /*.go ) \
2025-03-21 17:16:17 +02:00
$( DB_GEN_FILES ) \
coderd /rbac /object_gen .go \
.swaggo \
scripts /apidocgen /generate .sh \
2026-02-06 13:04:35 +01:00
scripts /apidocgen /swaginit /main .go \
2025-03-21 17:16:17 +02:00
$( wildcard scripts /apidocgen /postprocess /*) \
2026-03-05 22:32:18 +02:00
$( wildcard scripts /apidocgen /markdown -template /*) | _gen
tmpdir = $$ ( mktemp -d -p _gen) && swagtmp = $$ ( mktemp -d -p _gen) && \
tmpdir = $$ ( realpath " $$ tmpdir" ) && swagtmp = $$ ( realpath " $$ swagtmp" ) && \
2026-03-05 13:58:10 +02:00
mkdir -p " $$ tmpdir/reference/api" && \
cp docs/manifest.json " $$ tmpdir/manifest.json" && \
SWAG_OUTPUT_DIR = " $$ swagtmp" APIDOCGEN_DOCS_DIR = " $$ tmpdir" ./scripts/apidocgen/generate.sh && \
pnpm exec markdownlint-cli2 --fix " $$ tmpdir/reference/api/*.md" && \
pnpm exec markdown-table-formatter " $$ tmpdir/reference/api/*.md" && \
./scripts/biome_format.sh " $$ swagtmp/swagger.json" && \
2026-03-05 22:32:18 +02:00
for f in " $$ tmpdir/reference/api/" *.md; do mv " $$ f" "docs/reference/api/ $$ (basename " $$ f")" ; done && \
mv " $$ tmpdir/manifest.json" _gen/manifest-staging.json && \
mv " $$ swagtmp/docs.go" coderd/apidoc/docs.go && \
mv " $$ swagtmp/swagger.json" coderd/apidoc/swagger.json && \
2026-03-05 13:58:10 +02:00
rm -rf " $$ tmpdir" " $$ swagtmp"
2025-03-21 17:16:17 +02:00
touch " $@ "
2026-03-05 22:32:18 +02:00
docs/manifest.json : site /node_modules /.installed coderd /apidoc /.gen docs /reference /cli /index .md | _gen
tmpdir = $$ ( mktemp -d -p _gen) && tmpfile = $$ ( realpath " $$ tmpdir" ) /$( notdir $@ ) && \
cp _gen/manifest-staging.json " $$ tmpfile" && \
2026-03-05 13:58:10 +02:00
./scripts/biome_format.sh " $$ tmpfile" && \
2026-03-06 16:56:11 +02:00
mv " $$ tmpfile" " $@ " && rm -rf " $$ tmpdir"
2025-03-21 17:16:17 +02:00
coderd/apidoc/swagger.json : site /node_modules /.installed coderd /apidoc /.gen
2025-03-21 15:33:07 +02:00
touch " $@ "
2022-12-19 18:43:46 +01:00
2025-03-21 15:04:30 +02:00
update-golden-files :
2025-04-23 14:01:28 +03:00
echo 'WARNING: This target is deprecated. Use "make gen/golden-files" instead.' >& 2
echo 'Running "make gen/golden-files"' >& 2
2025-03-21 15:04:30 +02:00
make gen/golden-files
2022-11-04 19:48:36 +02:00
.PHONY : update -golden -files
2025-01-02 11:05:11 +02:00
clean/golden-files :
find . -type f -name '.gen-golden' -delete
find \
cli/testdata \
coderd/notifications/testdata \
coderd/testdata \
enterprise/cli/testdata \
enterprise/tailnet/testdata \
helm/coder/tests/testdata \
helm/provisioner/tests/testdata \
2026-07-22 17:42:42 +02:00
helm/ai-gateway/tests/testdata \
2025-01-02 11:05:11 +02:00
provisioner/terraform/testdata \
tailnet/testdata \
-type f -name '*.golden' -delete
.PHONY : clean /golden -files
2025-10-24 16:18:16 +02:00
agent/unit/testdata/.gen-golden : $( wildcard agent /unit /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard agent /unit /*_test .go )
TZ = UTC go test ./agent/unit -run= "TestGraph" -update
touch " $@ "
2023-07-06 10:59:08 +03:00
cli/testdata/.gen-golden : $( wildcard cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard cli /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./cli -run= "Test(CommandHelp|ServerYAML|ErrorExamples|.*Golden)" -update
2022-11-04 19:48:36 +02:00
touch " $@ "
2023-07-06 10:59:08 +03:00
enterprise/cli/testdata/.gen-golden : $( wildcard enterprise /cli /testdata /*.golden ) $( wildcard cli /*.tpl ) $( GO_SRC_FILES ) $( wildcard enterprise /cli /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./enterprise/cli -run= "TestEnterpriseCommandHelp" -update
2023-06-09 11:35:20 -05:00
touch " $@ "
2023-12-06 15:04:28 +04:00
tailnet/testdata/.gen-golden : $( wildcard tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard tailnet /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./tailnet -run= "TestDebugTemplate" -update
2023-12-06 15:04:28 +04:00
touch " $@ "
2023-11-28 22:37:20 +04:00
enterprise/tailnet/testdata/.gen-golden : $( wildcard enterprise /tailnet /testdata /*.golden .html ) $( GO_SRC_FILES ) $( wildcard enterprise /tailnet /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./enterprise/tailnet -run= "TestDebugTemplate" -update
2023-11-28 22:37:20 +04:00
touch " $@ "
2023-08-10 13:59:43 +04:00
helm/coder/tests/testdata/.gen-golden : $( wildcard helm /coder /tests /testdata /*.yaml ) $( wildcard helm /coder /tests /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard helm /coder /tests /*_test .go )
2026-02-27 11:50:56 -05:00
if command -v helm >/dev/null 2>& 1; then
TZ = UTC go test ./helm/coder/tests -run= TestUpdateGoldenFiles -update
else
echo "WARNING: helm not found; skipping helm/coder golden generation" >& 2
fi
2023-08-10 13:59:43 +04:00
touch " $@ "
helm/provisioner/tests/testdata/.gen-golden : $( wildcard helm /provisioner /tests /testdata /*.yaml ) $( wildcard helm /provisioner /tests /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard helm /provisioner /tests /*_test .go )
2026-02-27 11:50:56 -05:00
if command -v helm >/dev/null 2>& 1; then
TZ = UTC go test ./helm/provisioner/tests -run= TestUpdateGoldenFiles -update
else
echo "WARNING: helm not found; skipping helm/provisioner golden generation" >& 2
fi
2023-03-13 13:48:44 +00:00
touch " $@ "
2026-07-22 17:42:42 +02:00
helm/ai-gateway/tests/testdata/.gen-golden : $( wildcard helm /ai -gateway /tests /testdata /*.yaml ) $( wildcard helm /ai -gateway /tests /testdata /*.golden ) $( GO_SRC_FILES ) $( wildcard helm /ai -gateway /tests /*_test .go )
TZ = UTC go test ./helm/ai-gateway/tests -run= TestUpdateGoldenFiles -update
touch " $@ "
2023-08-24 13:36:40 +03:00
coderd/.gen-golden : $( wildcard coderd /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard coderd /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./coderd -run= "Test.*Golden $$ " -update
2024-10-10 00:31:12 +02:00
touch " $@ "
coderd/notifications/.gen-golden : $( wildcard coderd /notifications /testdata /*/*.golden ) $( GO_SRC_FILES ) $( wildcard coderd /notifications /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./coderd/notifications -run= "Test.*Golden $$ " -update
2023-08-24 13:36:40 +03:00
touch " $@ "
2026-03-24 13:02:45 +02:00
provisioner/terraform/testdata/.gen-golden : $( wildcard provisioner /terraform /testdata /*/*.golden ) $( wildcard provisioner /terraform /testdata /*/*/*.golden ) $( GO_SRC_FILES ) $( wildcard provisioner /terraform /*_test .go )
2025-04-23 13:26:46 +02:00
TZ = UTC go test ./provisioner/terraform -run= "Test.*Golden $$ " -update
2023-09-11 09:37:14 +02:00
touch " $@ "
2024-05-22 13:45:47 -04:00
provisioner/terraform/testdata/version :
2026-03-30 16:37:25 +03:00
@tf_match= true; \
if [[ " $$ (cat provisioner/terraform/testdata/version.txt)" != \
" $$ (terraform version -json | jq -r '.terraform_version')" ]] ; then \
tf_match = false; \
fi ; \
if ! $$ tf_match || \
! ./provisioner/terraform/testdata/generate.sh --check; then \
./provisioner/terraform/testdata/generate.sh; \
2024-05-22 13:45:47 -04:00
fi
.PHONY : provisioner /terraform /testdata /version
2026-03-30 16:37:25 +03:00
update-terraform-testdata :
./provisioner/terraform/testdata/generate.sh --upgrade
.PHONY : update -terraform -testdata
2025-05-06 16:53:26 +02:00
# Set the retry flags if TEST_RETRIES is set
ifdef TEST_RETRIES
GOTESTSUM_RETRY_FLAGS := --rerun-fails= $( TEST_RETRIES)
else
GOTESTSUM_RETRY_FLAGS :=
endif
2026-03-09 12:39:13 +02:00
# Default to 8x8 parallelism to avoid overwhelming our workspaces.
# Race detection defaults to 4x4 because the detector adds significant
# CPU overhead. Override via TEST_NUM_PARALLEL_PACKAGES /
# TEST_NUM_PARALLEL_TESTS.
TEST_PARALLEL_PACKAGES := $( or $( TEST_NUM_PARALLEL_PACKAGES) ,8)
TEST_PARALLEL_TESTS := $( or $( TEST_NUM_PARALLEL_TESTS) ,8)
RACE_PARALLEL_PACKAGES := $( or $( TEST_NUM_PARALLEL_PACKAGES) ,4)
RACE_PARALLEL_TESTS := $( or $( TEST_NUM_PARALLEL_TESTS) ,4)
# Use testsmallbatch tag to reduce wireguard memory allocation in tests
# (from ~18GB to negligible). Recursively expanded so target-specific
# overrides of TEST_PARALLEL_* take effect (e.g. test-race lowers
2026-08-10 12:29:05 -07:00
# parallelism). CI job timeout is 30m (see test-go-pg in ci.yaml),
2026-03-09 19:26:34 +02:00
# keep the Go timeout 5m shorter so tests produce goroutine dumps
# instead of the CI runner killing the process with no output.
2026-08-10 12:29:05 -07:00
GOTEST_FLAGS = -tags= testsmallbatch -v -timeout 25m -p $( TEST_PARALLEL_PACKAGES) -parallel= $( TEST_PARALLEL_TESTS)
2025-08-21 14:37:31 +02:00
# The most common use is to set TEST_COUNT=1 to avoid Go's test cache.
ifdef TEST_COUNT
GOTEST_FLAGS += -count= $( TEST_COUNT)
endif
ifdef TEST_SHORT
GOTEST_FLAGS += -short
endif
2026-05-28 12:35:37 +10:00
# RUN is single-quoted for the shell so regex metacharacters survive make.
# Embedded single quotes are not supported; whichtests only emits RUN values
# built from ASCII test names so generated regexes stay within this contract.
2025-08-21 14:37:31 +02:00
ifdef RUN
2026-05-28 12:35:37 +10:00
GOTEST_FLAGS += -run '$(RUN)'
endif
# TEST_SHUFFLE values must be off, on, or an integer seed.
ifdef TEST_SHUFFLE
GOTEST_FLAGS += -shuffle= $( TEST_SHUFFLE)
2025-08-21 14:37:31 +02:00
endif
2026-01-13 10:53:09 +02:00
ifdef TEST_CPUPROFILE
GOTEST_FLAGS += -cpuprofile= $( TEST_CPUPROFILE)
endif
ifdef TEST_MEMPROFILE
GOTEST_FLAGS += -memprofile= $( TEST_MEMPROFILE)
endif
2025-08-21 14:37:31 +02:00
TEST_PACKAGES ?= ./...
2025-10-10 10:02:03 +04:00
test :
2026-03-09 12:39:13 +02:00
$( GIT_FLAGS) gotestsum --format standard-quiet \
$( GOTESTSUM_RETRY_FLAGS) \
--packages= " $( TEST_PACKAGES) " \
-- \
$( GOTEST_FLAGS)
2022-06-18 14:47:10 -05:00
.PHONY : test
2022-05-21 00:39:51 +01:00
2026-03-09 12:39:13 +02:00
test-race : TEST_PARALLEL_PACKAGES := $( RACE_PARALLEL_PACKAGES )
test-race : TEST_PARALLEL_TESTS := $( RACE_PARALLEL_TESTS )
test-race :
$( GIT_FLAGS) gotestsum --format standard-quiet \
--junitfile= "gotests.xml" \
$( GOTESTSUM_RETRY_FLAGS) \
--packages= " $( TEST_PACKAGES) " \
-- \
-race \
$( GOTEST_FLAGS)
.PHONY : test -race
2025-10-10 10:02:03 +04:00
test-cli :
2025-08-21 14:37:31 +02:00
$( MAKE) test TEST_PACKAGES = "./cli..."
2025-01-20 09:06:33 +02:00
.PHONY : test -cli
2026-03-06 16:56:11 +02:00
test-js : site /node_modules /.installed
cd site/
pnpm test:ci
.PHONY : test -js
2026-03-20 17:05:44 +02:00
test-storybook : site /node_modules /.installed
cd site/
2026-03-23 22:57:03 +02:00
pnpm playwright:install
2026-03-20 17:05:44 +02:00
pnpm exec vitest run --project= storybook
.PHONY : test -storybook
2023-12-19 14:31:55 -06:00
# sqlc-cloud-is-setup will fail if no SQLc auth token is set. Use this as a
# dependency for any sqlc-cloud related targets.
sqlc-cloud-is-setup :
if [[ " $( SQLC_AUTH_TOKEN) " == "" ]] ; then
echo "ERROR: 'SQLC_AUTH_TOKEN' must be set to auth with sqlc cloud before running verify." 1>& 2
exit 1
fi
.PHONY : sqlc -cloud -is -setup
sqlc-push : sqlc -cloud -is -setup test -postgres -docker
echo "--- sqlc push"
2026-03-09 19:26:34 +02:00
SQLC_DATABASE_URL = "postgresql://postgres:postgres@localhost:5432/ $$ (go run scripts/migrate-ci/main.go)" \
2023-12-19 14:31:55 -06:00
sqlc push -f coderd/database/sqlc.yaml && echo "Passed sqlc push"
.PHONY : sqlc -push
sqlc-verify : sqlc -cloud -is -setup test -postgres -docker
echo "--- sqlc verify"
2026-03-09 19:26:34 +02:00
SQLC_DATABASE_URL = "postgresql://postgres:postgres@localhost:5432/ $$ (go run scripts/migrate-ci/main.go)" \
2023-12-19 14:31:55 -06:00
sqlc verify -f coderd/database/sqlc.yaml && echo "Passed sqlc verify"
.PHONY : sqlc -verify
2023-12-12 15:53:26 -06:00
sqlc-vet : test -postgres -docker
echo "--- sqlc vet"
2026-03-09 19:26:34 +02:00
SQLC_DATABASE_URL = "postgresql://postgres:postgres@localhost:5432/ $$ (go run scripts/migrate-ci/main.go)" \
2023-12-12 15:53:26 -06:00
sqlc vet -f coderd/database/sqlc.yaml && echo "Passed sqlc vet"
2023-12-12 16:55:13 -06:00
.PHONY : sqlc -vet
2023-12-12 15:53:26 -06:00
2022-05-21 00:39:51 +01:00
2024-04-23 12:43:14 +01:00
test-migrations : test -postgres -docker
echo "--- test migrations"
2024-04-24 08:31:01 +01:00
set -euo pipefail
2024-05-17 10:24:56 +01:00
COMMIT_FROM = $( shell git log -1 --format= '%h' HEAD)
echo "COMMIT_FROM= $$ {COMMIT_FROM}"
COMMIT_TO = $( shell git log -1 --format= '%h' origin/main)
echo "COMMIT_TO= $$ {COMMIT_TO}"
if [[ " $$ {COMMIT_FROM}" == " $$ {COMMIT_TO}" ]] ; then echo "Nothing to do!" ; exit 0; fi
2024-04-24 08:31:01 +01:00
echo "DROP DATABASE IF EXISTS migrate_test_ $$ {COMMIT_FROM}; CREATE DATABASE migrate_test_ $$ {COMMIT_FROM};" | psql 'postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable'
go run ./scripts/migrate-test/main.go --from= " $$ COMMIT_FROM" --to= " $$ COMMIT_TO" --postgres-url= "postgresql://postgres:postgres@localhost:5432/migrate_test_ $$ {COMMIT_FROM}?sslmode=disable"
2025-01-03 12:27:26 -08:00
.PHONY : test -migrations
2024-04-23 12:43:14 +01:00
2024-03-21 14:53:16 +00:00
# NOTE: we set --memory to the same size as a GitHub runner.
2022-05-21 00:39:51 +01:00
test-postgres-docker :
2026-03-09 19:26:34 +02:00
# If our container is already running, nothing to do.
if docker ps --filter "name=test-postgres-docker- ${ POSTGRES_VERSION } " --format '{{.Names}}' | grep -q .; then \
echo "test-postgres-docker- ${ POSTGRES_VERSION } is already running." ; \
exit 0; \
fi
# If something else is on 5432, warn but don't fail.
if pg_isready -h 127.0.0.1 -q 2>/dev/null; then \
echo "WARNING: PostgreSQL is already running on 127.0.0.1:5432 (not our container)." ; \
echo "Tests will use this instance. To use the Makefile's container, stop it first." ; \
exit 0; \
fi
2024-06-26 16:22:24 +01:00
docker rm -f test-postgres-docker-${ POSTGRES_VERSION } || true
2025-01-17 17:22:50 +02:00
# Try pulling up to three times to avoid CI flakes.
2025-06-11 23:06:31 +10:00
docker pull ${ POSTGRES_IMAGE } || {
2025-01-17 17:22:50 +02:00
retries = 2
2026-03-09 19:26:34 +02:00
for try in $$ ( seq 1 $$ { retries}) ; do
echo "Failed to pull image, retrying ( $$ {try}/ $$ {retries})..."
2025-01-17 17:22:50 +02:00
sleep 1
2025-06-11 23:06:31 +10:00
if docker pull ${ POSTGRES_IMAGE } ; then
2025-01-17 17:22:50 +02:00
break
fi
done
}
2025-01-17 16:07:11 +02:00
# Make sure to not overallocate work_mem and max_connections as each
# connection will be allowed to use this much memory. Try adjusting
# shared_buffers instead, if needed.
#
# - work_mem=8MB * max_connections=1000 = 8GB
# - shared_buffers=2GB + effective_cache_size=1GB = 3GB
#
# This leaves 5GB for the rest of the system _and_ storing the
# database in memory (--tmpfs).
#
# https://www.postgresql.org/docs/current/runtime-config-resource.html#GUC-WORK-MEM
2022-05-21 00:39:51 +01:00
docker run \
--env POSTGRES_PASSWORD = postgres \
--env POSTGRES_USER = postgres \
--env POSTGRES_DB = postgres \
--env PGDATA = /tmp \
2022-06-17 20:57:38 +01:00
--tmpfs /tmp \
2022-05-21 00:39:51 +01:00
--publish 5432:5432 \
2024-06-26 16:22:24 +01:00
--name test-postgres-docker-${ POSTGRES_VERSION } \
2022-06-17 20:57:38 +01:00
--restart no \
2022-05-21 00:39:51 +01:00
--detach \
2024-03-21 14:53:16 +00:00
--memory 16GB \
2025-06-11 23:06:31 +10:00
${ POSTGRES_IMAGE } \
2025-01-17 16:07:11 +02:00
-c shared_buffers = 2GB \
2023-05-14 15:32:44 -05:00
-c effective_cache_size = 1GB \
2025-01-17 16:07:11 +02:00
-c work_mem = 8MB \
2022-06-17 20:57:38 +01:00
-c max_connections = 1000 \
-c fsync = off \
-c synchronous_commit = off \
2023-02-03 18:58:31 +00:00
-c full_page_writes = off \
2026-09-08 09:53:17 -07:00
-c log_statement = $( TEST_POSTGRES_LOG_STATEMENT)
2022-06-27 12:07:39 -05:00
while ! pg_isready -h 127.0.0.1
do
2026-03-09 19:26:34 +02:00
echo " $$ (date) - waiting for database to start"
2022-06-27 12:07:39 -05:00
sleep 0.5
done
2022-06-18 14:47:10 -05:00
.PHONY : test -postgres -docker
2022-05-21 00:39:51 +01:00
2026-06-15 16:23:36 -04:00
# test-postgres-docker-logs prints the PostgreSQL container's logs. The
# postgres image logs to stderr (no logging_collector), which Docker captures,
# so combined with log_statement=all in test-postgres-docker these logs include
# every executed statement. Redirect to a file to save them, e.g.
# `make test-postgres-docker-logs > postgres.log`.
test-postgres-docker-logs :
docker logs test-postgres-docker-${ POSTGRES_VERSION }
.PHONY : test -postgres -docker -logs
2024-05-06 23:21:17 -07:00
test-tailnet-integration :
env \
CODER_TAILNET_TESTS = true \
CODER_MAGICSOCK_DEBUG_LOGGING = true \
TS_DEBUG_NETCHECK = true \
GOTRACEBACK = single \
go test \
2026-01-13 12:36:06 +02:00
-tags= testsmallbatch \
2024-05-06 23:21:17 -07:00
-exec "sudo -E" \
-timeout= 5m \
-count= 1 \
./tailnet/test/integration
2025-01-03 12:27:26 -08:00
.PHONY : test -tailnet -integration
2024-05-06 23:21:17 -07:00
2026-07-23 09:51:10 +01:00
test-timings :
@tmp_json= " $$ (mktemp)" ; \
trap 'rm -f "$$tmp_json"' EXIT; \
set +e; \
GOTESTSUM_JSONFILE = " $$ tmp_json" $( GIT_FLAGS) gotestsum --format standard-quiet \
$( GOTESTSUM_RETRY_FLAGS) \
--packages= " $( TEST_PACKAGES) " \
-- \
$( GOTEST_FLAGS) ; \
test_status = $$ ?; \
jq -r -s '
[
["package", "test", "status", "elapsed_ms"],
(
map(select(
(.Test // "") != "" and
(.Action == "pass" or .Action == "fail" or .Action == "skip")
))
| sort_by([.Package, .Test])
| group_by([.Package, .Test])
| map(last)
| sort_by([(-(.Elapsed // 0)), .Package, .Test])
| .[]
| [.Package, .Test, .Action, ((.Elapsed // 0) * 1000)]
)
]
| .[]
| @tsv
' " $$ tmp_json" > " $( or $( TEST_TIMINGS_OUTPUT) ,test-timings.tsv) " ; \
report_status = $$ ?; \
if [[ $$ test_status -ne 0 ]] ; then exit $$ test_status; fi ; \
exit $$ report_status
.PHONY : test -timings
2023-07-07 12:16:16 +01:00
# Note: we used to add this to the test target, but it's not necessary and we can
# achieve the desired result by specifying -count=1 in the go test invocation
# instead. Keeping it here for convenience.
2022-05-21 00:39:51 +01:00
test-clean :
go clean -testcache
2022-06-18 14:47:10 -05:00
.PHONY : test -clean
2024-06-26 09:00:42 +01:00
2026-07-15 21:21:59 +03:00
site/e2e/bin/coder : go .mod go .sum $( GO_SRC_FILES ) site /out /index .html
2025-01-23 09:45:50 -07:00
go build -o $@ \
2026-07-15 21:21:59 +03:00
-tags embed,ts_omit_aws,ts_omit_bird,ts_omit_tap,ts_omit_kube \
2025-01-23 09:45:50 -07:00
./enterprise/cmd/coder
test-e2e : site /e 2e /bin /coder site /node_modules /.installed site /out /index .html
2025-01-03 12:27:26 -08:00
cd site/
2026-03-09 19:26:34 +02:00
pnpm playwright:install
2025-01-03 12:27:26 -08:00
ifdef CI
DEBUG = pw:api pnpm playwright:test --forbid-only --workers 1
else
pnpm playwright : test
endif
2024-06-26 09:00:42 +01:00
.PHONY : test -e 2e
2025-01-28 16:38:37 +01:00
2025-10-27 14:31:32 +04:00
# Count the number of test databases created per test package.
count-test-databases :
PGPASSWORD = postgres psql -h localhost -U postgres -d coder_testing -P pager = off -c 'SELECT test_package, count(*) as count from test_databases GROUP BY test_package ORDER BY count DESC'
.PHONY : count -test -databases
2026-03-11 17:44:19 +01:00
.PHONY : count -test -databases