2020-01-26 19:08:47 +00:00
|
|
|
GO ?= go
|
|
|
|
|
2020-01-26 07:22:57 +00:00
|
|
|
WORK_DIR := $(shell pwd)
|
|
|
|
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_SDK_TEST_URL ?= http://localhost:3000
|
|
|
|
FORGEJO_SDK_TEST_USERNAME ?= test01
|
|
|
|
FORGEJO_SDK_TEST_PASSWORD ?= test01
|
2020-01-26 07:22:57 +00:00
|
|
|
|
2024-06-14 21:48:24 +01:00
|
|
|
PACKAGE := codeberg.org/mvdkleijn/forgejo-sdk/forgejo
|
2020-11-09 20:54:59 +00:00
|
|
|
|
2023-03-01 00:50:04 +00:00
|
|
|
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.4.0
|
|
|
|
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.0
|
|
|
|
|
2024-09-12 20:13:17 +01:00
|
|
|
FORGEJO_VERSION := 8.0.3
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := https://codeberg.org/forgejo/forgejo/releases/download/v$(FORGEJO_VERSION)/forgejo-$(FORGEJO_VERSION)-
|
2020-11-09 20:54:59 +00:00
|
|
|
UNAME_S := $(shell uname -s)
|
|
|
|
ifeq ($(UNAME_S),Linux)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)linux-
|
2020-11-09 20:54:59 +00:00
|
|
|
|
|
|
|
UNAME_P := $(shell uname -p)
|
|
|
|
ifeq ($(UNAME_P),unknown)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)amd64
|
2020-11-09 20:54:59 +00:00
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_P),x86_64)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)amd64
|
2020-11-09 20:54:59 +00:00
|
|
|
endif
|
|
|
|
ifneq ($(filter %86,$(UNAME_P)),)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)386
|
2020-11-09 20:54:59 +00:00
|
|
|
endif
|
|
|
|
ifneq ($(filter arm%,$(UNAME_P)),)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)arm-5
|
2020-11-09 20:54:59 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq ($(UNAME_S),Darwin)
|
2024-02-23 00:26:49 +00:00
|
|
|
FORGEJO_DL := $(FORGEJO_DL)darwin-10.12-amd64
|
2020-11-09 20:54:59 +00:00
|
|
|
endif
|
|
|
|
|
2016-11-07 12:41:57 +00:00
|
|
|
.PHONY: all
|
|
|
|
all: clean test build
|
|
|
|
|
2020-01-26 07:22:57 +00:00
|
|
|
.PHONY: help
|
|
|
|
help:
|
|
|
|
@echo "Make Routines:"
|
|
|
|
@echo " - \"\" run \"make clean test build\""
|
|
|
|
@echo " - build build sdk"
|
|
|
|
@echo " - clean clean"
|
|
|
|
@echo " - fmt format the code"
|
|
|
|
@echo " - lint run golint"
|
|
|
|
@echo " - vet examines Go source code and reports"
|
2024-02-23 00:26:49 +00:00
|
|
|
@echo " - test run unit tests (need a running forgejo)"
|
|
|
|
@echo " - test-instance start a forgejo instance for test"
|
2020-01-26 07:22:57 +00:00
|
|
|
|
|
|
|
|
2016-11-07 12:41:57 +00:00
|
|
|
.PHONY: clean
|
|
|
|
clean:
|
2020-01-26 07:22:57 +00:00
|
|
|
rm -r -f test
|
2024-02-23 00:26:49 +00:00
|
|
|
cd forgejo && $(GO) clean -i ./...
|
2016-11-07 12:41:57 +00:00
|
|
|
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
2022-04-28 16:33:21 +01:00
|
|
|
find . -name "*.go" -type f | xargs gofmt -s -w; \
|
2024-02-23 00:26:49 +00:00
|
|
|
$(GO) run $(GOFUMPT_PACKAGE) -extra -w ./forgejo
|
2016-11-07 12:41:57 +00:00
|
|
|
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
2021-08-13 15:21:17 +01:00
|
|
|
# Default vet
|
2024-02-23 00:26:49 +00:00
|
|
|
cd forgejo && $(GO) vet $(PACKAGE)
|
2016-11-07 12:41:57 +00:00
|
|
|
|
2022-04-28 16:33:21 +01:00
|
|
|
.PHONY: ci-lint
|
2024-09-12 20:13:17 +01:00
|
|
|
ci-lint:
|
2024-02-23 00:26:49 +00:00
|
|
|
@cd forgejo/; echo -n "gofumpt ...";\
|
2023-03-01 00:50:04 +00:00
|
|
|
diff=$$($(GO) run $(GOFUMPT_PACKAGE) -extra -l .); \
|
2022-04-28 16:33:21 +01:00
|
|
|
if [ -n "$$diff" ]; then \
|
2022-05-30 23:08:44 +01:00
|
|
|
echo; echo "Not gofumpt-ed"; \
|
2022-04-28 16:33:21 +01:00
|
|
|
exit 1; \
|
2022-05-30 23:08:44 +01:00
|
|
|
fi; echo " done"; echo -n "golangci-lint ...";\
|
2023-03-01 00:50:04 +00:00
|
|
|
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --timeout 5m; \
|
2022-04-28 16:33:21 +01:00
|
|
|
if [ $$? -eq 1 ]; then \
|
2022-05-30 23:08:44 +01:00
|
|
|
echo; echo "Doesn't pass golangci-lint"; \
|
2022-04-28 16:33:21 +01:00
|
|
|
exit 1; \
|
2022-05-30 23:08:44 +01:00
|
|
|
fi; echo " done"; \
|
2022-04-28 16:33:21 +01:00
|
|
|
cd -; \
|
2016-11-07 12:41:57 +00:00
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
2024-02-23 00:26:49 +00:00
|
|
|
@export FORGEJO_SDK_TEST_URL=${FORGEJO_SDK_TEST_URL}; export FORGEJO_SDK_TEST_USERNAME=${FORGEJO_SDK_TEST_USERNAME}; export FORGEJO_SDK_TEST_PASSWORD=${FORGEJO_SDK_TEST_PASSWORD}; \
|
|
|
|
if [ -z "$(shell curl --noproxy "*" "${FORGEJO_SDK_TEST_URL}/api/v1/version" 2> /dev/null)" ]; then \echo "No test-instance detected!"; exit 1; else \
|
|
|
|
cd forgejo && $(GO) test -race -cover -coverprofile coverage.out; \
|
2020-01-26 07:22:57 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: test-instance
|
|
|
|
test-instance:
|
2024-09-12 22:11:44 +01:00
|
|
|
rm -f -r ${WORK_DIR}/test/conf ${WORK_DIR}/test/data 2> /dev/null; \
|
2020-01-26 07:22:57 +00:00
|
|
|
mkdir -p ${WORK_DIR}/test/conf/ ${WORK_DIR}/test/data/
|
2024-09-12 22:11:44 +01:00
|
|
|
# wget ${FORGEJO_DL} -O ${WORK_DIR}/test/forgejo-main; \
|
2024-02-23 00:26:49 +00:00
|
|
|
chmod +x ${WORK_DIR}/test/forgejo-main; \
|
2020-01-26 07:22:57 +00:00
|
|
|
echo "[security]" > ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "INTERNAL_TOKEN = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYmYiOjE1NTg4MzY4ODB9.LoKQyK5TN_0kMJFVHWUW0uDAyoGjDP6Mkup4ps2VJN4" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "INSTALL_LOCK = true" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "SECRET_KEY = 2crAW4UANgvLipDS6U5obRcFosjSJHQANll6MNfX7P0G3se3fKcCwwK3szPyGcbo" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "PASSWORD_COMPLEXITY = off" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "[database]" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "DB_TYPE = sqlite3" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "[repository]" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
echo "ROOT = ${WORK_DIR}/test/data/" >> ${WORK_DIR}/test/conf/app.ini; \
|
2020-11-09 00:58:30 +00:00
|
|
|
echo "[server]" >> ${WORK_DIR}/test/conf/app.ini; \
|
2024-02-23 00:26:49 +00:00
|
|
|
echo "ROOT_URL = ${FORGEJO_SDK_TEST_URL}" >> ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
${WORK_DIR}/test/forgejo-main migrate -c ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
${WORK_DIR}/test/forgejo-main admin user create --username=${FORGEJO_SDK_TEST_USERNAME} --password=${FORGEJO_SDK_TEST_PASSWORD} --email=test01@forgejo.org --admin=true --must-change-password=false --access-token -c ${WORK_DIR}/test/conf/app.ini; \
|
|
|
|
${WORK_DIR}/test/forgejo-main web -c ${WORK_DIR}/test/conf/app.ini
|
2016-11-07 12:41:57 +00:00
|
|
|
|
2017-08-22 18:20:39 +01:00
|
|
|
.PHONY: bench
|
|
|
|
bench:
|
2024-02-23 00:26:49 +00:00
|
|
|
cd forgejo && $(GO) test -run=XXXXXX -benchtime=10s -bench=. || exit 1
|
2017-08-22 18:20:39 +01:00
|
|
|
|
2016-11-07 12:41:57 +00:00
|
|
|
.PHONY: build
|
|
|
|
build:
|
2024-02-23 00:26:49 +00:00
|
|
|
cd forgejo && $(GO) build
|
2022-05-30 23:08:44 +01:00
|
|
|
|