mirror of
https://github.com/usememos/memos.git
synced 2024-11-23 22:07:47 +03:00
feat: add goreleaser
This commit is contained in:
parent
647602beac
commit
5f26c52b49
33
.github/workflows/build-artifacts.yml
vendored
Normal file
33
.github/workflows/build-artifacts.yml
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
name: Build artifacts
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
- uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: 1.22
|
||||
check-latest: true
|
||||
cache: true
|
||||
- name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v5
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
# 'latest', 'nightly', or a semver
|
||||
version: latest
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
3
.gitignore
vendored
3
.gitignore
vendored
@ -6,7 +6,6 @@ tmp
|
||||
|
||||
# Frontend asset
|
||||
web/dist
|
||||
server/frontend/dist
|
||||
|
||||
# build folder
|
||||
build
|
||||
@ -22,3 +21,5 @@ build
|
||||
bin/air
|
||||
|
||||
dev-dist
|
||||
|
||||
dist/
|
||||
|
38
.goreleaser.yaml
Normal file
38
.goreleaser.yaml
Normal file
@ -0,0 +1,38 @@
|
||||
version: 1
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
main: ./bin/memos
|
||||
binary: memos
|
||||
goos:
|
||||
- linux
|
||||
- darwin
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||
name_template: >-
|
||||
{{ .ProjectName }}_{{ .Tag }}_{{ .Os }}_{{ .Arch }}
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
|
||||
checksum:
|
||||
disable: true
|
||||
|
||||
release:
|
||||
draft: true
|
||||
replace_existing_draft: true
|
||||
make_latest: true
|
||||
mode: replace
|
||||
skip_upload: false
|
@ -15,6 +15,7 @@ FROM golang:1.22-alpine AS backend
|
||||
WORKDIR /backend-build
|
||||
|
||||
COPY . .
|
||||
COPY --from=frontend /frontend-build/web/dist /backend-build/server/route/frontend/dist
|
||||
|
||||
RUN CGO_ENABLED=0 go build -o memos ./bin/memos/main.go
|
||||
|
||||
@ -25,7 +26,6 @@ WORKDIR /usr/local/memos
|
||||
RUN apk add --no-cache tzdata
|
||||
ENV TZ="UTC"
|
||||
|
||||
COPY --from=frontend /frontend-build/web/dist /usr/local/memos/dist
|
||||
COPY --from=backend /backend-build/memos /usr/local/memos/
|
||||
|
||||
EXPOSE 5230
|
||||
|
@ -2,9 +2,10 @@ package frontend
|
||||
|
||||
import (
|
||||
"context"
|
||||
"embed"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -18,6 +19,9 @@ import (
|
||||
"github.com/usememos/memos/store"
|
||||
)
|
||||
|
||||
//go:embed dist
|
||||
var embeddedFiles embed.FS
|
||||
|
||||
const (
|
||||
// maxMetadataDescriptionLength is the maximum length of metadata description.
|
||||
maxMetadataDescriptionLength = 256
|
||||
@ -39,8 +43,8 @@ func (s *FrontendService) Serve(ctx context.Context, e *echo.Echo) {
|
||||
// Use echo static middleware to serve the built dist folder.
|
||||
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||
Root: "dist",
|
||||
HTML5: true,
|
||||
HTML5: true,
|
||||
Filesystem: getFileSystem("dist"),
|
||||
Skipper: func(c echo.Context) bool {
|
||||
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v2", "/robots.txt", "/sitemap.xml", "/m/:name")
|
||||
},
|
||||
@ -115,6 +119,15 @@ Sitemap: %s/sitemap.xml`, instanceURL, instanceURL)
|
||||
})
|
||||
}
|
||||
|
||||
func getFileSystem(path string) http.FileSystem {
|
||||
fs, err := fs.Sub(embeddedFiles, path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return http.FS(fs)
|
||||
}
|
||||
|
||||
func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
|
||||
metadata := getDefaultMetadata()
|
||||
metadata.Title = fmt.Sprintf("%s(@%s) on Memos", creator.Nickname, creator.Username)
|
||||
@ -135,7 +148,7 @@ func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
|
||||
}
|
||||
|
||||
func getRawIndexHTML() string {
|
||||
bytes, _ := os.ReadFile("dist/index.html")
|
||||
bytes, _ := embeddedFiles.ReadFile("dist/index.html")
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user