2022-08-28 02:27:51 +02:00
DIST := dist
EXECUTABLE := act_runner
GOFMT ?= gofumpt -l
DIST := dist
DIST_DIRS := $( DIST) /binaries $( DIST) /release
GO ?= go
SHASUM ?= shasum -a 256
HAS_GO = $( shell hash $( GO) > /dev/null 2>& 1 && echo "GO" || echo "NOGO" )
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
XGO_VERSION := go-1.18.x
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
LINUX_ARCHS ?= linux/amd64,linux/arm64
DARWIN_ARCHS ?= darwin-12/amd64,darwin-12/arm64
WINDOWS_ARCHS ?= windows/amd64
2023-03-14 11:43:05 +01:00
GO_FMT_FILES := $( shell find . -type f -name "*.go" ! -name "generated.*" )
GOFILES := $( shell find . -type f -name "*.go" -o -name "go.mod" ! -name "generated.*" )
2022-08-28 02:27:51 +02:00
2023-04-12 22:17:08 +02:00
DOCKER_IMAGE ?= gitea/act_runner
DOCKER_TAG ?= nightly
DOCKER_REF := $( DOCKER_IMAGE) :$( DOCKER_TAG)
2023-06-12 08:35:27 +02:00
DOCKER_ROOTLESS_REF := $( DOCKER_IMAGE) _rootless:$( DOCKER_TAG)
2023-04-12 22:17:08 +02:00
2022-08-28 02:27:51 +02:00
i f n e q ( $( shell uname ) , D a r w i n )
EXTLDFLAGS = -extldflags "-static" $( null)
e l s e
EXTLDFLAGS =
e n d i f
i f e q ( $( HAS_GO ) , G O )
GOPATH ?= $( shell $( GO) env GOPATH)
export PATH := $( GOPATH) /bin:$( PATH)
CGO_EXTRA_CFLAGS := -DSQLITE_MAX_VARIABLE_NUMBER= 32766
CGO_CFLAGS ?= $( shell $( GO) env CGO_CFLAGS) $( CGO_EXTRA_CFLAGS)
e n d i f
i f e q ( $( OS ) , W i n d o w s _ N T )
GOFLAGS := -v -buildmode= exe
EXECUTABLE ?= $( EXECUTABLE) .exe
e l s e i f e q ( $( OS ) , W i n d o w s )
GOFLAGS := -v -buildmode= exe
EXECUTABLE ?= $( EXECUTABLE) .exe
e l s e
GOFLAGS := -v
EXECUTABLE ?= $( EXECUTABLE)
e n d i f
STORED_VERSION_FILE := VERSION
i f n e q ( $( DRONE_TAG ) , )
VERSION ?= $( subst v,,$( DRONE_TAG) )
RELASE_VERSION ?= $( VERSION)
e l s e
ifneq ( $( DRONE_BRANCH) ,)
VERSION ?= $( subst release/v,,$( DRONE_BRANCH) )
else
2023-03-13 11:57:35 +01:00
VERSION ?= main
2022-08-28 02:27:51 +02:00
endif
STORED_VERSION = $( shell cat $( STORED_VERSION_FILE) 2>/dev/null)
ifneq ( $( STORED_VERSION) ,)
RELASE_VERSION ?= $( STORED_VERSION)
else
RELASE_VERSION ?= $( shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//' )
endif
e n d i f
2023-05-06 11:00:52 +02:00
GO_PACKAGES_TO_VET ?= $( filter-out gitea.com/gitea/act_runner/internal/pkg/client/mocks,$( shell $( GO) list ./...) )
2022-08-28 02:27:51 +02:00
TAGS ?=
2023-04-04 15:32:04 +02:00
LDFLAGS ?= -X " gitea.com/gitea/act_runner/internal/pkg/ver.version= $( RELASE_VERSION) "
2022-08-28 02:27:51 +02:00
all : build
fmt :
@hash gofumpt > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2023-02-24 16:30:09 +01:00
$( GO) install mvdan.cc/gofumpt@latest; \
2022-08-28 02:27:51 +02:00
fi
2023-03-14 11:43:05 +01:00
$( GOFMT) -w $( GO_FMT_FILES)
2022-08-28 02:27:51 +02:00
2023-03-16 04:37:08 +01:00
.PHONY : go -check
go-check :
$( eval MIN_GO_VERSION_STR := $( shell grep -Eo '^go\s+[0-9]+\.[0-9]+' go.mod | cut -d' ' -f2) )
$( eval MIN_GO_VERSION := $( shell printf "%03d%03d" $( shell echo '$(MIN_GO_VERSION_STR)' | tr '.' ' ' ) ) )
$( eval GO_VERSION := $( shell printf "%03d%03d" $( shell $( GO) version | grep -Eo '[0-9]+\.[0-9]+' | tr '.' ' ' ) ; ) )
@if [ " $( GO_VERSION) " -lt " $( MIN_GO_VERSION) " ] ; then \
echo " Act Runner requires Go $( MIN_GO_VERSION_STR) or greater to build. You can get it at https://go.dev/dl/ " ; \
exit 1; \
fi
2022-08-28 02:27:51 +02:00
.PHONY : fmt -check
fmt-check :
@hash gofumpt > /dev/null 2>& 1; if [ $$ ? -ne 0 ] ; then \
2023-02-24 16:30:09 +01:00
$( GO) install mvdan.cc/gofumpt@latest; \
2022-08-28 02:27:51 +02:00
fi
2023-03-14 11:43:05 +01:00
@diff= $$ ( $( GOFMT) -d $( GO_FMT_FILES) ) ; \
2022-08-28 02:27:51 +02:00
if [ -n " $$ diff " ] ; then \
echo "Please run 'make fmt' and commit the result:" ; \
echo " $$ {diff} " ; \
exit 1; \
fi ;
test : fmt -check
@$( GO) test -v -cover -coverprofile coverage.txt ./... && echo "\n==>\033[32m Ok\033[m\n" || exit 1
2023-02-28 11:44:46 +01:00
.PHONY : vet
vet :
@echo "Running go vet..."
@$( GO) build code.gitea.io/gitea-vet
2023-05-06 11:00:52 +02:00
@$( GO) vet -vettool= gitea-vet $( GO_PACKAGES_TO_VET)
2023-02-28 11:44:46 +01:00
2022-08-28 02:27:51 +02:00
install : $( GOFILES )
$( GO) install -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)'
2023-03-16 04:37:08 +01:00
build : go -check $( EXECUTABLE )
2022-08-28 02:27:51 +02:00
$(EXECUTABLE) : $( GOFILES )
$( GO) build -v -tags '$(TAGS)' -ldflags '$(EXTLDFLAGS)-s -w $(LDFLAGS)' -o $@
.PHONY : deps -backend
deps-backend :
$( GO) mod download
$( GO) install $( GXZ_PAGAGE)
$( GO) install $( XGO_PACKAGE)
.PHONY : release
release : release -windows release -linux release -darwin release -copy release -compress release -check
$(DIST_DIRS) :
mkdir -p $( DIST_DIRS)
.PHONY : release -windows
release-windows : | $( DIST_DIRS )
CGO_CFLAGS = " $( CGO_CFLAGS) " $( GO) run $( XGO_PACKAGE) -go $( XGO_VERSION) -buildmode exe -dest $( DIST) /binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(WINDOWS_ARCHS)' -out $( EXECUTABLE) -$( VERSION) .
i f e q ( $( CI ) , t r u e )
cp -r /build/* $( DIST) /binaries/
e n d i f
.PHONY : release -linux
release-linux : | $( DIST_DIRS )
CGO_CFLAGS = " $( CGO_CFLAGS) " $( GO) run $( XGO_PACKAGE) -go $( XGO_VERSION) -dest $( DIST) /binaries -tags 'netgo osusergo $(TAGS)' -ldflags '-linkmode external -extldflags "-static" $(LDFLAGS)' -targets '$(LINUX_ARCHS)' -out $( EXECUTABLE) -$( VERSION) .
i f e q ( $( CI ) , t r u e )
cp -r /build/* $( DIST) /binaries/
e n d i f
.PHONY : release -darwin
release-darwin : | $( DIST_DIRS )
CGO_CFLAGS = " $( CGO_CFLAGS) " $( GO) run $( XGO_PACKAGE) -go $( XGO_VERSION) -dest $( DIST) /binaries -tags 'netgo osusergo $(TAGS)' -ldflags '$(LDFLAGS)' -targets '$(DARWIN_ARCHS)' -out $( EXECUTABLE) -$( VERSION) .
i f e q ( $( CI ) , t r u e )
cp -r /build/* $( DIST) /binaries/
e n d i f
.PHONY : release -copy
release-copy : | $( DIST_DIRS )
cd $( DIST) ; for file in ` find . -type f -name "*" ` ; do cp $$ { file} ./release/; done ;
.PHONY : release -check
release-check : | $( DIST_DIRS )
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " checksumming $$ {file} " && $( SHASUM) ` echo $$ { file} | sed 's/^..//' ` > $$ { file} .sha256; done ;
.PHONY : release -compress
release-compress : | $( DIST_DIRS )
cd $( DIST) /release/; for file in ` find . -type f -name "*" ` ; do echo " compressing $$ {file} " && $( GO) run $( GXZ_PAGAGE) -k -9 $$ { file} ; done ;
2023-04-12 22:17:08 +02:00
.PHONY : docker
docker :
2023-04-24 21:15:48 +02:00
if ! docker buildx version >/dev/null 2>& 1; then \
ARG_DISABLE_CONTENT_TRUST = --disable-content-trust= false; \
fi ; \
docker build $$ { ARG_DISABLE_CONTENT_TRUST} -t $( DOCKER_REF) .
2023-06-12 08:35:27 +02:00
docker build $$ { ARG_DISABLE_CONTENT_TRUST} -t $( DOCKER_ROOTLESS_REF) -f Dockerfile.rootless .
2023-04-12 22:17:08 +02:00
2022-08-28 02:27:51 +02:00
clean :
$( GO) clean -x -i ./...
rm -rf coverage.txt $( EXECUTABLE) $( DIST)
version :
@echo $( VERSION)