新增 Github Actions

This commit is contained in:
dragon
2025-09-25 10:19:13 +08:00
parent abba011a61
commit 9a425a057e
4 changed files with 95 additions and 4 deletions

24
.github/workflows/go-release.yml vendored Normal file
View File

@@ -0,0 +1,24 @@
name: Go Release
on:
push:
tags:
- 'v*'
jobs:
release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Build releases
run: make releases
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
files: dist/*.tar.gz

36
.github/workflows/go-test.yml vendored Normal file
View File

@@ -0,0 +1,36 @@
name: Go Test
on:
push:
branches: [ "main" ]
paths:
- '**.go'
- 'go.mod'
pull_request:
branches: [ "main" ]
paths:
- '**.go'
- 'go.mod'
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.25'
- name: Install dependencies
run: go mod download
- name: Run tests with coverage
run: go test -v -coverprofile=coverage.txt ./...
- uses: codecov/codecov-action@v5
with:
files: ./coverage.txt
token: ${{ secrets.CODECOV_TOKEN }}

4
.gitignore vendored
View File

@@ -61,4 +61,6 @@ fabric.properties
*.vsix
config-local.yaml
gitea-pages
gitea-pages
*.zip
dist/

View File

@@ -1,17 +1,46 @@
GOPATH := $(shell go env GOPATH)
GOARCH ?= $(shell go env GOARCH)
GOOS ?= $(shell go env GOOS)
ifeq ($(GOOS),windows)
GO_DIST_NAME := gitea-pages.exe
else
GO_DIST_NAME := gitea-pages
endif
fmt:
@(test -f "$(GOPATH)/bin/gofumpt" || go install mvdan.cc/gofumpt@latest) && \
"$(GOPATH)/bin/gofumpt" -l -w .
.PHONY: release
release: dist/gitea-pages-$(GOOS)-$(GOARCH).tar.gz
dist/gitea-pages-$(GOOS)-$(GOARCH).tar.gz: $(shell find . -type f -name "*.go" ) go.mod go.sum
@echo Compile $@ via $(GO_DIST_NAME) && \
mkdir -p dist && \
rm -f dist/$(GO_DIST_NAME) && \
GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o dist/$(GO_DIST_NAME) . && \
cd dist && \
tar zcf gitea-pages-$(GOOS)-$(GOARCH).tar.gz $(GO_DIST_NAME) ../LICENSE ../config.yaml ../errors.html.tmpl ../README.md ../README_*.md && \
rm -f $(GO_DIST_NAME)
gitea-pages: $(shell find . -type f -name "*.go" ) go.mod go.sum
@CGO_ENABLED=0 go build -ldflags="-s -w" -o $@ .
@CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o $@ .
.PHONY: debug
debug: gitea-pages
@./gitea-pages -conf config-local.yaml -debug
.PHONY: test
test:
@go test -v ./...
@go test -v ./...
.PHONY: releases
releases:
@make release GOOS=linux GOARCH=amd64 && \
make release GOOS=linux GOARCH=arm64 && \
make release GOOS=linux GOARCH=loong64 && \
make release GOOS=windows GOARCH=amd64