Feat: add workflows
Some checks failed
Go test / run-go-vet (push) Successful in 6s
Go test / run-go-test (push) Failing after 23s
Go test / cleanup-go-test (push) Successful in 12s

This commit is contained in:
2025-12-08 23:18:19 +08:00
parent f191aef810
commit 62c4d38e9c
3 changed files with 49 additions and 7 deletions

29
.gitea/workflows/test.yml Normal file
View File

@@ -0,0 +1,29 @@
---
name: Go test
on: [push]
jobs:
run-go-vet:
runs-on: imgbuilder
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run go vet
run: go vet
run-go-test:
needs: run-go-vet
runs-on: imgbuilder
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run go test
run: make test-ci
cleanup-go-test:
needs: run-go-test
runs-on: imgbuilder
if: always()
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run make docker-clean
run: make docker-clean

View File

@@ -1,4 +1,5 @@
.PHONY: all swagger docker install test
.PHONY: all swagger install postgres test test-ci \
docker docker-quiet docker-clean
SWAG ?= go run github.com/swaggo/swag/cmd/swag@v1.16.4
DOCKER ?= docker
@@ -9,22 +10,33 @@ TARGET := backend
all: swagger docker
swagger:
$(SWAG) fmt
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
docker: $(TARGET)
$(DOCKER) compose up -d --force-recreate --build backend
$(TARGET): $(SOURCE)
$(GO_ENV) go build -o $@
install:
$(GO_ENV) go install
test:
go test -v ./tests -count=1
go test -v ./tests -count=1 -failfast
postgres:
$(DOCKER) compose exec postgres psql \
postgres://go2025:go2025@postgres:5432/go2025?sslmode=disable
swagger:
$(SWAG) fmt
$(SWAG) init -o docs -g cmds/serve.go -pdl 1
test-ci: docker-quiet test docker-clean
$(TARGET): $(SOURCE)
$(GO_ENV) go build -o $@
docker-quiet: $(TARGET)
$(DOCKER) compose -p go2025-backend up -d \
--force-recreate --build backend \
--quiet-build --quiet-pull
sleep 5
docker-clean:
$(DOCKER) compose -p go2025-backend down -v --remove-orphans

View File

@@ -64,6 +64,7 @@ services:
context: .
env_file:
- path: ./.env
required: false
ports:
- 8080:8080
volumes: