diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ae94020e4..c2a79048a 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 0112097c3..60a44c540 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 fe6b05f5b..7e816aade 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 - 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 + +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 \ + 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 $(call BUILD_CMD,$(@),) + +auth-x86: deps + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 $(call BUILD_CMD,$(@),) + +auth-arm64: deps + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),) -build-strip: deps ## Build a stripped binary, for which the version file needs to be rewritten. - echo "package utilities" > internal/utilities/version.go - echo "const Version = \"$(VERSION)\"" >> internal/utilities/version.go +auth-darwin-arm64: deps + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@),) - CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build \ - $(FLAGS) -ldflags "-s -w" -o auth-arm64-strip +auth-arm64-strip: deps + CGO_ENABLED=0 GOOS=linux GOARCH=arm64 $(call BUILD_CMD,$(@), -s) 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 $(