ci: speedup Windows CI (#9426)

This commit is contained in:
Brooooooklyn
2024-12-30 10:10:59 +00:00
parent 569e63377d
commit 8463e4d683
6 changed files with 98 additions and 61 deletions

View File

@@ -7,6 +7,10 @@ inputs:
package: package:
description: 'Package to build' description: 'Package to build'
required: true required: true
no-build:
description: 'Whether to skip building'
required: false
default: 'false'
runs: runs:
using: 'composite' using: 'composite'
@@ -14,20 +18,34 @@ runs:
- name: Print rustup toolchain version - name: Print rustup toolchain version
shell: bash shell: bash
id: rustup-version id: rustup-version
working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }}
run: | run: |
export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')" 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"
echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT" echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT"
- name: Setup Rust - name: Setup Rust
uses: dtolnay/rust-toolchain@stable uses: dtolnay/rust-toolchain@stable
if: ${{ runner.os != 'Windows' }}
with: with:
toolchain: '${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}' toolchain: '${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}'
targets: ${{ inputs.target }} targets: ${{ inputs.target }}
env: env:
CARGO_INCREMENTAL: '1' 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 - 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 shell: bash
run: | run: |
echo "CC=clang" >> "$GITHUB_ENV" echo "CC=clang" >> "$GITHUB_ENV"
@@ -35,12 +53,37 @@ runs:
- name: Cache cargo - name: Cache cargo
uses: Swatinem/rust-cache@v2 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: with:
save-if: ${{ github.ref_name == 'canary' }} save-if: ${{ github.ref_name == 'canary' }}
shared-key: ${{ inputs.target }}-inputs.package shared-key: ${{ inputs.target }}-${{ inputs.package }}
- name: Build - name: Build
shell: bash shell: bash
if: ${{ runner.os != 'Windows' && inputs.no-build != 'true' }}
run: | run: |
yarn workspace ${{ inputs.package }} build --target ${{ inputs.target }} --use-napi-cross yarn workspace ${{ inputs.package }} build --target ${{ inputs.target }} --use-napi-cross
env: env:
DEBUG: 'napi:*' 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

View File

@@ -35,10 +35,19 @@ inputs:
full-cache: full-cache:
description: 'Full installation cache' description: 'Full installation cache'
required: false required: false
runs: runs:
using: 'composite' using: 'composite'
steps: 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 - name: Setup Node.js
uses: actions/setup-node@v4 uses: actions/setup-node@v4
with: with:
@@ -52,26 +61,31 @@ runs:
- name: Init CorePack - name: Init CorePack
if: ${{ inputs.corepack-install == 'true' }} if: ${{ inputs.corepack-install == 'true' }}
shell: bash shell: bash
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
run: corepack enable run: corepack enable
- name: Set nmMode - name: Set nmMode
if: ${{ inputs.hard-link-nm == 'false' }} if: ${{ inputs.hard-link-nm == 'false' }}
shell: bash shell: bash
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
run: yarn config set nmMode classic run: yarn config set nmMode classic
- name: Set nmHoistingLimits - name: Set nmHoistingLimits
if: ${{ inputs.nmHoistingLimits }} if: ${{ inputs.nmHoistingLimits }}
shell: bash shell: bash
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
run: yarn config set nmHoistingLimits ${{ inputs.nmHoistingLimits }} run: yarn config set nmHoistingLimits ${{ inputs.nmHoistingLimits }}
- name: Set enableScripts - name: Set enableScripts
if: ${{ inputs.enableScripts == 'false' }} if: ${{ inputs.enableScripts == 'false' }}
shell: bash shell: bash
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
run: yarn config set enableScripts false run: yarn config set enableScripts false
- name: Set yarn global cache path - name: Set yarn global cache path
shell: bash shell: bash
id: yarn-cache 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 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 - name: Cache non-full yarn cache on Linux
@@ -79,7 +93,7 @@ runs:
if: ${{ inputs.full-cache != 'true' && runner.os == 'Linux' }} if: ${{ inputs.full-cache != 'true' && runner.os == 'Linux' }}
with: with:
path: | path: |
node_modules ${{ steps.workspace-path.outputs.workspace_path }}/node_modules
${{ steps.yarn-cache.outputs.yarn_global_cache }} ${{ 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 }} 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' }} if: ${{ inputs.package-install == 'true' }}
continue-on-error: true continue-on-error: true
shell: bash shell: bash
run: yarn ${{ inputs.extra-flags }} working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
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
run: yarn ${{ inputs.extra-flags }} run: yarn ${{ inputs.extra-flags }}
env: env:
HUSKY: '0' HUSKY: '0'
@@ -138,6 +142,7 @@ runs:
id: playwright-version id: playwright-version
if: ${{ inputs.playwright-install == 'true' }} if: ${{ inputs.playwright-install == 'true' }}
shell: bash 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 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 # Attempt to restore the correct Playwright browser binaries based on the
@@ -150,7 +155,7 @@ runs:
id: playwright-cache id: playwright-cache
if: ${{ inputs.playwright-install == 'true' }} if: ${{ inputs.playwright-install == 'true' }}
with: 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 }}' 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 # 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 # most recently cached version. There's a good chance that at least one
@@ -169,12 +174,14 @@ runs:
shell: bash shell: bash
if: inputs.playwright-install == 'true' if: inputs.playwright-install == 'true'
run: yarn playwright install --with-deps chromium webkit run: yarn playwright install --with-deps chromium webkit
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
env: 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 - name: Get installed Electron version
id: electron-version id: electron-version
if: ${{ inputs.electron-install == 'true' }} if: ${{ inputs.electron-install == 'true' }}
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
shell: bash shell: bash
run: | 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 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 id: electron-cache
if: ${{ inputs.electron-install == 'true' }} if: ${{ inputs.electron-install == 'true' }}
with: 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 }}' 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: | restore-keys: |
${{ runner.os }}-${{ runner.arch }}-${{ steps.system-info.outputs.name }}-${{ steps.system-info.outputs.release }}-${{ steps.system-info.outputs.version }}-electron- ${{ 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 shell: bash
if: inputs.electron-install == 'true' if: inputs.electron-install == 'true'
run: node ./node_modules/electron/install.js run: node ./node_modules/electron/install.js
working-directory: ${{ steps.workspace-path.outputs.workspace_path }}
env: 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

View File

@@ -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

View File

@@ -19,7 +19,6 @@ env:
AFFINE_ENV: dev AFFINE_ENV: dev
COVERAGE: true COVERAGE: true
MACOSX_DEPLOYMENT_TARGET: '10.13' MACOSX_DEPLOYMENT_TARGET: '10.13'
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright
DEPLOYMENT_TYPE: affine DEPLOYMENT_TYPE: affine
concurrency: concurrency:
@@ -280,11 +279,16 @@ jobs:
spec: spec:
- { os: ubuntu-latest, target: x86_64-unknown-linux-gnu } - { os: ubuntu-latest, target: x86_64-unknown-linux-gnu }
- { os: windows-latest, target: x86_64-pc-windows-msvc } - { os: windows-latest, target: x86_64-pc-windows-msvc }
- { os: macos-14, target: x86_64-apple-darwin } - { os: macos-latest, target: x86_64-apple-darwin }
- { os: macos-14, target: aarch64-apple-darwin } - { os: macos-latest, target: aarch64-apple-darwin }
steps: steps:
- uses: actions/checkout@v4 - 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 - name: Setup Node.js
uses: ./.github/actions/setup-node uses: ./.github/actions/setup-node
with: with:
@@ -292,6 +296,7 @@ jobs:
electron-install: false electron-install: false
- name: Setup filename - name: Setup filename
id: filename id: filename
working-directory: ${{ env.DEV_DRIVE_WORKSPACE || github.workspace }}
shell: bash shell: bash
run: | run: |
export PLATFORM_ARCH_ABI=$(node -e "console.log(require('@napi-rs/cli').parseTriple('${{ matrix.spec.target }}').platformArchABI)") 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 uses: actions/upload-artifact@v4
with: with:
name: ${{ steps.filename.outputs.filename }} 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 if-no-files-found: error
build-server-native: build-server-native:
@@ -435,7 +440,10 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Rust - name: Setup Rust
uses: ./.github/actions/setup-rust uses: ./.github/actions/build-rust
with:
package: 'affine'
no-build: 'true'
- name: Install latest nextest release - name: Install latest nextest release
uses: taiki-e/install-action@nextest uses: taiki-e/install-action@nextest
@@ -717,14 +725,14 @@ jobs:
matrix: matrix:
spec: spec:
- { - {
os: macos-14, os: macos-latest,
platform: macos, platform: macos,
arch: x64, arch: x64,
target: x86_64-apple-darwin, target: x86_64-apple-darwin,
test: false, test: false,
} }
- { - {
os: macos-14, os: macos-latest,
platform: macos, platform: macos,
arch: arm64, arch: arm64,
target: aarch64-apple-darwin, target: aarch64-apple-darwin,

View File

@@ -3,9 +3,6 @@ name: Copilot Cron Test
on: on:
workflow_dispatch: workflow_dispatch:
env:
PLAYWRIGHT_BROWSERS_PATH: ${{ github.workspace }}/node_modules/.cache/ms-playwright
jobs: jobs:
build-server-native: build-server-native:
name: Build Server native name: Build Server native

View File

@@ -149,9 +149,11 @@ jobs:
p12-file-base64: ${{ secrets.CERTIFICATES_P12_MOBILE }} p12-file-base64: ${{ secrets.CERTIFICATES_P12_MOBILE }}
p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD_MOBILE }} p12-password: ${{ secrets.CERTIFICATES_P12_PASSWORD_MOBILE }}
- name: Setup Rust - name: Setup Rust
uses: ./.github/actions/setup-rust uses: ./.github/actions/build-rust
with: with:
targets: 'aarch64-apple-ios' target: 'aarch64-apple-ios'
package: 'affine_mobile_native'
no-build: 'true'
- name: Build Rust - name: Build Rust
run: | run: |
brew install swiftformat brew install swiftformat
@@ -195,9 +197,11 @@ jobs:
hard-link-nm: false hard-link-nm: false
enableScripts: false enableScripts: false
- name: Setup Rust - name: Setup Rust
uses: ./.github/actions/setup-rust uses: ./.github/actions/build-rust
with: with:
targets: 'aarch64-linux-android' target: 'aarch64-linux-android'
package: 'affine_mobile_native'
no-build: 'true'
- name: Cap sync - name: Cap sync
run: yarn workspace @affine/android cap sync run: yarn workspace @affine/android cap sync
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5