Compare commits

...

4 Commits

Author SHA1 Message Date
Joel Wetzell 248081e305 add webui to remaining builds 2026-05-23 11:41:16 -05:00
Joel Wetzell 159bb80bca dont use full ref in fallback showbridge_version property 2026-05-23 11:33:56 -05:00
Joel Wetzell 3f7323ccef add job to checkout and build webui into binary 2026-05-23 11:28:41 -05:00
Joel Wetzell 704f593c87 add optional webui behind a build tag 2026-05-23 11:25:25 -05:00
5 changed files with 151 additions and 7 deletions
+63 -7
View File
@@ -21,7 +21,7 @@ jobs:
with:
fetch-depth: 0
- name: set environment variables
run: echo "SHOWBRIDGE_VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
run: echo "SHOWBRIDGE_VERSION=${GITHUB_SHA::7}" >> $GITHUB_ENV
- name: clean tag
if: startsWith(github.ref, 'refs/tags/v')
run: echo "SHOWBRIDGE_VERSION=${SHOWBRIDGE_VERSION#v}" >> $GITHUB_ENV
@@ -37,6 +37,37 @@ jobs:
with:
draft: true
generate_release_notes: true
build_webui:
runs-on: ubuntu-latest
needs: setup_release
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
steps:
- name: Check out repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: jwetzell/showbridge-webui
ref: main
- name: Set up Node.js
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: ".nvmrc"
cache: "npm"
cache-dependency-path: "package-lock.json"
- name: Install Node.js dependencies
run: npm ci
- run: npm run build -- --base-href=/ui/
- name: upload webui artifacts
uses: actions/upload-artifact@v7
with:
name: showbridge-webui
path: dist/webui/
linux_amd64:
runs-on: ubuntu-24.04
needs: setup_release
@@ -54,6 +85,11 @@ jobs:
go-version-file: "go.mod"
- name: install alsa lib
run: sudo apt-get install -y libasound2-dev
- name: get webui artifacts
uses: actions/download-artifact@v8
with:
name: showbridge-webui
path: internal/api/webui/
- name: build
run: |
CGO_ENABLED=1 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
@@ -88,9 +124,14 @@ jobs:
go-version-file: "go.mod"
- name: install alsa lib
run: sudo apt-get install -y libasound2-dev
- name: get webui artifacts
uses: actions/download-artifact@v8
with:
name: showbridge-webui
path: internal/api/webui/
- name: build
run: |
CGO_ENABLED=1 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
CGO_ENABLED=1 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" -tags=showbridge_webui ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_linux-arm64.tar.gz showbridge
- name: upload linux artifacts
uses: actions/upload-artifact@v7
@@ -124,13 +165,18 @@ jobs:
uses: mlugg/setup-zig@v2
with:
version: 0.16.0
- name: get webui artifacts
uses: actions/download-artifact@v8
with:
name: showbridge-webui
path: internal/api/webui/
- name: build amd64
run: |
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zig cc -target x86_64-windows-gnu" CXX="zig c++ -target x86_64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zig cc -target x86_64-windows-gnu" CXX="zig c++ -target x86_64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" -tags=showbridge_webui ./cmd/showbridge
zip showbridge_${SHOWBRIDGE_VERSION}_windows-amd64.zip showbridge.exe
- name: build arm64
run: |
CGO_ENABLED=1 GOOS=windows GOARCH=arm64 CC="zig cc -target aarch64-windows-gnu" CXX="zig c++ -target aarch64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
CGO_ENABLED=1 GOOS=windows GOARCH=arm64 CC="zig cc -target aarch64-windows-gnu" CXX="zig c++ -target aarch64-windows-gnu" go build -o showbridge.exe -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" -tags=showbridge_webui ./cmd/showbridge
zip showbridge_${SHOWBRIDGE_VERSION}_windows-arm64.zip showbridge.exe
- name: upload windows artifacts
uses: actions/upload-artifact@v7
@@ -160,9 +206,14 @@ jobs:
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: get webui artifacts
uses: actions/download-artifact@v8
with:
name: showbridge-webui
path: internal/api/webui/
- name: build
run: |
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" -tags=showbridge_webui ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_macOS-arm64.tar.gz showbridge
- name: upload macos artifacts
uses: actions/upload-artifact@v7
@@ -179,7 +230,7 @@ jobs:
files: showbridge_*.tar.gz
macos_amd64:
runs-on: macos-26-intel
needs: setup_release
needs: [setup_release, build_webui]
env:
SHOWBRIDGE_VERSION: ${{ needs.setup_release.outputs.version }}
SHORT_COMMIT: ${{ needs.setup_release.outputs.short_commit }}
@@ -192,9 +243,14 @@ jobs:
uses: actions/setup-go@v6
with:
go-version-file: "go.mod"
- name: get webui artifacts
uses: actions/download-artifact@v8
with:
name: showbridge-webui
path: internal/api/webui/
- name: build
run: |
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" ./cmd/showbridge
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o showbridge -ldflags="-s -w -X main.version=${SHOWBRIDGE_VERSION}-${SHORT_COMMIT}" -tags=showbridge_webui ./cmd/showbridge
tar -czf showbridge_${SHOWBRIDGE_VERSION}_macOS-amd64.tar.gz showbridge
- name: upload macos artifacts
uses: actions/upload-artifact@v7
+1
View File
@@ -0,0 +1 @@
webui/
+2
View File
@@ -48,6 +48,8 @@ func (as *ApiServer) Start(config config.ApiConfig) {
mux.HandleFunc("/schema/routes.schema.json", handleRoutesSchema)
mux.HandleFunc("/schema/modules.schema.json", handleModulesSchema)
mux.HandleFunc("/schema/processors.schema.json", handleProcessorsSchema)
mux.HandleFunc("/ui", handleWebUI)
mux.HandleFunc("/ui/", handleWebUI)
as.serverMu.Lock()
defer as.serverMu.Unlock()
+12
View File
@@ -0,0 +1,12 @@
//go:build !showbridge_webui
package api
import (
"net/http"
)
func handleWebUI(w http.ResponseWriter, req *http.Request) {
http.Error(w, "Web UI is not enabled", http.StatusNotImplemented)
}
+73
View File
@@ -0,0 +1,73 @@
//go:build showbridge_webui
package api
import (
"embed"
"errors"
"io/fs"
"net/http"
"path"
"strings"
_ "embed"
)
//go:embed webui
var webUIFS embed.FS
var fsPrefix = "webui/browser"
var index = path.Join(fsPrefix, "index.html")
func handleWebUI(w http.ResponseWriter, req *http.Request) {
requestedPath := strings.TrimLeft(req.URL.Path, "/ui")
switch req.Method {
case http.MethodGet:
var pathToLoad string
stat, err := fs.Stat(webUIFS, path.Join(fsPrefix, requestedPath))
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
pathToLoad = index
} else {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
}
if stat != nil {
if stat.IsDir() {
pathToLoad = index
} else {
pathToLoad = path.Join(fsPrefix, requestedPath)
}
}
file, err := webUIFS.ReadFile(pathToLoad)
if err != nil {
http.Error(w, "Internal server error", http.StatusInternalServerError)
return
}
w.Header().Set("Access-Control-Allow-Origin", "*")
switch path.Ext(pathToLoad) {
case ".js":
w.Header().Set("Content-Type", "application/javascript")
case ".css":
w.Header().Set("Content-Type", "text/css")
case ".html":
w.Header().Set("Content-Type", "text/html")
case ".ico":
w.Header().Set("Content-Type", "image/x-icon")
}
w.Write(file)
return
case http.MethodOptions:
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS")
w.Header().Set("Access-Control-Allow-Headers", "Content-Type")
w.WriteHeader(http.StatusOK)
default:
w.Header().Set("Access-Control-Allow-Origin", "*")
w.WriteHeader(http.StatusMethodNotAllowed)
}
}