mirror of
https://github.com/usememos/memos.git
synced 2025-02-14 02:10:39 +01: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
|
# Frontend asset
|
||||||
web/dist
|
web/dist
|
||||||
server/frontend/dist
|
|
||||||
|
|
||||||
# build folder
|
# build folder
|
||||||
build
|
build
|
||||||
@ -22,3 +21,5 @@ build
|
|||||||
bin/air
|
bin/air
|
||||||
|
|
||||||
dev-dist
|
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
|
WORKDIR /backend-build
|
||||||
|
|
||||||
COPY . .
|
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
|
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
|
RUN apk add --no-cache tzdata
|
||||||
ENV TZ="UTC"
|
ENV TZ="UTC"
|
||||||
|
|
||||||
COPY --from=frontend /frontend-build/web/dist /usr/local/memos/dist
|
|
||||||
COPY --from=backend /backend-build/memos /usr/local/memos/
|
COPY --from=backend /backend-build/memos /usr/local/memos/
|
||||||
|
|
||||||
EXPOSE 5230
|
EXPOSE 5230
|
||||||
|
@ -2,9 +2,10 @@ package frontend
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"embed"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
@ -18,6 +19,9 @@ import (
|
|||||||
"github.com/usememos/memos/store"
|
"github.com/usememos/memos/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//go:embed dist
|
||||||
|
var embeddedFiles embed.FS
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// maxMetadataDescriptionLength is the maximum length of metadata description.
|
// maxMetadataDescriptionLength is the maximum length of metadata description.
|
||||||
maxMetadataDescriptionLength = 256
|
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.
|
// Use echo static middleware to serve the built dist folder.
|
||||||
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
// refer: https://github.com/labstack/echo/blob/master/middleware/static.go
|
||||||
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Root: "dist",
|
HTML5: true,
|
||||||
HTML5: true,
|
Filesystem: getFileSystem("dist"),
|
||||||
Skipper: func(c echo.Context) bool {
|
Skipper: func(c echo.Context) bool {
|
||||||
return util.HasPrefixes(c.Path(), "/api", "/memos.api.v2", "/robots.txt", "/sitemap.xml", "/m/:name")
|
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 {
|
func generateMemoMetadata(memo *store.Memo, creator *store.User) *Metadata {
|
||||||
metadata := getDefaultMetadata()
|
metadata := getDefaultMetadata()
|
||||||
metadata.Title = fmt.Sprintf("%s(@%s) on Memos", creator.Nickname, creator.Username)
|
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 {
|
func getRawIndexHTML() string {
|
||||||
bytes, _ := os.ReadFile("dist/index.html")
|
bytes, _ := embeddedFiles.ReadFile("dist/index.html")
|
||||||
return string(bytes)
|
return string(bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user