Skip to content

Commit

Permalink
error message & CI
Browse files Browse the repository at this point in the history
  • Loading branch information
MXWXZ committed May 27, 2024
1 parent 569ed42 commit 6c8544e
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 69 deletions.
105 changes: 105 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Release

on:
push:
tags:
- "v*"

jobs:
build_frontend:
name: Build frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "yarn"
- run: yarn
working-directory: skynet/frontend
- run: yarn build
working-directory: skynet/frontend
- uses: actions/upload-artifact@v4
with:
name: frontend
path: skynet/frontend/dist

build_skynet:
needs: build_frontend
name: Build skynet ${{ matrix.platform.os_name }}
runs-on: ${{ matrix.platform.os }}
strategy:
matrix:
platform:
- os_name: linux-x86_64
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
bin: skynet
name: skynet-linux-x86_64.tar.gz
- os_name: linux-i686
os: ubuntu-20.04
target: i686-unknown-linux-gnu
bin: skynet
name: skynet-linux-i686.tar.gz
- os_name: linux-aarch64
os: ubuntu-20.04
target: aarch64-unknown-linux-gnu
bin: skynet
name: skynet-linux-aarch64.tar.gz
- os_name: windows-x86_64
os: windows-latest
target: x86_64-pc-windows-gnu
bin: skynet.exe
name: skynet-windows-x86_64.zip
- os_name: macOS-x86_64
os: macOS-latest
target: x86_64-apple-darwin
bin: skynet
name: skynet-darwin-x86_64.tar.gz
- os_name: macOS-aarch64
os: macOS-latest
target: aarch64-apple-darwin
bin: skynet
name: skynet-darwin-aarch64.tar.gz
steps:
- uses: actions/checkout@v4
- name: Cache cargo & target directories
uses: Swatinem/rust-cache@v2
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0
with:
command: "both"
target: ${{ matrix.platform.target }}
args: "--locked --release"
strip: false
- uses: actions/download-artifact@v4
with:
name: frontend
path: release/skynet/assets
- name: Package as archive
shell: bash
run: |
cd release
mkdir skynet/plugin
cp ../target/${{ matrix.platform.target }}/release/${{ matrix.platform.bin }} skynet
cp ../conf.yml skynet
cp ../conf.schema.json skynet
cp ../default.webp skynet
if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then
7z a ../${{ matrix.platform.name }} skynet
else
tar czvf ../${{ matrix.platform.name }} skynet
fi
cd -
- name: Publish release artifacts
uses: actions/upload-artifact@v4
with:
name: skynet-${{ matrix.platform.os_name }}
path: ${{ matrix.platform.name }}
- name: Generate SHA-256
run: shasum -a 256 ${{ matrix.platform.name }} > ${{ matrix.platform.name }}.sha256
- name: Publish GitHub release
uses: softprops/action-gh-release@v2
with:
draft: true
files: ${{ matrix.platform.name }}*
77 changes: 43 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
SHELL = /bin/bash
.SHELLFLAGS = -
OUTPUTDIR = ./bin
RELEASEDIR = ./release
OUTPUT_DIR = $$(pwd)/bin
TARGET_DIR = $$(pwd)/target
PLUGIN_DIR = $$(pwd)/plugin
PLUGIN_SUFFIX =

ifeq ($(OS),Windows_NT)
Expand All @@ -17,7 +18,7 @@ else
endif

.ONESHELL:
.PHONY: check build run dev static clean help release
.PHONY: check build run dev static clean help

all: help

Expand All @@ -44,21 +45,23 @@ check:
build:
@echo Building...
@cargo build
@mkdir -p $(OUTPUTDIR)
@cp conf.yml $(OUTPUTDIR)
@cp conf.schema.json $(OUTPUTDIR)
@cp default.webp $(OUTPUTDIR)
@cp ./target/debug/skynet $(OUTPUTDIR)
@mkdir -p $(OUTPUTDIR)/plugin
@for d in `ls ./plugin`;do \
if [ -f ./plugin/$$d/config.yml ];then \
mkdir -p $(OUTPUTDIR)/plugin/$$d; \
cp ./target/debug/lib$$d$(PLUGIN_SUFFIX) $(OUTPUTDIR)/plugin/$$d; \
cp ./plugin/$$d/config.yml $(OUTPUTDIR)/plugin/$$d; \
if [ -f ./plugin/$$d/Makefile ];then \
@mkdir -p $(OUTPUT_DIR)
@cp conf.dev.yml $(OUTPUT_DIR)/conf.yml
@cp conf.schema.json $(OUTPUT_DIR)
@cp default.webp $(OUTPUT_DIR)
@cp $(TARGET_DIR)/debug/skynet $(OUTPUT_DIR)
@mkdir -p $(OUTPUT_DIR)/plugin
@for d in `ls $(PLUGIN_DIR)`;do \
if [ -f $(PLUGIN_DIR)/$$d/config.yml ];then \
mkdir -p $(OUTPUT_DIR)/plugin/$$d; \
cp $(TARGET_DIR)/debug/lib$$d$(PLUGIN_SUFFIX) $(OUTPUT_DIR)/plugin/$$d; \
cp $(PLUGIN_DIR)/$$d/config.yml $(OUTPUT_DIR)/plugin/$$d; \
if [ -f $(PLUGIN_DIR)/$$d/Makefile ];then \
t=$(TARGET_DIR); \
o=$(OUTPUT_DIR)/plugin/$$d; \
pushd . > /dev/null; \
cd ./plugin/$$d; \
make --no-print-directory build; \
cd $(PLUGIN_DIR)/$$d; \
make --no-print-directory build TARGET_DIR=$$t OUTPUT_DIR=$$o; \
popd > /dev/null; \
fi \
fi \
Expand All @@ -67,7 +70,7 @@ build:

## run: Run skynet (dev).
run: build
@cd $(OUTPUTDIR) && ./skynet run -v --persist-session --disable-csrf
@cd $(OUTPUT_DIR) && ./skynet run -v --persist-session --disable-csrf

## dev: Run dev server, auto reload on save.
dev:
Expand All @@ -76,24 +79,25 @@ dev:
## static: make static files.
static:
@cd ./skynet/frontend && yarn && yarn build
@mkdir -p $(OUTPUTDIR)
@rm -rf $(OUTPUTDIR)/assets
@cp -r ./skynet/frontend/dist/. $(OUTPUTDIR)/assets && mkdir $(OUTPUTDIR)/assets/_plugin
@for d in `ls ./plugin`;do \
if [ -d ./plugin/$$d/frontend ];then \
id=`cat ./plugin/$$d/config.yml | head -n 1 | cut -d \" -f 2`; \
mkdir -p $(OUTPUTDIR)/assets/_plugin/$$id; \
@mkdir -p $(OUTPUT_DIR)
@rm -rf $(OUTPUT_DIR)/assets
@cp -r ./skynet/frontend/dist/. $(OUTPUT_DIR)/assets && mkdir $(OUTPUT_DIR)/assets/_plugin
@for d in `ls $(PLUGIN_DIR)`;do \
if [ -d $(PLUGIN_DIR)/$$d/frontend ];then \
id=`cat $(PLUGIN_DIR)/$$d/config.yml | head -n 1 | cut -d \" -f 2`; \
mkdir -p $(OUTPUT_DIR)/assets/_plugin/$$id; \
pushd . > /dev/null; \
cd ./plugin/$$d/frontend; \
cd $(PLUGIN_DIR)/$$d/frontend; \
yarn build; \
popd > /dev/null; \
cp -r ./plugin/$$d/frontend/dist/. $(OUTPUTDIR)/assets/_plugin/$$id; \
cp -r $(PLUGIN_DIR)/$$d/frontend/dist/. $(OUTPUT_DIR)/assets/_plugin/$$id; \
fi \
done

## clean: clean all build files.
clean:
@rm -rf $(OUTPUTDIR)
@rm -rf $(OUTPUT_DIR)
@rm -rf $(RELEASE_DIR)
@cargo clean

## help: Show this help.
Expand All @@ -102,9 +106,14 @@ help: Makefile
@sed -n 's/^##//p' $< | column -t -s ':' | sed -e 's/^/ /'

## release: Build skynet (release).
release: static
@rm -rf $(RELEASEDIR)
@mkdir -p $(RELEASEDIR)/windows-x86_64
@cross build --target x86_64-pc-windows-gnu --release
@mkdir -p $(RELEASEDIR)/linux-x86_64
@cross build --target x86_64-unknown-linux-gnu --release
release:
@rm -rf $(RELEASE_DIR)
@echo Building...
@RUSTFLAGS=$(RUSTFLAGS) cargo build --release
@cd ./skynet/frontend && yarn && yarn build
@mkdir -p $(RELEASE_DIR)/plugin && \
cp -r ./skynet/frontend/dist/. $(RELEASE_DIR)/assets && mkdir -p $(RELEASE_DIR)/assets/_plugin && \
cp conf.yml $(RELEASE_DIR) && \
cp conf.schema.json $(RELEASE_DIR) && \
cp default.webp $(RELEASE_DIR) && \
cp $(TARGET_DIR)/release/skynet$(EXE_SUFFIX) $(RELEASE_DIR)
2 changes: 1 addition & 1 deletion actix-session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<Store: SessionStore> SessionMiddlewareBuilder<Store> {
/// Default is [`SessionLifecycle::BrowserSession`].
///
/// # Examples
/// ```
/// ```ignore
/// use actix_web::cookie::{Key, time::Duration};
/// use actix_session::{SessionMiddleware, config::PersistentSession};
/// use actix_session::storage::CookieSessionStore;
Expand Down
2 changes: 1 addition & 1 deletion actix-session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Further reading on sessions:
To start using sessions in your Actix Web application you must register [`SessionMiddleware`]
as a middleware on your `App`:
```no_run
```ignore
use actix_web::{web, App, HttpServer, HttpResponse, Error};
use actix_session::{Session, SessionMiddleware, storage::RedisSessionStore};
use actix_web::cookie::Key;
Expand Down
4 changes: 2 additions & 2 deletions actix-session/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use crate::{
/// reasonably secure implementation of sessions.
///
/// # Examples
/// ```no_run
/// ```ignore
/// use actix_web::{web, App, HttpServer, HttpResponse, Error};
/// use actix_session::{Session, SessionMiddleware, storage::RedisSessionStore};
/// use actix_web::cookie::Key;
Expand Down Expand Up @@ -78,7 +78,7 @@ use crate::{
///
/// If you want to customise use [`builder`](Self::builder) instead of [`new`](Self::new):
///
/// ```no_run
/// ```ignore
/// use actix_web::{App, cookie::{Key, time}, Error, HttpResponse, HttpServer, web};
/// use actix_session::{Session, SessionMiddleware, storage::RedisSessionStore};
/// use actix_session::config::PersistentSession;
Expand Down
4 changes: 2 additions & 2 deletions actix-session/src/storage/redis_rs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::storage::{

/// Use Redis as session storage backend.
///
/// ```no_run
/// ```ignore
/// use actix_web::{web, App, HttpServer, HttpResponse, Error};
/// use actix_session::{SessionMiddleware, storage::RedisSessionStore};
/// use actix_web::cookie::Key;
Expand Down Expand Up @@ -47,7 +47,7 @@ use crate::storage::{
/// Add the `redis-rs-tls-session` feature flag to enable TLS support. You can then establish a TLS
/// connection to Redis using the `rediss://` URL scheme:
///
/// ```no_run
/// ```ignore
/// use actix_session::{storage::RedisSessionStore};
///
/// # actix_web::rt::System::new().block_on(async {
Expand Down
42 changes: 42 additions & 0 deletions conf.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# yaml-language-server: $schema=conf.schema.json
database:
dsn: "sqlite://../data.db?mode=rwc" # database dsn, support sqlite, mysql, postgresql

redis:
dsn: "redis://127.0.0.1:6379/0" # redis dsn

session:
key: "Ckm7cYj0XDaIkGQeXYun7fuduCT8V5dMwYzMAz2mb5nlj3FTAgLYp5MstHh18PW8" # session sign key, at least 64 in length
prefix: "session_" # prefix in redis, please prevent glob pattern keywords like ? and *
cookie: "SESSIONID" # session cookie name
expire: 3600 # default expire time seconds
remember: 5184000 # remember expire time seconds

listen:
address: "localhost:8080" # listen address
worker: 0 # web workers, 0 for cores
ssl: false # enable ssl
ssl_cert: "" # ssl certificate path(.crt)
ssl_key: "" # ssl key path(.key)

header:
csp: "default-src 'none'; script-src 'self' 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; base-uri 'self'" # Content Security Policy, https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP

proxy:
enable: false # if skynet is behind proxy, enable to get correct ip
header: "X-Forwarded-For" # ip header set by proxy server
trusted: "" # trusted proxy address, client ip will be the first untrusted one in header, seperated by ,

recaptcha:
enable: false # if enable recaptcha
url: "https://www.recaptcha.net" # verify url
sitekey: "" # recaptcha sitekey
secret: "" # recaptcha secret
timeout: 10 # connect timeout seconds

csrf:
prefix: "csrf_" # redis prefix
timeout: 10 # timeout second

avatar: "default.webp" # default avatar
lang: "en-US" # default language
4 changes: 2 additions & 2 deletions conf.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# yaml-language-server: $schema=conf.schema.json
database:
dsn: "sqlite://../data.db?mode=rwc" # database dsn, support sqlite, mysql, postgresql
dsn: "sqlite://data.db?mode=rwc" # database dsn, support sqlite, mysql, postgresql

redis:
dsn: "redis://127.0.0.1:6379/0" # redis dsn
dsn: "redis://redis:6379/0" # redis dsn

session:
key: "Ckm7cYj0XDaIkGQeXYun7fuduCT8V5dMwYzMAz2mb5nlj3FTAgLYp5MstHh18PW8" # session sign key, at least 64 in length
Expand Down
5 changes: 2 additions & 3 deletions plugin/agent/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
SHELL = /bin/bash
.SHELLFLAGS = -
OUTPUTDIR = ../../bin/plugin/agent
PLATFORM =
MACHINE =
SUFFIX =
Expand Down Expand Up @@ -38,5 +37,5 @@ else
endif

build:
@mkdir -p $(OUTPUTDIR)/bin
@cp ../../target/debug/agent $(OUTPUTDIR)/bin/agent_$(PLATFORM)_$(MACHINE)$(SUFFIX);
@mkdir -p $(OUTPUT_DIR)/bin
@cp $(TARGET_DIR)/debug/agent $(OUTPUT_DIR)/bin/agent_$(PLATFORM)_$(MACHINE)$(SUFFIX);
2 changes: 1 addition & 1 deletion plugin/agent/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async fn connect<'a>(
"{addr}/api/plugins/{}/agents/ws",
monitor_service::ID
))
.unwrap();
.expect("URL parse failed");
info!("Connecting to {url}");
let (ws, _) = connect_async_with_config(
url,
Expand Down
14 changes: 9 additions & 5 deletions skynet/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ pub async fn init_skynet(
skynet.add_locale(i18n!("locales"));

// init db
let db = db::connect(skynet.config.database_dsn.get()).await.unwrap();
skynet.default_id = db::init(&db, &skynet).await.unwrap();
let db = db::connect(skynet.config.database_dsn.get())
.await
.expect("DB connect failed");
skynet.default_id = db::init(&db, &skynet).await.expect("DB init failed");
debug!("DB connected");

// init redis
let redis = ConnectionManager::new(redis::Client::open(skynet.config.redis_dsn.get()).unwrap())
.await
.unwrap();
let redis = ConnectionManager::new(
redis::Client::open(skynet.config.redis_dsn.get()).expect("Redis open failed"),
)
.await
.expect("Redis connect failed");
debug!("Redis connected");

// init notification
Expand Down
2 changes: 1 addition & 1 deletion skynet/src/cmd/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async fn create(
) {
let mut avatar_file: Option<Vec<u8>> = None;
if let Some(x) = avatar {
avatar_file = Some(fs::read(x).unwrap());
avatar_file = Some(fs::read(x).expect("Read avatar failed"));
debug!("Read avatar success: {:?}", x);
}
let tx = db.begin().await.unwrap();
Expand Down
Loading

0 comments on commit 6c8544e

Please sign in to comment.