Skip to content

Commit

Permalink
workflow: 合并前后端工作流
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Dec 20, 2024
1 parent c5b23aa commit bbe07f7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 55 deletions.
49 changes: 38 additions & 11 deletions .github/workflows/backend.yml → .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,46 @@
name: Backend
name: Build
on:
push:
branches:
- main
pull_request:
jobs:
build:
frontend:
runs-on: ubuntu-24.04
defaults:
run:
working-directory: web
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
with:
version: latest
run_install: true
package_json_file: web/package.json
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 22
cache: 'pnpm'
cache-dependency-path: web/pnpm-lock.yaml
- name: Build frontend
# We need to run the dev server first to generate the auto-imports files
run: |
cp .env.production .env
cp settings/proxy-config.example.ts settings/proxy-config.ts
pnpm dev &
sleep 5
kill %1
pnpm build
- name: Upload frontend
uses: actions/upload-artifact@v4
with:
name: frontend
path: web/dist/ # https://github.com/actions/upload-artifact/issues/541
backend:
needs: frontend
runs-on: ubuntu-24.04
strategy:
matrix:
Expand All @@ -23,19 +58,11 @@ jobs:
go-version: 'stable'
- name: Install dependencies
run: go mod tidy
- name: Wait for frontend build
uses: lewagon/[email protected]
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
check-name: 'build (frontend)'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Download frontend
uses: dawidd6/action-download-artifact@v7
uses: actions/download-artifact@v4
with:
workflow: frontend.yml
name: frontend
path: internal/embed/frontend
check_artifacts: true
- name: Set build info
run: |
echo "VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo '0.0.0')" >> $GITHUB_ENV
Expand Down
42 changes: 0 additions & 42 deletions .github/workflows/frontend.yml

This file was deleted.

2 changes: 1 addition & 1 deletion cmd/web/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion internal/app/web.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"context"
"errors"
"fmt"
"net/http"
Expand All @@ -12,6 +13,8 @@ import (
"github.com/gookit/validate"
"github.com/knadh/koanf/v2"
"github.com/robfig/cron/v3"

"github.com/TheTNB/panel/pkg/queue"
)

type Web struct {
Expand All @@ -20,15 +23,17 @@ type Web struct {
server *hlfhr.Server
migrator *gormigrate.Gormigrate
cron *cron.Cron
queue *queue.Queue
}

func NewWeb(conf *koanf.Koanf, router *chi.Mux, server *hlfhr.Server, migrator *gormigrate.Gormigrate, cron *cron.Cron, _ *validate.Validation) *Web {
func NewWeb(conf *koanf.Koanf, router *chi.Mux, server *hlfhr.Server, migrator *gormigrate.Gormigrate, cron *cron.Cron, queue *queue.Queue, _ *validate.Validation) *Web {
return &Web{
conf: conf,
router: router,
server: server,
migrator: migrator,
cron: cron,
queue: queue,
}
}

Expand All @@ -43,6 +48,9 @@ func (r *Web) Run() error {
r.cron.Start()
fmt.Println("[CRON] cron scheduler started")

// start queue
r.queue.Run(context.TODO())

// run http server
if r.conf.Bool("http.tls") {
cert := filepath.Join(Root, "panel/storage/cert.pem")
Expand Down

0 comments on commit bbe07f7

Please sign in to comment.