ci: add ci
This commit is contained in:
parent
1874ae3ac1
commit
8ca548a5e3
65
.github/workflows/build.yml
vendored
Normal file
65
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
# This workflow will build a golang project
|
||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
|
||||
|
||||
name: Go
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [published]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-ubuntu:
|
||||
permissions:
|
||||
contents: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.24.4'
|
||||
- name: Setup NodeJS
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '24.2.0'
|
||||
- name: Build web
|
||||
working-directory: ./apps/web
|
||||
run: |
|
||||
npm ci
|
||||
npm run build
|
||||
mv dist/* ../api/web
|
||||
- name: Build server for linux
|
||||
working-directory: ./apps/api
|
||||
run: |
|
||||
GOOS=linux go build -v -o ./yabl-linux-x86_64 .
|
||||
GOOS=darwin go build -v -o ./yabl-darwin-x86_64 .
|
||||
GOOS=windows go build -v -o ./yabl-windows-x86_64.exe .
|
||||
- name: upload linux artifact
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./yabl-linux-x86_64
|
||||
asset_name: server-linux
|
||||
asset_content_type: application/octet-stream
|
||||
- name: upload darwin artifact
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./yabl-darwin-x86_64
|
||||
asset_name: yabl-darwin-x86_64
|
||||
asset_content_type: application/octet-stream
|
||||
- name: upload windows artifact
|
||||
uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ github.token }}
|
||||
with:
|
||||
upload_url: ${{ github.event.release.upload_url }}
|
||||
asset_path: ./yabl-windows-x86_64.exe
|
||||
asset_name: yabl-windows-x86_64.exe
|
||||
asset_content_type: application/octet-stream
|
||||
@ -222,7 +222,7 @@ type ReaderJSON struct {
|
||||
OnBookshelf bool `json:"onBookshelf"`
|
||||
}
|
||||
|
||||
//go:embed web/dist
|
||||
//go:embed web
|
||||
var embeddedWeb embed.FS
|
||||
|
||||
//go:embed fonts
|
||||
@ -327,7 +327,7 @@ func main() {
|
||||
} else {
|
||||
log.Fatalln("Not found KEYS_PATH env")
|
||||
}
|
||||
priv, pub := loadOrGenerateKeys(keysPath+"/private.pem", keysPath+"/public.pem")
|
||||
priv, pub := loadOrGenerateKeys(keysPath)
|
||||
|
||||
if len(os.Args) == 3 && os.Args[1] == "--authors-whitelist" {
|
||||
GenWhitelist(db, os.Args[2])
|
||||
@ -342,8 +342,8 @@ func main() {
|
||||
router := gin.Default()
|
||||
// router.Use(cors.Default())
|
||||
|
||||
//router.StaticFileFS("/", "/web/dist/", http.FS(embeddedWeb))
|
||||
rootFS, _ := fs.Sub(embeddedWeb, "web/dist")
|
||||
//router.StaticFileFS("/", "/web/", http.FS(embeddedWeb))
|
||||
rootFS, _ := fs.Sub(embeddedWeb, "web")
|
||||
|
||||
router.NoRoute(func(ctx *gin.Context) {
|
||||
_, err := rootFS.Open(strings.TrimLeft(ctx.Request.URL.Path, "/"))
|
||||
@ -1321,19 +1321,22 @@ func (APICollection) TableName() string {
|
||||
return "collections"
|
||||
}
|
||||
|
||||
func loadOrGenerateKeys(privateKeyFile string, publicKeyFile string) (*rsa.PrivateKey, *rsa.PublicKey) {
|
||||
_, errPrivate := os.Stat(privateKeyFile)
|
||||
_, errPublic := os.Stat(publicKeyFile)
|
||||
func loadOrGenerateKeys(keysPath string) (*rsa.PrivateKey, *rsa.PublicKey) {
|
||||
privatePath := keysPath + "/private.pem"
|
||||
publicPath := keysPath + "/public.pem"
|
||||
_, errPrivate := os.Stat(privatePath)
|
||||
_, errPublic := os.Stat(publicPath)
|
||||
if errors.Is(errPrivate, os.ErrNotExist) || errors.Is(errPublic, os.ErrNotExist) {
|
||||
log.Println("Generating JWT keys...")
|
||||
os.MkdirAll(keysPath, os.ModePerm)
|
||||
priv, _ := rsa.GenerateKey(rand.Reader, 2048)
|
||||
privBytes := x509.MarshalPKCS1PrivateKey(priv)
|
||||
err := os.WriteFile(privateKeyFile, pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: privBytes}), 0600)
|
||||
err := os.WriteFile(privatePath, pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: privBytes}), 0600)
|
||||
if err != nil {
|
||||
log.Panicln("Unable to write private JWT key")
|
||||
}
|
||||
pubBytes, _ := x509.MarshalPKIXPublicKey(&priv.PublicKey)
|
||||
err = os.WriteFile(publicKeyFile, pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: pubBytes}), 0644)
|
||||
err = os.WriteFile(publicPath, pem.EncodeToMemory(&pem.Block{Type: "PUBLIC KEY", Bytes: pubBytes}), 0644)
|
||||
if err != nil {
|
||||
log.Panicln("Unable to write public JWT key")
|
||||
}
|
||||
@ -1343,11 +1346,11 @@ func loadOrGenerateKeys(privateKeyFile string, publicKeyFile string) (*rsa.Priva
|
||||
log.Panicln("Something went wrong with key files")
|
||||
}
|
||||
|
||||
privPem, _ := os.ReadFile(privateKeyFile)
|
||||
privPem, _ := os.ReadFile(privatePath)
|
||||
privBlock, _ := pem.Decode(privPem)
|
||||
priv, _ := x509.ParsePKCS1PrivateKey(privBlock.Bytes)
|
||||
|
||||
pubPem, _ := os.ReadFile(publicKeyFile)
|
||||
pubPem, _ := os.ReadFile(publicPath)
|
||||
pubBlock, _ := pem.Decode(pubPem)
|
||||
pubRaw, _ := x509.ParsePKIXPublicKey(pubBlock.Bytes)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user