diff --git a/.github/workflows/go-release.yml b/.github/workflows/go-release.yml new file mode 100644 index 0000000..bda028f --- /dev/null +++ b/.github/workflows/go-release.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/go-test.yml b/.github/workflows/go-test.yml new file mode 100644 index 0000000..53e90dd --- /dev/null +++ b/.github/workflows/go-test.yml @@ -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 }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7dcac90..1052c35 100644 --- a/.gitignore +++ b/.gitignore @@ -61,4 +61,6 @@ fabric.properties *.vsix config-local.yaml -gitea-pages \ No newline at end of file +gitea-pages +*.zip +dist/ \ No newline at end of file diff --git a/Makefile b/Makefile index 56fdab6..4165b73 100644 --- a/Makefile +++ b/Makefile @@ -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 ./... \ No newline at end of file + @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