diff --git a/.github/actions/build-rust/action.yml b/.github/actions/build-rust/action.yml index 22300abdf7..004fe52fbc 100644 --- a/.github/actions/build-rust/action.yml +++ b/.github/actions/build-rust/action.yml @@ -7,6 +7,10 @@ inputs: package: description: 'Package to build' required: true + no-build: + description: 'Whether to skip building' + required: false + default: 'false' runs: using: 'composite' @@ -14,20 +18,34 @@ runs: - name: Print rustup toolchain version shell: bash id: rustup-version + working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }} run: | export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')" echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION" echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT" - name: Setup Rust uses: dtolnay/rust-toolchain@stable + if: ${{ runner.os != 'Windows' }} with: toolchain: '${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}' targets: ${{ inputs.target }} env: CARGO_INCREMENTAL: '1' + - name: Setup Rust + uses: dtolnay/rust-toolchain@stable + if: ${{ runner.os == 'Windows' }} + with: + toolchain: '${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}' + targets: ${{ inputs.target }} + env: + CARGO_INCREMENTAL: '1' + CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo + RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup + - name: Set CC - if: ${{ contains(inputs.target, 'linux') && inputs.package != '@affine/native' }} + if: ${{ contains(inputs.target, 'linux') && inputs.package != '@affine/native' && inputs.no-build != 'true' }} + working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }} shell: bash run: | echo "CC=clang" >> "$GITHUB_ENV" @@ -35,12 +53,37 @@ runs: - name: Cache cargo uses: Swatinem/rust-cache@v2 + if: ${{ runner.os == 'Windows' }} + with: + workspaces: ${{ inputs.workspace-path }} + save-if: ${{ github.ref_name == 'canary' }} + shared-key: ${{ inputs.target }}-${{ inputs.package }} + env: + CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo + RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup + + - name: Cache cargo + uses: Swatinem/rust-cache@v2 + if: ${{ runner.os != 'Windows' }} with: save-if: ${{ github.ref_name == 'canary' }} - shared-key: ${{ inputs.target }}-inputs.package + shared-key: ${{ inputs.target }}-${{ inputs.package }} + - name: Build shell: bash + if: ${{ runner.os != 'Windows' && inputs.no-build != 'true' }} run: | yarn workspace ${{ inputs.package }} build --target ${{ inputs.target }} --use-napi-cross env: DEBUG: 'napi:*' + + - name: Build + working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }} + shell: bash + if: ${{ runner.os == 'Windows' && inputs.no-build != 'true' }} + run: | + yarn workspace ${{ inputs.package }} build --target ${{ inputs.target }} --use-napi-cross + env: + DEBUG: 'napi:*' + CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo + RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup diff --git a/.github/actions/setup-node/action.yml b/.github/actions/setup-node/action.yml index 5ed9ccd261..1a1d422f2c 100644 --- a/.github/actions/setup-node/action.yml +++ b/.github/actions/setup-node/action.yml @@ -35,10 +35,19 @@ inputs: full-cache: description: 'Full installation cache' required: false - runs: using: 'composite' steps: + - name: Output workspace path + id: workspace-path + shell: bash + run: | + if [ -n "${{ env.DEV_DRIVE_WORKSPACE }}" ]; then + echo "workspace_path=${{ env.DEV_DRIVE_WORKSPACE }}" >> $GITHUB_OUTPUT + else + echo "workspace_path=${{ github.workspace }}" >> $GITHUB_OUTPUT + fi + - name: Setup Node.js uses: actions/setup-node@v4 with: @@ -52,26 +61,31 @@ runs: - name: Init CorePack if: ${{ inputs.corepack-install == 'true' }} shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: corepack enable - name: Set nmMode if: ${{ inputs.hard-link-nm == 'false' }} shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: yarn config set nmMode classic - name: Set nmHoistingLimits if: ${{ inputs.nmHoistingLimits }} shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: yarn config set nmHoistingLimits ${{ inputs.nmHoistingLimits }} - name: Set enableScripts if: ${{ inputs.enableScripts == 'false' }} shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: yarn config set enableScripts false - name: Set yarn global cache path shell: bash id: yarn-cache + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: node -e "const p = $(yarn config cacheFolder --json).effective; console.log('yarn_global_cache=' + p)" >> $GITHUB_OUTPUT - name: Cache non-full yarn cache on Linux @@ -79,7 +93,7 @@ runs: if: ${{ inputs.full-cache != 'true' && runner.os == 'Linux' }} with: path: | - node_modules + ${{ steps.workspace-path.outputs.workspace_path }}/node_modules ${{ steps.yarn-cache.outputs.yarn_global_cache }} key: node_modules-cache-${{ github.job }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.name }}-${{ steps.system-info.outputs.release }}-${{ steps.system-info.outputs.version }} @@ -115,17 +129,7 @@ runs: if: ${{ inputs.package-install == 'true' }} continue-on-error: true shell: bash - run: yarn ${{ inputs.extra-flags }} - env: - HUSKY: '0' - PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: '1' - ELECTRON_SKIP_BINARY_DOWNLOAD: '1' - SENTRYCLI_SKIP_DOWNLOAD: '1' - DEBUG: '*' - - - name: yarn install (try again) - if: ${{ steps.install.outcome == 'failure' }} - shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: yarn ${{ inputs.extra-flags }} env: HUSKY: '0' @@ -138,6 +142,7 @@ runs: id: playwright-version if: ${{ inputs.playwright-install == 'true' }} shell: bash + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} run: echo "version=$(yarn why --json @playwright/test | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://' | head -n 1)" >> $GITHUB_OUTPUT # Attempt to restore the correct Playwright browser binaries based on the @@ -150,7 +155,7 @@ runs: id: playwright-cache if: ${{ inputs.playwright-install == 'true' }} with: - path: ${{ github.workspace }}/node_modules/.cache/ms-playwright + path: ${{ steps.workspace-path.outputs.workspace_path }}/node_modules/.cache/ms-playwright key: '${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.name }}-${{ steps.system-info.outputs.release }}-${{ steps.system-info.outputs.version }}-playwright-${{ steps.playwright-version.outputs.version }}' # As a fallback, if the Playwright version has changed, try use the # most recently cached version. There's a good chance that at least one @@ -169,12 +174,14 @@ runs: shell: bash if: inputs.playwright-install == 'true' run: yarn playwright install --with-deps chromium webkit + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} env: - PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright + PLAYWRIGHT_BROWSERS_PATH: ${{ steps.workspace-path.outputs.workspace_path }}/node_modules/.cache/ms-playwright - name: Get installed Electron version id: electron-version if: ${{ inputs.electron-install == 'true' }} + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} shell: bash run: | echo "version=$(yarn why --json electron | grep -h 'workspace:.' | jq --raw-output '.children[].locator' | sed -e 's/@playwright\/test@.*://' | head -n 1)" >> $GITHUB_OUTPUT @@ -183,7 +190,7 @@ runs: id: electron-cache if: ${{ inputs.electron-install == 'true' }} with: - path: 'node_modules/.cache/electron' + path: ${{ steps.workspace-path.outputs.workspace_path }}/node_modules/.cache/electron key: '${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.name }}-${{ steps.system-info.outputs.release }}-${{ steps.system-info.outputs.version }}-electron-${{ steps.electron-version.outputs.version }}' restore-keys: | ${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.name }}-${{ steps.system-info.outputs.release }}-${{ steps.system-info.outputs.version }}-electron- @@ -192,5 +199,11 @@ runs: shell: bash if: inputs.electron-install == 'true' run: node ./node_modules/electron/install.js + working-directory: ${{ steps.workspace-path.outputs.workspace_path }} env: - electron_config_cache: ./node_modules/.cache/electron + electron_config_cache: ${{ steps.workspace-path.outputs.workspace_path }}/node_modules/.cache/electron + + - name: Write PLAYWRIGHT_BROWSERS_PATH env + shell: bash + run: | + echo "PLAYWRIGHT_BROWSERS_PATH=${{ steps.workspace-path.outputs.workspace_path }}/node_modules/.cache/ms-playwright" >> $GITHUB_ENV diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml deleted file mode 100644 index a555df3f3e..0000000000 --- a/.github/actions/setup-rust/action.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: 'Rust setup' -description: 'Rust setup, including cache configuration' -inputs: - components: - description: 'Cargo components' - required: false - targets: - description: 'Cargo target' - required: false - toolchain: - description: 'Rustup toolchain' - required: false - default: 'stable' - -runs: - using: 'composite' - steps: - - name: Setup Rust - uses: dtolnay/rust-toolchain@stable - with: - toolchain: ${{ inputs.toolchain }} - targets: ${{ inputs.targets }} - components: ${{ inputs.components }} - - name: Add Targets - if: ${{ inputs.targets }} - run: rustup target add ${{ inputs.targets }} - shell: bash - - uses: Swatinem/rust-cache@v2 diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 965c35364f..0dae039b82 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -19,7 +19,6 @@ env: AFFINE_ENV: dev COVERAGE: true MACOSX_DEPLOYMENT_TARGET: '10.13' - PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright DEPLOYMENT_TYPE: affine concurrency: @@ -280,11 +279,16 @@ jobs: spec: - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu } - { os: windows-latest, target: x86_64-pc-windows-msvc } - - { os: macos-14, target: x86_64-apple-darwin } - - { os: macos-14, target: aarch64-apple-darwin } + - { os: macos-latest, target: x86_64-apple-darwin } + - { os: macos-latest, target: aarch64-apple-darwin } steps: - uses: actions/checkout@v4 + - uses: samypr100/setup-dev-drive@v3 + if: ${{ matrix.spec.os == 'windows-latest' }} + with: + workspace-copy: true + drive-size: 8GB - name: Setup Node.js uses: ./.github/actions/setup-node with: @@ -292,6 +296,7 @@ jobs: electron-install: false - name: Setup filename id: filename + working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }} shell: bash run: | export PLATFORM_ARCH_ABI=$(node -e "console.log(require('@napi-rs/cli').parseTriple('${{ matrix.spec.target }}').platformArchABI)") @@ -305,7 +310,7 @@ jobs: uses: actions/upload-artifact@v4 with: name: ${{ steps.filename.outputs.filename }} - path: ./packages/frontend/native/${{ steps.filename.outputs.filename }} + path: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }}/packages/frontend/native/${{ steps.filename.outputs.filename }} if-no-files-found: error build-server-native: @@ -435,7 +440,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: ./.github/actions/build-rust + with: + package: 'affine' + no-build: 'true' - name: Install latest nextest release uses: taiki-e/install-action@nextest @@ -717,14 +725,14 @@ jobs: matrix: spec: - { - os: macos-14, + os: macos-latest, platform: macos, arch: x64, target: x86_64-apple-darwin, test: false, } - { - os: macos-14, + os: macos-latest, platform: macos, arch: arm64, target: aarch64-apple-darwin, diff --git a/.github/workflows/copilot-test.yml b/.github/workflows/copilot-test.yml index e330ca49f6..e91942173b 100644 --- a/.github/workflows/copilot-test.yml +++ b/.github/workflows/copilot-test.yml @@ -3,9 +3,6 @@ name: Copilot Cron Test on: workflow_dispatch: -env: - PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright - jobs: build-server-native: name: Build Server native diff --git a/.github/workflows/release-mobile.yml b/.github/workflows/release-mobile.yml index fa9249f4aa..d9cb0a549f 100644 --- a/.github/workflows/release-mobile.yml +++ b/.github/workflows/release-mobile.yml @@ -149,9 +149,11 @@ jobs: p12-file-base64: ${{ secrets.CERTIFICATES_P12_MOBILE }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD_MOBILE }} - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: ./.github/actions/build-rust with: - targets: 'aarch64-apple-ios' + target: 'aarch64-apple-ios' + package: 'affine_mobile_native' + no-build: 'true' - name: Build Rust run: | brew install swiftformat @@ -195,9 +197,11 @@ jobs: hard-link-nm: false enableScripts: false - name: Setup Rust - uses: ./.github/actions/setup-rust + uses: ./.github/actions/build-rust with: - targets: 'aarch64-linux-android' + target: 'aarch64-linux-android' + package: 'affine_mobile_native' + no-build: 'true' - name: Cap sync run: yarn workspace @affine/android cap sync - uses: actions/setup-python@v5