diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 65ed95a..8acd53b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -24,6 +24,9 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 + - name: Build Vue App + run: cd internal/admin/ui && npm ci && npm run build + - name: Cache go mod uses: actions/cache@v2 with: @@ -55,6 +58,9 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 + - name: Build Vue App + run: cd internal/admin/ui && npm ci && npm run build + - name: Cache go mod uses: actions/cache@v2 with: diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7d39b28..d402df3 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -38,34 +38,37 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed steps: - - name: Checkout repository - uses: actions/checkout@v2 + - name: Checkout repository + uses: actions/checkout@v2 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main + - name: Build Vue App + run: cd internal/admin/ui && npm ci && npm run build - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + # queries: ./path/to/local/query, your-org/your-repo/queries@main - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl + # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v1 - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language + # â„šī¸ Command-line programs to run using the OS shell. + # 📚 https://git.io/JvXDl - #- run: | - # make bootstrap - # make release + # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines + # and modify them (or add more) to build your code if your project + # uses a compiled language - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + #- run: | + # make bootstrap + # make release + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/staticcheck.yaml b/.github/workflows/staticcheck.yaml index 382465e..af5f2c6 100644 --- a/.github/workflows/staticcheck.yaml +++ b/.github/workflows/staticcheck.yaml @@ -22,6 +22,9 @@ jobs: - name: Checkout Code uses: actions/checkout@v2 + - name: Build Vue App + run: cd internal/admin/ui && npm ci && npm run build + - name: Cache go mod uses: actions/cache@v2 with: diff --git a/.gitignore b/.gitignore index 7dd4c14..bc35d94 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ Desktop.ini # Build build/ output/ +dist/ # Config config.yaml \ No newline at end of file diff --git a/internal/admin/admin.go b/internal/admin/admin.go new file mode 100644 index 0000000..d4d0208 --- /dev/null +++ b/internal/admin/admin.go @@ -0,0 +1,26 @@ +package admin + +import ( + "embed" + "io/fs" + "net/http" + + "go.uber.org/zap" + + "github.com/gorilla/mux" +) + +//go:embed ui/dist +var adminUI embed.FS + +func Serve(r *mux.Router, log *zap.Logger) { + sub, err := fs.Sub(adminUI, "ui/dist") + if err != nil { + log.Error("failed to get subtree for admin pages", zap.Error(err)) + return + } + + adminFS := http.FileServer(http.FS(sub)) + + r.PathPrefix("/admin").Handler(http.StripPrefix("/admin", adminFS)) +} diff --git a/internal/admin/ui/vite.config.js b/internal/admin/ui/vite.config.js index 315212d..7d481c7 100644 --- a/internal/admin/ui/vite.config.js +++ b/internal/admin/ui/vite.config.js @@ -3,5 +3,6 @@ import vue from '@vitejs/plugin-vue' // https://vitejs.dev/config/ export default defineConfig({ - plugins: [vue()] + plugins: [vue()], + base: '/admin/' }) diff --git a/internal/server/server.go b/internal/server/server.go index 3144dce..ee968ac 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -70,7 +70,7 @@ func (s *Server) setup() { defer s.graceFullShutdown() if !s.apiOnly { - web.Routes(s.router) + web.Routes(s.router, s.logger) } apiRouter := s.router.PathPrefix("/api").Subrouter() diff --git a/internal/server/web/web.go b/internal/server/web/web.go index 7770cd0..3a7f801 100644 --- a/internal/server/web/web.go +++ b/internal/server/web/web.go @@ -1,7 +1,11 @@ package web -import "github.com/gorilla/mux" - -func Routes(r *mux.Router) { +import ( + "github.com/aveloper/blog/internal/admin" + "github.com/gorilla/mux" + "go.uber.org/zap" +) +func Routes(r *mux.Router, log *zap.Logger) { + admin.Serve(r, log) } diff --git a/scripts/build.sh b/scripts/build.sh index 01b4594..20ca64b 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -1,13 +1,19 @@ #!/bin/sh +echo "Building Admin UI" + +cd internal/admin/ui && npm install && npm run build || exit 1 + +cd ../../.. || exit 1 + echo "Running go generate" -go generate ./... +go generate ./... || exit 1 echo "Fetching latest version information" # Fetch the latest to ensure we have the latest tag -git fetch origin +git fetch origin || exit 1 # Get the version from the git tag # If not available, default to v0.0.0