From 45bbf78a2546421ebbc30bf5328e7fd105fa821e Mon Sep 17 00:00:00 2001 From: Chris Stockton Date: Fri, 20 Mar 2026 13:20:46 -0700 Subject: [PATCH 1/2] feat: improve parallelization in github workflows and Makefile The primary goals of this PR are: * Better parallelization for github workflows and local builds * Allow easily running the github workflows locally Changes: * Makefile now describes dependencies among targets to enable parallel jobs * Created `release` target to be called from the release workflow * Creates temporary build folders to isolate symlinks * Created `release-test` target to be called form the test workflow * Makefile now has a release target which will concurrently build all 4 archives * Added -j flag to Makefile so it may create multiple jobs * This should leverage all cpus 4 cpu machines we will build on * I've made the arch explicit (GOOS=amd64) for x86 binary for safety * For now I've preserved the existing targets for "make build" and "make build-strip", but ideally: * `make build` only builds using `CGO_ENABLED=0 go build` giving native arch for local dev. * `make release` builds all the release binaries, without any env defined values such as `CGO_ENABLED=0 go build` (it is currently doing this now) * I've collapsed the test workflows into one step so they can run concurrently One note is that the go tool chain does make use of multiple cpus. But there should still be measurable benefits on 4 cpu machines with these changes. --- .github/workflows/release.yml | 15 +------ .github/workflows/test.yml | 25 +++-------- Makefile | 80 +++++++++++++++++++++++++++++------ 3 files changed, 76 insertions(+), 44 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae94020e4a..c2a79048a3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -99,19 +99,8 @@ jobs: run: | set -ex - RELEASE_VERSION=$RELEASE_VERSION make deps - RELEASE_VERSION=$RELEASE_VERSION make build build-strip - - ln -s auth gotrue - tar -czvf auth-v$RELEASE_VERSION-x86.tar.gz auth gotrue migrations/ - mv auth-arm64 auth - tar -czvf auth-v$RELEASE_VERSION-arm64.tar.gz auth gotrue migrations/ - - mv auth-darwin-arm64 auth - tar -czvf auth-v$RELEASE_VERSION-darwin-arm64.tar.gz auth gotrue migrations/ - - mv auth-arm64-strip auth - tar -cf - auth gotrue migrations/ | xz -T0 -9e -C crc64 > auth-v$RELEASE_VERSION-arm64.tar.xz + MAKE_JOBS="$(nproc 2>/dev/null || echo 4)" + RELEASE_VERSION=$RELEASE_VERSION make -j"$MAKE_JOBS" release - name: Generate checksums if: ${{ steps.release.outputs.release_created == 'true' || steps.release.outputs.prs_created == 'true' }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0112097c3c..60a44c540d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,28 +42,17 @@ jobs: then echo 'Make sure to run "gofmt -s -w ." before commit!' && exit 1 fi - - name: Check go vet - run: | - set -x - go vet ./... - - name: Run static check - run: | - set -x - make static - - name: Check gosec - run: | - set -x - make sec - - name: Run govulncheck - run: | - set -x - make vulncheck - name: Init Database run: psql -f hack/init_postgres.sql postgresql://postgres:root@localhost:5432/postgres - name: Run migrations run: make migrate_dev - - name: Lint and test - run: make test + - name: Run linters and tests + run: | + set -x + + MAKE_JOBS="$(nproc 2>/dev/null || echo 4)" + make -j"$MAKE_JOBS" release-test + - name: Cleanup coverage run: | set -x diff --git a/Makefile b/Makefile index fe6b05f5ba..e62a5059e8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -.PHONY: all build deps image migrate test vet sec vulncheck format unused +.PHONY: all build deps image migrate test vet sec vulncheck format unused release .PHONY: check-gosec check-govulncheck check-oapi-codegen check-staticcheck -CHECK_FILES?=./... +CHECK_FILES ?= ./... ifdef RELEASE_VERSION VERSION=v$(RELEASE_VERSION) @@ -8,44 +8,91 @@ else VERSION=$(shell git describe --tags) endif -FLAGS=-ldflags "-X github.com/supabase/auth/internal/utilities.Version=$(VERSION)" -buildvcs=false +FLAGS = -ldflags "-X github.com/supabase/auth/internal/utilities.Version=$(VERSION)" -buildvcs=false ifneq ($(shell docker compose version 2>/dev/null),) - DOCKER_COMPOSE=docker compose + DOCKER_COMPOSE = docker compose else - DOCKER_COMPOSE=docker-compose + DOCKER_COMPOSE = docker-compose endif -DEV_DOCKER_COMPOSE:=docker-compose-dev.yml +DEV_DOCKER_COMPOSE = docker-compose-dev.yml + +RELEASE_TARGETS = x86 arm64 darwin-arm64 arm64-strip +RELEASE_ARCHIVES = \ + auth-$(VERSION)-x86.tar.gz \ + auth-$(VERSION)-arm64.tar.gz \ + auth-$(VERSION)-darwin-arm64.tar.gz \ + auth-$(VERSION)-arm64.tar.xz + help: ## Show this help. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) all: vet sec static build ## Run the tests and build the binary. -build: deps ## Build the binary. - CGO_ENABLED=0 go build $(FLAGS) - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(FLAGS) -o auth-arm64 - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(FLAGS) -o auth-darwin-arm64 +build: auth auth-arm64 auth-darwin-arm64 ## Build the binaries. + +build-strip: auth-arm64-strip ## Build a stripped binary, for which the version file needs to be rewritten. + +auth: deps + CGO_ENABLED=0 go build $(FLAGS) -o $(@) -build-strip: deps ## Build a stripped binary, for which the version file needs to be rewritten. +auth-x86: deps + CGO_ENABLED=0 GOARCH=amd64 go build $(FLAGS) -o $(@) + +auth-arm64: deps + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(FLAGS) -o $(@) + +auth-darwin-arm64: deps + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(FLAGS) -o $(@) + +auth-arm64-strip: deps echo "package utilities" > internal/utilities/version.go echo "const Version = \"$(VERSION)\"" >> internal/utilities/version.go CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \ - $(FLAGS) -ldflags "-s -w" -o auth-arm64-strip + $(FLAGS) -ldflags "-s -w" -o $(@) deps: ## Install dependencies. @go mod download @go mod verify + +release-test: \ + vet \ + static \ + sec \ + vulncheck \ + test + +release: $(RELEASE_ARCHIVES) + +auth-$(VERSION)-%.tar.gz: \ + release-%/auth \ + release-%/gotrue | migrations + tar -C $( $(@) + +release-%/auth: auth-% + mkdir -p $(@D) + cp -a $(<) $(@) + +release-%/gotrue: release-%/auth + ln -sf $( Date: Wed, 25 Mar 2026 10:34:48 -0700 Subject: [PATCH 2/2] chore: additional cleanup to build targets Some additional cleanup: * Added a common build macro that accepts the dest name and an optional set of flags to pass to the go linker. * Removed the redundant -w flag on strip target (it's implied) * Removed the version file writes and used the optional linker flags added in the build macro, since stripped binaries allow for -X flags. --- Makefile | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index e62a5059e8..7e816aade0 100644 --- a/Makefile +++ b/Makefile @@ -8,16 +8,21 @@ else VERSION=$(shell git describe --tags) endif -FLAGS = -ldflags "-X github.com/supabase/auth/internal/utilities.Version=$(VERSION)" -buildvcs=false - ifneq ($(shell docker compose version 2>/dev/null),) - DOCKER_COMPOSE = docker compose + DOCKER_COMPOSE = docker compose else - DOCKER_COMPOSE = docker-compose + DOCKER_COMPOSE = docker-compose endif DEV_DOCKER_COMPOSE = docker-compose-dev.yml +BUILD_VERSION_PKG = github.com/supabase/auth/internal/utilities +BUILD_LD_FLAGS = -X $(BUILD_VERSION_PKG).Version=$(VERSION) +BUILD_CMD = go build \ + -o $(1) \ + -buildvcs=false \ + -ldflags "$(BUILD_LD_FLAGS)$(2)" + RELEASE_TARGETS = x86 arm64 darwin-arm64 arm64-strip RELEASE_ARCHIVES = \ auth-$(VERSION)-x86.tar.gz \ @@ -36,29 +41,24 @@ build: auth auth-arm64 auth-darwin-arm64 ## Build the binaries. build-strip: auth-arm64-strip ## Build a stripped binary, for which the version file needs to be rewritten. auth: deps - CGO_ENABLED=0 go build $(FLAGS) -o $(@) + CGO_ENABLED=0 $(call BUILD_CMD,$(@),) auth-x86: deps - CGO_ENABLED=0 GOARCH=amd64 go build $(FLAGS) -o $(@) + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(call BUILD_CMD,$(@),) auth-arm64: deps - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build $(FLAGS) -o $(@) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),) auth-darwin-arm64: deps - CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build $(FLAGS) -o $(@) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),) auth-arm64-strip: deps - echo "package utilities" > internal/utilities/version.go - echo "const Version = \"$(VERSION)\"" >> internal/utilities/version.go - - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \ - $(FLAGS) -ldflags "-s -w" -o $(@) + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@), -s) deps: ## Install dependencies. @go mod download @go mod verify - release-test: \ vet \ static \