Skip to content

Commit

Permalink
ci: reuse artifacts from previous pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Dec 16, 2024
1 parent 40eb731 commit db3e74b
Show file tree
Hide file tree
Showing 16 changed files with 203 additions and 191 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,11 @@ jobs:
playwright-install: true
hard-link-nm: false

- name: Download web artifact
uses: ./.github/actions/download-web
with:
path: packages/frontend/apps/electron/renderer/dist

- name: Download server-native.node
uses: actions/download-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"build:electron": "yarn nx build @affine/electron",
"build:server-native": "yarn nx run-many -t build -p @affine/server-native",
"start:web-static": "yarn workspace @affine/web static-server",
"serve:test-static": "yarn exec serve tests/fixtures --cors -p 8081",
"start:desktop-static": "yarn workspace @affine/electron static-server",
"lint:eslint": "cross-env NODE_OPTIONS=\"--max-old-space-size=8192\" eslint --report-unused-disable-directives-severity=off . --cache",
"lint:eslint:fix": "yarn lint:eslint --fix",
"lint:prettier": "prettier --ignore-unknown --cache --check .",
Expand Down
20 changes: 11 additions & 9 deletions packages/frontend/apps/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
"homepage": "https://github.com/toeverything/AFFiNE",
"scripts": {
"start": "electron .",
"dev": "DEV_SERVER_URL=http://localhost:8080 node --loader ts-node/esm/transpile-only ./scripts/dev.ts",
"dev:prod": "yarn node --loader ts-node/esm/transpile-only scripts/dev.ts",
"build": "NODE_ENV=production node --loader ts-node/esm/transpile-only scripts/build-layers.ts",
"build:dev": "NODE_ENV=development node --loader ts-node/esm/transpile-only scripts/build-layers.ts",
"generate-assets": "node --loader ts-node/esm/transpile-only scripts/generate-assets.ts",
"package": "cross-env NODE_OPTIONS=\"--loader ts-node/esm/transpile-only\" electron-forge package",
"make": "cross-env NODE_OPTIONS=\"--loader ts-node/esm/transpile-only\" electron-forge make",
"make-squirrel": "node --loader ts-node/esm/transpile-only scripts/make-squirrel.ts",
"make-nsis": "node --loader ts-node/esm/transpile-only scripts/make-nsis.ts"
"dev": "DEV_SERVER_URL=http://localhost:8080 node --import @oxc-node/core/register ./scripts/dev.ts",
"dev:prod": "yarn node --import @oxc-node/core/register scripts/dev.ts",
"build": "NODE_ENV=production node --import @oxc-node/core/register scripts/build-layers.ts",
"build:dev": "NODE_ENV=development node --import @oxc-node/core/register scripts/build-layers.ts",
"generate-assets": "node --import @oxc-node/core/register scripts/generate-assets.ts",
"package": "cross-env NODE_OPTIONS=\"--import @oxc-node/core/register\" electron-forge package",
"make": "cross-env NODE_OPTIONS=\"--import @oxc-node/core/register\" electron-forge make",
"make-squirrel": "node --import @oxc-node/core/register scripts/make-squirrel.ts",
"make-nsis": "node --import @oxc-node/core/register scripts/make-nsis.ts",
"static-server": "cross-env DISTRIBUTION=desktop yarn workspace @affine/cli dev --static"
},
"main": "./dist/main.js",
"devDependencies": {
Expand All @@ -42,6 +43,7 @@
"@electron-forge/plugin-auto-unpack-natives": "^7.6.0",
"@electron-forge/shared-types": "^7.6.0",
"@emotion/react": "^11.14.0",
"@oxc-node/core": "^0.0.16",
"@pengx17/electron-forge-maker-appimage": "^1.2.1",
"@sentry/electron": "^5.8.0",
"@sentry/esbuild-plugin": "^2.22.7",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"scripts": {
"build": "cross-env DISTRIBUTION=web yarn workspace @affine/cli bundle",
"dev": "yarn workspace @affine/cli dev",
"static-server": "yarn workspace @affine/cli dev --static"
"static-server": "cross-env DISTRIBUTION=web yarn workspace @affine/cli dev --static"
},
"dependencies": {
"@affine/component": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion tests/affine-cloud-copilot/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ const config: PlaywrightTestConfig = {
},
// Intentionally not building the web, reminds you to run it by yourself.
{
command: 'yarn -T run start:web-static',
command: 'DISTRIBUTION=web BUILD_TYPE=canary yarn dev',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
...process.env,
},
},
{
Expand Down
3 changes: 2 additions & 1 deletion tests/affine-cloud/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ const config: PlaywrightTestConfig = {
},
// Intentionally not building the web, reminds you to run it by yourself.
{
command: 'yarn -T run start:web-static',
command: 'DISTRIBUTION=web BUILD_TYPE=canary yarn dev',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
...process.env,
},
},
{
Expand Down
3 changes: 1 addition & 2 deletions tests/affine-desktop-cloud/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { testResultDir } from '@affine-test/kit/playwright';
import type { PlaywrightTestConfig } from '@playwright/test';
// import { devices } from '@playwright/test';

/**
* Read environment variables from file.
Expand All @@ -23,7 +22,7 @@ const config: PlaywrightTestConfig = {
webServer: [
// Intentionally not building the web, reminds you to run it by yourself.
{
command: 'yarn -T run start:web-static',
command: 'yarn -T run start:desktop-static',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
Expand Down
4 changes: 2 additions & 2 deletions tests/affine-desktop/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import assert from 'node:assert';

import { testResultDir } from '@affine-test/kit/playwright';
import type { PlaywrightTestConfig } from '@playwright/test';
// import { devices } from '@playwright/test';

/**
* Read environment variables from file.
Expand Down Expand Up @@ -41,12 +40,13 @@ if (process.env.DEV_SERVER_URL) {
);
config.webServer = [
{
command: 'yarn run start:web-static',
command: 'DISTRIBUTION=desktop BUILD_TYPE=canary yarn dev',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
...process.env,
},
},
];
Expand Down
14 changes: 2 additions & 12 deletions tests/affine-local/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
PlaywrightTestConfig,
PlaywrightWorkerOptions,
} from '@playwright/test';
// import { devices } from '@playwright/test';

/**
* Read environment variables from file.
Expand Down Expand Up @@ -44,24 +43,15 @@ const config: PlaywrightTestConfig = {
reporter: process.env.CI ? 'github' : 'list',

webServer: [
{
command: 'yarn run serve:test-static',
port: 8081,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
ENABLE_DEBUG_PAGE: '1',
},
},
// Intentionally not building the web, reminds you to run it by yourself.
{
command: 'yarn run start:web-static',
command: 'DISTRIBUTION=web BUILD_TYPE=canary yarn dev',
port: 8080,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
env: {
COVERAGE: process.env.COVERAGE || 'false',
...process.env,
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions tools/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@clack/prompts": "^0.8.2",
"@magic-works/i18n-codegen": "^0.6.1",
"@napi-rs/simple-git": "^0.1.19",
"@oxc-node/core": "^0.0.16",
"@perfsee/webpack": "^1.13.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@sentry/webpack-plugin": "^2.22.7",
Expand All @@ -33,16 +34,15 @@
"style-loader": "^4.0.0",
"swc-loader": "^0.2.6",
"tailwindcss": "^3.4.16",
"terser-webpack-plugin": "^5.3.10",
"ts-node": "^10.9.2",
"terser-webpack-plugin": "^5.3.11",
"vite": "^6.0.3",
"webpack": "^5.97.1",
"webpack-dev-server": "^5.2.0",
"webpack-merge": "^6.0.1"
},
"scripts": {
"bundle": "node --loader ts-node/esm/transpile-only.mjs ./src/bin/build.ts",
"dev": "node --loader ts-node/esm/transpile-only.mjs ./src/bin/dev.ts"
"bundle": "node --import @oxc-node/core/register ./src/bin/build.ts",
"dev": "node --import @oxc-node/core/register ./src/bin/dev.ts"
},
"version": "0.18.0"
}
142 changes: 74 additions & 68 deletions tools/cli/src/bin/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { getCwdFromDistribution, projectRoot } from '../config/cwd.cjs';
import type { BuildFlags } from '../config/index.js';
import { createWebpackConfig } from '../webpack/webpack.config.js';

const flags: BuildFlags = {
distribution:
(process.env.DISTRIBUTION as BuildFlags['distribution']) ?? 'web',
const flags: BuildFlags & { ci: boolean } = {
distribution: process.env.DISTRIBUTION as BuildFlags['distribution'],
mode: 'development',
static: false,
channel: 'canary',
coverage: process.env.COVERAGE === 'true',
ci: !!process.env.CI || !!process.env.IN_CI_TEST,
};

const files = ['.env', '.env.local'];
Expand All @@ -34,72 +34,75 @@ for (const file of files) {

const buildFlags = process.argv.includes('--static')
? { ...flags, static: true }
: ((await p.group(
{
distribution: () =>
p.select({
message: 'Distribution',
options: [
{
value: 'web',
},
{
value: 'desktop',
},
{
value: 'admin',
},
{
value: 'mobile',
},
{
value: 'ios',
},
],
initialValue: 'web',
}),
mode: () =>
p.select({
message: 'Mode',
options: [
{
value: 'development',
},
{
value: 'production',
},
],
initialValue: 'development',
}),
channel: () =>
p.select({
message: 'Channel',
options: [
{
value: 'canary',
},
{
value: 'beta',
},
{
value: 'stable',
},
],
initialValue: 'canary',
}),
coverage: () =>
p.confirm({
message: 'Enable coverage',
initialValue: process.env.COVERAGE === 'true',
}),
},
{
onCancel: () => {
p.cancel('Operation cancelled.');
process.exit(0);
: // skip interactive mode in CI
flags.ci
? flags
: ((await p.group(
{
distribution: () =>
p.select({
message: 'Distribution',
options: [
{
value: 'web',
},
{
value: 'desktop',
},
{
value: 'admin',
},
{
value: 'mobile',
},
{
value: 'ios',
},
],
initialValue: 'web',
}),
mode: () =>
p.select({
message: 'Mode',
options: [
{
value: 'development',
},
{
value: 'production',
},
],
initialValue: 'development',
}),
channel: () =>
p.select({
message: 'Channel',
options: [
{
value: 'canary',
},
{
value: 'beta',
},
{
value: 'stable',
},
],
initialValue: 'canary',
}),
coverage: () =>
p.confirm({
message: 'Enable coverage',
initialValue: process.env.COVERAGE === 'true',
}),
},
}
)) as BuildFlags);
{
onCancel: () => {
p.cancel('Operation cancelled.');
process.exit(0);
},
}
)) as BuildFlags & { ci: boolean });

flags.distribution = buildFlags.distribution;
flags.mode = buildFlags.mode;
Expand Down Expand Up @@ -134,6 +137,9 @@ try {
const config = createWebpackConfig(cwd, flags);
if (flags.static) {
config.watch = false;
config.entry = {
_undefined_entry: join(import.meta.dirname, 'empty.ts'),
};
}
const compiler = webpack(config);
// Start webpack
Expand Down
5 changes: 5 additions & 0 deletions tools/cli/src/bin/empty.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file is aim to reuse webpack devServer in the serve:static mode
// In serve:static mode, the sources are built in previous pipeline
// So we need to provide a empty entry to webpack to make devServer work

const _a = void 0;
4 changes: 2 additions & 2 deletions tools/cli/src/webpack/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const OptimizeOptionOptions: (
new TerserPlugin({
minify: TerserPlugin.swcMinify,
exclude: [/plugins\/.+\/.+\.js$/, /plugins\/.+\/.+\.mjs$/],
parallel: true,
parallel: false,
extractComments: true,
terserOptions: {
ecma: 2020,
Expand Down Expand Up @@ -374,7 +374,7 @@ export const createConfiguration: (
watch: !buildFlags.static,
},
{
directory: join(cwd, 'public'),
directory: join(cwd, 'dist'),
publicPath: '/',
watch: !buildFlags.static,
},
Expand Down
4 changes: 3 additions & 1 deletion tools/cli/src/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export function createWebpackConfig(cwd: string, flags: BuildFlags) {

return merge(config, {
entry,
plugins: Object.keys(entry).map(createHTMLPlugins).flat(),
plugins: flags.static
? []
: Object.keys(entry).map(createHTMLPlugins).flat(),
});
}
Loading

0 comments on commit db3e74b

Please sign in to comment.