ci: build web

This commit is contained in:
levi committed 2022-11-01 15:13:59 +08:00
1 parent ff4e6f448c
commit bf8e24a6af
13 files changed
+140 -74

No files matched your search

+73 -34
View File
@@ -25,39 +25,39 @@ jobs:
id: create_release id: create_release
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
build-cli: # build-cli:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
needs: [ release ] # needs: [ release ]
steps: # steps:
- uses: actions/checkout@v3 # - uses: actions/checkout@v3
- uses: actions/setup-go@v3 # - uses: actions/setup-go@v3
with: # with:
go-version: '^1.19' # go-version: '^1.19'
cache: true # cache: true
- name: Build # - name: Build
env: # env:
VERSION: ${{ needs.release.outputs.tag_name }} # VERSION: ${{ needs.release.outputs.tag_name }}
run: | # run: |
mkdir -p dist/zip # mkdir -p dist/zip
goos_arr=(windows darwin linux) # goos_arr=(windows darwin linux)
goarch_arr=(386 amd64 arm64) # goarch_arr=(386 amd64 arm64)
export CGO_ENABLED=0 # export CGO_ENABLED=0
for goos in "${goos_arr[@]}"; do # for goos in "${goos_arr[@]}"; do
for goarch in "${goarch_arr[@]}"; do # for goarch in "${goarch_arr[@]}"; do
dir="dist/gopeed-$VERSION-$goos-$goarch/" # dir="dist/gopeed-$VERSION-$goos-$goarch/"
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/gopeed \ # (GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/gopeed \
&& cd $dir \ # && cd $dir \
&& zip -r ../zip/gopeed-cli-$VERSION-$goos-$goarch.zip * \ # && zip -r ../zip/gopeed-cli-$VERSION-$goos-$goarch.zip * \
&& cd ../..) \ # && cd ../..) \
|| true # || true
done # done
done # done
- name: Upload # - name: Upload
uses: shogo82148/actions-upload-release-asset@v1 # uses: shogo82148/actions-upload-release-asset@v1
with: # with:
upload_url: ${{ needs.release.outputs.upload_url }} # upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: dist/zip/* # asset_path: dist/zip/*
overwrite: true # overwrite: true
build-macos-arm64-lib: build-macos-arm64-lib:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [ release ] needs: [ release ]
@@ -163,7 +163,7 @@ jobs:
mkdir ui/flutter/android/app/libs mkdir ui/flutter/android/app/libs
go install golang.org/x/mobile/cmd/gomobile@latest go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init gomobile init
gomobile bind -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile gomobile bind -tags nosqlite -ldflags="-w -s" -o ui/flutter/android/app/libs/libgopeed.aar -target=android -androidapi 19 -javapkg=com.gopeed github.com/monkeyWie/gopeed/bind/mobile
cd ui/flutter cd ui/flutter
flutter build apk flutter build apk
mkdir dist mkdir dist
@@ -174,3 +174,42 @@ jobs:
upload_url: ${{ needs.release.outputs.upload_url }} upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: ui/flutter/dist/* asset_path: ui/flutter/dist/*
overwrite: true overwrite: true
build-web:
runs-on: ubuntu-latest
needs: [ release ]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v3
with:
go-version: '^1.19'
cache: true
- uses: subosito/flutter-action@v2
- name: Build
env:
VERSION: ${{ needs.release.outputs.tag_name }}
run: |
cd ui/flutter
flutter build web
cd ../../
cp -r ui/flutter/build/web cmd/web/dist
mkdir -p dist/zip
goos_arr=(windows darwin linux)
goarch_arr=(386 amd64 arm64)
export CGO_ENABLED=0
for goos in "${goos_arr[@]}"; do
for goarch in "${goarch_arr[@]}"; do
dir="dist/gopeed-$VERSION-$goos-$goarch/"
(GOOS=$goos GOARCH=$goarch go build -tags nosqlite -ldflags="-s -w" -o $dir github.com/monkeyWie/gopeed/cmd/web \
&& cd $dir \
&& rename 's/^web/gopeed/' * \
&& zip -r ../zip/gopeed-web-$VERSION-$goos-$goarch.zip * \
&& cd ../..) \
|| true
done
done
- name: Upload
uses: shogo82148/actions-upload-release-asset@v1
with:
upload_url: ${{ needs.release.outputs.upload_url }}
asset_path: dist/zip/*
overwrite: true
+3 -1
View File
@@ -22,4 +22,6 @@ bin/
*.data *.data
*.db *.db
.DS_Store .DS_Store
dist/
File renamed without changes.
File renamed without changes.
-16
View File
@@ -1,16 +0,0 @@
package main
import (
"github.com/monkeyWie/gopeed/pkg/rest"
"github.com/monkeyWie/gopeed/pkg/rest/model"
)
func main() {
if err := rest.StartSync(&model.StartConfig{
Network: "tcp",
Address: "127.0.0.1:9999",
Storage: model.StorageMem,
}); err != nil {
panic(err)
}
}
+7
View File
@@ -0,0 +1,7 @@
_______ ______ .______ _______ _______ _______
/ _____| / __ \ | _ \ | ____|| ____|| \
| | __ | | | | | |_) | | |__ | |__ | .--. |
| | |_ | | | | | | ___/ | __| | __| | | | |
| |__| | | `--' | | | | |____ | |____ | '--' |
\______| \______/ | _| |_______||_______||_______/
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"embed"
"fmt"
"github.com/monkeyWie/gopeed/pkg/rest"
"github.com/monkeyWie/gopeed/pkg/rest/model"
"io/fs"
"net/http"
)
//go:embed banner.txt
var banner string
//go:embed dist/*
var dist embed.FS
func main() {
sub, err := fs.Sub(dist, "dist")
if err != nil {
panic(err)
}
cfg := &model.StartConfig{
Network: "tcp",
Address: "127.0.0.1:9999",
Storage: model.StorageMem,
WebEnable: true,
WebFS: sub,
}
fmt.Println(banner)
srv, listener, err := rest.BuildServer(cfg)
if err != nil {
panic(err)
}
fmt.Printf("Server start success on http://%s\n", listener.Addr().String())
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
panic(err)
}
}
+5 -5
View File
@@ -1,6 +1,7 @@
package controller package controller
import ( import (
"errors"
"os" "os"
"path/filepath" "path/filepath"
) )
@@ -11,11 +12,10 @@ type Controller interface {
} }
type DefaultController struct { type DefaultController struct {
Files map[string]*os.File
} }
func NewController() *DefaultController { func NewController() *DefaultController {
return &DefaultController{Files: make(map[string]*os.File)} return &DefaultController{}
} }
func (c *DefaultController) Touch(name string, size int64) (file *os.File, err error) { func (c *DefaultController) Touch(name string, size int64) (file *os.File, err error) {
@@ -24,15 +24,15 @@ func (c *DefaultController) Touch(name string, size int64) (file *os.File, err e
return return
} }
file, err = os.Create(name) file, err = os.Create(name)
if err != nil && !errors.Is(err, os.ErrExist) {
return
}
if size > 0 { if size > 0 {
err = os.Truncate(name, size) err = os.Truncate(name, size)
if err != nil { if err != nil {
return nil, err return nil, err
} }
} }
if err == nil {
c.Files[name] = file
}
return return
} }
+5
View File
@@ -1,5 +1,7 @@
package model package model
import "io/fs"
type Storage string type Storage string
const ( const (
@@ -13,6 +15,9 @@ type StartConfig struct {
Storage Storage `json:"storage"` Storage Storage `json:"storage"`
StorageDir string `json:"storageDir"` StorageDir string `json:"storageDir"`
RefreshInterval int `json:"refreshInterval"` RefreshInterval int `json:"refreshInterval"`
WebEnable bool
WebFS fs.FS
} }
func (cfg *StartConfig) Init() *StartConfig { func (cfg *StartConfig) Init() *StartConfig {
+5 -13
View File
@@ -19,7 +19,7 @@ var (
) )
func Start(startCfg *model.StartConfig) (int, error) { func Start(startCfg *model.StartConfig) (int, error) {
srv, listener, err := buildServer(startCfg) srv, listener, err := BuildServer(startCfg)
if err != nil { if err != nil {
return 0, err return 0, err
} }
@@ -38,17 +38,6 @@ func Start(startCfg *model.StartConfig) (int, error) {
return port, nil return port, nil
} }
func StartSync(startCfg *model.StartConfig) error {
srv, listener, err := buildServer(startCfg)
if err != nil {
return err
}
if err := srv.Serve(listener); err != nil && err != http.ErrServerClosed {
return err
}
return nil
}
func Stop() { func Stop() {
if srv != nil { if srv != nil {
if err := srv.Shutdown(context.TODO()); err != nil { if err := srv.Shutdown(context.TODO()); err != nil {
@@ -62,7 +51,7 @@ func Stop() {
} }
} }
func buildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error) { func BuildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error) {
if startCfg == nil { if startCfg == nil {
startCfg = &model.StartConfig{} startCfg = &model.StartConfig{}
} }
@@ -104,6 +93,9 @@ func buildServer(startCfg *model.StartConfig) (*http.Server, net.Listener, error
r.Methods(http.MethodGet).Path("/api/v1/tasks").HandlerFunc(GetTasks) r.Methods(http.MethodGet).Path("/api/v1/tasks").HandlerFunc(GetTasks)
r.Methods(http.MethodGet).Path("/api/v1/config").HandlerFunc(GetConfig) r.Methods(http.MethodGet).Path("/api/v1/config").HandlerFunc(GetConfig)
r.Methods(http.MethodPut).Path("/api/v1/config").HandlerFunc(PutConfig) r.Methods(http.MethodPut).Path("/api/v1/config").HandlerFunc(PutConfig)
if startCfg.WebEnable {
r.PathPrefix("/").Handler(http.FileServer(http.FS(startCfg.WebFS)))
}
srv = &http.Server{Handler: handlers.CORS( srv = &http.Server{Handler: handlers.CORS(
handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}), handlers.AllowedHeaders([]string{"X-Requested-With", "Content-Type", "Authorization"}),
+1 -2
View File
@@ -32,7 +32,6 @@
/build/ /build/
# Web related # Web related
lib/generated_plugin_registrant.dart
# Symbolication related # Symbolication related
app.*.symbols app.*.symbols
@@ -47,4 +46,4 @@ app.*.map.json
android/app/libs/libgopeed.aar android/app/libs/libgopeed.aar
android/app/libs/libgopeed-sources.jar android/app/libs/libgopeed-sources.jar
macos/Frameworks/libgopeed.h macos/Frameworks/libgopeed.h
macos/Frameworks/libgopeed.dylib macos/Frameworks/libgopeed.dylib
@@ -5,7 +5,8 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<application android:requestLegacyExternalStorage="true" <application
android:requestLegacyExternalStorage="true"
android:name="${applicationName}" android:name="${applicationName}"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="gopeed"> android:label="gopeed">
-2
View File
@@ -114,8 +114,6 @@ class Item extends StatelessWidget {
list.add(IconButton( list.add(IconButton(
icon: const Icon(Icons.folder_open), icon: const Icon(Icons.folder_open),
onPressed: () async { onPressed: () async {
print(Util.buildAbsPath(task.opts.path, task.res.files[0].path,
task.res.files[0].name));
final file = File(Util.buildAbsPath(task.opts.path, final file = File(Util.buildAbsPath(task.opts.path,
task.res.files[0].path, task.res.files[0].name)); task.res.files[0].path, task.res.files[0].name));
await launchUrl(file.parent.uri); await launchUrl(file.parent.uri);