diff --git a/.github/workflows/backend.yml b/.github/workflows/build.yml similarity index 69% rename from .github/workflows/backend.yml rename to .github/workflows/build.yml index c195e69a99..96d8643b07 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/build.yml @@ -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: @@ -23,19 +58,11 @@ jobs: go-version: 'stable' - name: Install dependencies run: go mod tidy - - name: Wait for frontend build - uses: lewagon/wait-on-check-action@v1.3.4 - 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 diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml deleted file mode 100644 index 8706b827f1..0000000000 --- a/.github/workflows/frontend.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Frontend -on: - push: - branches: - - main - pull_request: -jobs: - build: - name: 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 diff --git a/cmd/web/wire_gen.go b/cmd/web/wire_gen.go index 2487566358..a537cdf189 100644 --- a/cmd/web/wire_gen.go +++ b/cmd/web/wire_gen.go @@ -141,6 +141,6 @@ func initWeb() (*app.Web, error) { return nil, err } validation := bootstrap.NewValidator(db) - web := app.NewWeb(koanf, mux, server, gormigrate, cron, validation) + web := app.NewWeb(koanf, mux, server, gormigrate, cron, queue, validation) return web, nil } diff --git a/internal/app/web.go b/internal/app/web.go index 4d0da6e865..1fbb08e0e9 100644 --- a/internal/app/web.go +++ b/internal/app/web.go @@ -1,6 +1,7 @@ package app import ( + "context" "errors" "fmt" "net/http" @@ -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 { @@ -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, } } @@ -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")