Skip to content

Commit

Permalink
fix: add web and tauri ci
Browse files Browse the repository at this point in the history
  • Loading branch information
root authored and root committed Apr 2, 2024
1 parent c1961da commit f5d9bac
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 32 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/tauri2_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Tauri2-CI
on:
pull_request:
paths:
- ".github/workflows/tauri2_ci.yaml"
- "frontend/rust-lib/**"
- "frontend/appflowy_web_app/**"
- "frontend/resources/**"

env:
NODE_VERSION: "18.16.0"
PNPM_VERSION: "8.5.0"
RUST_TOOLCHAIN: "1.75"

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
tauri-build:
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
platform: [ubuntu-20.04]

runs-on: ${{ matrix.platform }}

env:
CI: true
steps:
- uses: actions/checkout@v4

- name: Maximize build space (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo docker image prune --all --force
sudo rm -rf /opt/hostedtoolcache/codeQL
sudo rm -rf ${GITHUB_WORKSPACE}/.git
sudo rm -rf $ANDROID_HOME/ndk
- name: setup node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- name: setup pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}

- name: Install Rust toolchain
id: rust_toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.RUST_TOOLCHAIN }}
override: true
profile: minimal

- name: Rust cache
uses: swatinem/rust-cache@v2
with:
workspaces: "./frontend/appflowy_web_app/src-tauri -> target"

- name: Node_modules cache
uses: actions/cache@v2
with:
path: frontend/appflowy_web_app/node_modules
key: node-modules-${{ runner.os }}

- name: install dependencies (windows only)
if: matrix.platform == 'windows-latest'
working-directory: frontend
run: |
cargo install --force duckscript_cli
vcpkg integrate install
- name: install dependencies (ubuntu only)
if: matrix.platform == 'ubuntu-20.04'
working-directory: frontend
run: |
sudo apt-get update
sudo apt-get install -y libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf
- name: install cargo-make
working-directory: frontend
run: |
cargo install --force cargo-make
cargo make appflowy-tauri-deps-tools
- name: install frontend dependencies
working-directory: frontend/appflowy_web_app
run: |
mkdir dist
pnpm install
cd src-tauri && cargo build
- name: test and lint
working-directory: frontend/appflowy_web_app
run: |
pnpm run lint:tauri
- uses: tauri-apps/tauri-action@v0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tauriScript: pnpm tauri
projectPath: frontend/appflowy_web_app
args: "--debug"
61 changes: 61 additions & 0 deletions .github/workflows/web2_ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Web2-CI
on:
pull_request:
paths:
- ".github/workflows/web2_ci.yaml"
- "frontend/appflowy_web_app/**"
- "frontend/resources/**"
env:
NODE_VERSION: "18.16.0"
PNPM_VERSION: "8.5.0"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
tauri-build:
if: github.event.pull_request.draft != true
strategy:
fail-fast: false
matrix:
platform: [ubuntu-latest]

runs-on: ${{ matrix.platform }}

steps:
- uses: actions/checkout@v4
- name: Maximize build space (ubuntu only)
if: matrix.platform == 'ubuntu-latest'
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
sudo docker image prune --all --force
sudo rm -rf /opt/hostedtoolcache/codeQL
sudo rm -rf ${GITHUB_WORKSPACE}/.git
sudo rm -rf $ANDROID_HOME/ndk
- name: setup node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: setup pnpm
uses: pnpm/action-setup@v2
with:
version: ${{ env.PNPM_VERSION }}
- name: Node_modules cache
uses: actions/cache@v2
with:
path: frontend/appflowy_web_app/node_modules
key: node-modules-${{ runner.os }}
- name: install frontend dependencies
working-directory: frontend/appflowy_web_app
run: |
pnpm install
- name: test and lint
working-directory: frontend/appflowy_web_app
run: |
pnpm run lint
- name: build
working-directory: frontend/appflowy_web_app
run: |
pnpm run build
3 changes: 2 additions & 1 deletion frontend/appflowy_web_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ Before you begin, ensure you have the following installed:
# make sure you are in the root directory of the project
cd frontend/appflowy_web_app
mkdir dist
cargo make --cwd .. tauri_build
cd src-tauri
cargo build
```

### 🚀 Running the Application
Expand Down
8 changes: 4 additions & 4 deletions frontend/appflowy_web_app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
"scripts": {
"dev": "pnpm run sync:i18n && vite",
"dev:tauri": "TAURI_MODE=true pnpm run sync:i18n && tauri dev",
"build": "pnpm run sync:i18n && pnpm run lint:web && vite build",
"build:tauri": "TAURI_MODE=true pnpm run sync:i18n && pnpm run lint && vite build",
"lint:tauri": "TAURI_MODE=true tsc --noEmit && eslint --ext .js,.ts,.tsx . --ignore-path .eslintigore",
"lint": "tsc --noEmit && eslint --ext .js,.ts,.tsx . --ignore-path .eslintigore.web",
"build": "pnpm run lint:web && vite build",
"build:tauri": "TAURI_MODE=true pnpm run lint && vite build",
"lint:tauri": "TAURI_MODE=true pnpm run sync:i18n && tsc --noEmit && eslint --ext .js,.ts,.tsx . --ignore-path .eslintigore",
"lint": "pnpm run sync:i18n && tsc --noEmit --project tsconfig.web.json && eslint --ext .js,.ts,.tsx . --ignore-path .eslintigore.web",
"preview": "vite preview",
"tauri:dev": "tauri dev",
"css:variables": "node style-dictionary/config.cjs",
Expand Down
24 changes: 6 additions & 18 deletions frontend/appflowy_web_app/src/AppConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { createContext, useEffect, useMemo, useState } from 'react';
import { AFServiceConfig, AFService } from '@/application/services/services.type';
import { AFService } from '@/application/services/services.type';
import { getService } from '@/application/services';
import { useAppSelector } from '@/stores/store';

export const AFConfigContext = createContext<
| {
Expand All @@ -9,30 +10,17 @@ export const AFConfigContext = createContext<
| undefined
>(undefined);

const defaultConfig: AFServiceConfig = {
cloudConfig: {
baseURL: import.meta.env.DEV
? import.meta.env.AF_BASE_URL || 'https://test.appflowy.cloud'
: 'https://beta.appflowy.cloud',
gotrueURL: import.meta.env.DEV
? import.meta.env.AF_GOTRUE_URL || 'https://test.appflowy.cloud/gotrue'
: 'https://beta.appflowy.cloud/gotrue',
wsURL: import.meta.env.DEV
? import.meta.env.AF_WS_URL || 'wss://test.appflowy.cloud/ws/v1'
: 'wss://beta.appflowy.cloud/ws/v1',
},
};

function AppConfig({ children }: { children: React.ReactNode }) {
const [serviceConfig, setServiceConfig] = useState<AFServiceConfig | undefined>(defaultConfig);
const appConfig = useAppSelector((state) => state.app.appConfig);
const [service, setService] = useState<AFService>();

useEffect(() => {
void (async () => {
if (!serviceConfig) return;
setService(await getService(serviceConfig));
if (!appConfig) return;
setService(await getService(appConfig));
})();
}, [serviceConfig]);
}, [appConfig]);

const config = useMemo(
() => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class JSDocumentService implements DocumentService {
const docId = '26d5c8c1-1c66-459c-bc6c-f4da1a663348';
const data = await this.httpClient.getObject(workspaceId, docId, CollabType.Document);

console.log(data);
console.log(docID, data);

return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UserProfilePB, WorkspacePB } from '@/application/services/js-services/http/http.type';
import { Authenticator, UserProfile, Workspace } from '@/application/services/user.type';
import axios, { AxiosInstance } from 'axios';
import axios, { AxiosInstance, InternalAxiosRequestConfig, AxiosResponse, AxiosRequestConfig } from 'axios';
import {
ACCESS_TOKEN_NAME,
AUTHORIZATION_NAME,
Expand Down Expand Up @@ -43,7 +43,7 @@ export function getAxiosInstances(baseURL: string, gotrueURL: string) {
},
});

const requestInterceptor = async (config: any) => {
const requestInterceptor = async (config: InternalAxiosRequestConfig) => {
const accessToken = sessionStorage.getItem(ACCESS_TOKEN_NAME);
const tokenType = sessionStorage.getItem(TOKEN_TYPE_NAME) || 'Bearer';

Expand All @@ -54,15 +54,21 @@ export function getAxiosInstances(baseURL: string, gotrueURL: string) {
return config;
};

const errorInterceptor = async (error: any) => {
if (error.response?.status === 401 && !error.config.url.includes(gotrueHttpUrls[URL_NAME.LOGOUT])) {
const errorInterceptor = async (error: {
response?: AxiosResponse;
config: AxiosRequestConfig;
}) => {
if (error.response?.status === 401 && !error.config.url?.includes(gotrueHttpUrls[URL_NAME.LOGOUT])) {
try {
const tokenType = sessionStorage.getItem(TOKEN_TYPE_NAME) || 'Bearer';
const accessToken = await refreshToken(gotrueInstance);

error.config.headers[AUTHORIZATION_NAME] = `${tokenType} ${accessToken}`;
const config = {
...error.config,
[AUTHORIZATION_NAME]: `${tokenType} ${accessToken}`,
}

return gotrueInstance.request(error.config);
return gotrueInstance.request(config);
} catch (e) {
// do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class CloudService {
try {
const res = await this.client?.sign_in_password(email, password);

// console.log(res);
console.log(res);
} catch (error) {
// console.error(error);
console.error(error);
}
}
}
36 changes: 36 additions & 0 deletions frontend/appflowy_web_app/src/stores/app/slice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { AFServiceConfig } from '@/application/services/services.type';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

const defaultConfig: AFServiceConfig = {
cloudConfig: {
baseURL: import.meta.env.DEV
? import.meta.env.AF_BASE_URL || 'https://test.appflowy.cloud'
: 'https://beta.appflowy.cloud',
gotrueURL: import.meta.env.DEV
? import.meta.env.AF_GOTRUE_URL || 'https://test.appflowy.cloud/gotrue'
: 'https://beta.appflowy.cloud/gotrue',
wsURL: import.meta.env.DEV
? import.meta.env.AF_WS_URL || 'wss://test.appflowy.cloud/ws/v1'
: 'wss://beta.appflowy.cloud/ws/v1',
},
};

export interface AppState {
appConfig: AFServiceConfig;
}

const initialState: AppState = {
appConfig: defaultConfig,
};

export const slice = createSlice({
name: 'app',
initialState,
reducers: {
setAppConfig: (state, action: PayloadAction<AFServiceConfig>) => {
state.appConfig = action.payload;
},
},
});

export const { setAppConfig } = slice.actions;
2 changes: 2 additions & 0 deletions frontend/appflowy_web_app/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
} from '@reduxjs/toolkit';
import { errorSlice } from '@/stores/error/slice';
import { currentUserSlice } from '@/stores/currentUser/slice';
import { slice as appSlice } from '@/stores/app/slice';

const listenerMiddlewareInstance = createListenerMiddleware({
onError: () => console.error,
});

const store = configureStore({
reducer: {
[appSlice.name]: appSlice.reducer,
[errorSlice.name]: errorSlice.reducer,
[currentUserSlice.name]: currentUserSlice.reducer,
},
Expand Down
12 changes: 12 additions & 0 deletions frontend/appflowy_web_app/tsconfig.web.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"exclude": [
"node_modules",
"src/application/services/tauri-services"
],
"references": [
{
"path": "./tsconfig.node.json"
}
]
}

0 comments on commit f5d9bac

Please sign in to comment.