From f090e0d95331aed6af5d65fcd26b57151b5fdd30 Mon Sep 17 00:00:00 2001 From: Marcel Menk Date: Fri, 2 Oct 2026 17:26:31 +0200 Subject: [PATCH] ci: speed up environment setup speed up the setup of ci environments by caching setup results more agressively so it can be reused in consecutive steps --- .github/actions/setup-env/action.yml | 106 +++++++++++------- .../setup-windows-build-env/action.yml | 21 +++- .github/workflows/pull-request-checks.yml | 16 +++ .github/workflows/release.yml | 14 +++ 4 files changed, 117 insertions(+), 40 deletions(-) diff --git a/.github/actions/setup-env/action.yml b/.github/actions/setup-env/action.yml index ee9fcf0c7..86d4cc6f9 100644 --- a/.github/actions/setup-env/action.yml +++ b/.github/actions/setup-env/action.yml @@ -1,28 +1,54 @@ name: Setup Environment -description: Setup environment variables for the GitHub Actions workflow. +description: Setup Node, dependencies, and optional Electron binaries for GitHub Actions jobs. + +inputs: + install-dependencies: + description: Run a lockfile install (npm ci / yarn / pnpm). Set false when node_modules was restored from artifacts. + required: false + default: 'true' + install-electron: + description: Restore/cache Electron binaries and run the Electron postinstall. + required: false + default: 'false' runs: using: 'composite' steps: + - name: Detect package manager + id: pm + shell: bash + run: | + if [ -f pnpm-lock.yaml ]; then + echo "pm=pnpm" >> "$GITHUB_OUTPUT" + echo "lockfile=pnpm-lock.yaml" >> "$GITHUB_OUTPUT" + exit 0 + fi + if [ -f yarn.lock ]; then + echo "pm=yarn" >> "$GITHUB_OUTPUT" + echo "lockfile=yarn.lock" >> "$GITHUB_OUTPUT" + exit 0 + fi + if [ -f package-lock.json ]; then + echo "pm=npm" >> "$GITHUB_OUTPUT" + echo "lockfile=package-lock.json" >> "$GITHUB_OUTPUT" + exit 0 + fi + echo "pm=pnpm" >> "$GITHUB_OUTPUT" + echo "lockfile=pnpm-lock.yaml" >> "$GITHUB_OUTPUT" + - name: Setup Node from .nvmrc uses: actions/setup-node@v6 with: node-version-file: .nvmrc + cache: ${{ steps.pm.outputs.pm }} + cache-dependency-path: ${{ steps.pm.outputs.lockfile }} - name: Enable corepack shell: bash run: corepack enable || true - - name: Detect package manager - id: pm - shell: bash - run: | - if [ -f pnpm-lock.yaml ]; then echo "pm=pnpm" >> $GITHUB_OUTPUT; exit 0; fi - if [ -f yarn.lock ]; then echo "pm=yarn" >> $GITHUB_OUTPUT; exit 0; fi - if [ -f package-lock.json ]; then echo "pm=npm" >> $GITHUB_OUTPUT; exit 0; fi - echo "pm=pnpm" >> $GITHUB_OUTPUT - - name: Install dependencies + if: inputs.install-dependencies == 'true' shell: bash run: | PM="${{ steps.pm.outputs.pm }}" @@ -30,45 +56,49 @@ runs: if [ "$PM" = "yarn" ]; then yarn install --frozen-lockfile; fi if [ "$PM" = "npm" ]; then npm ci; fi - - name: Set Cypress cache folder - id: cypress-cache + - name: Assert node_modules present + if: inputs.install-dependencies != 'true' + shell: bash + run: | + if [ ! -d node_modules ]; then + echo "::error::install-dependencies is false but node_modules is missing. Restore build artifacts before setup-env, or set install-dependencies to true." + exit 1 + fi + + - name: Apply patches (artifact restore) + if: inputs.install-dependencies != 'true' + shell: bash + run: | + if [ -d patches ]; then + npx patch-package + fi + + - name: Set Electron cache folder + if: inputs.install-electron == 'true' + id: electron-cache shell: bash run: | if [ "${{ runner.os }}" = "Windows" ]; then - CYPRESS_CACHE="$USERPROFILE/.cache/Cypress" + ELECTRON_CACHE="$USERPROFILE/.cache/electron" else - CYPRESS_CACHE="$HOME/.cache/Cypress" + ELECTRON_CACHE="$HOME/.cache/electron" fi - echo "folder=$CYPRESS_CACHE" >> $GITHUB_OUTPUT - echo "CYPRESS_CACHE_FOLDER=$CYPRESS_CACHE" >> $GITHUB_ENV + echo "folder=$ELECTRON_CACHE" >> "$GITHUB_OUTPUT" + echo "ELECTRON_CACHE=$ELECTRON_CACHE" >> "$GITHUB_ENV" - - name: Restore Cypress cache + - name: Restore Electron cache + if: inputs.install-electron == 'true' uses: actions/cache@v5 with: - path: | - ${{ steps.cypress-cache.outputs.folder }} - node_modules/.cache/Cypress - key: ${{ runner.os }}-cypress-${{ hashFiles('**/pnpm-lock.yaml', '**/yarn.lock', '**/package-lock.json') }} + path: ${{ steps.electron-cache.outputs.folder }} + key: ${{ runner.os }}-electron-${{ hashFiles('**/pnpm-lock.yaml', '**/yarn.lock', '**/package-lock.json') }} restore-keys: | - ${{ runner.os }}-cypress- - - - name: Cypress binary install - shell: bash - env: - CYPRESS_CACHE_FOLDER: ${{ steps.cypress-cache.outputs.folder }} - run: | - PM="${{ steps.pm.outputs.pm }}" - if [ "$PM" = "pnpm" ]; then pnpm exec cypress install || true; fi - if [ "$PM" = "yarn" ]; then yarn run -s cypress install || yarn dlx cypress install || true; fi - if [ "$PM" = "npm" ]; then npx --yes cypress install || true; fi + ${{ runner.os }}-electron- - name: Electron binary install + if: inputs.install-electron == 'true' shell: bash working-directory: ./node_modules/electron + env: + ELECTRON_CACHE: ${{ steps.electron-cache.outputs.folder }} run: npm run postinstall || node install.js || true - - - name: Patch package - shell: bash - run: | - npm install -g patch-package - patch-package diff --git a/.github/actions/setup-windows-build-env/action.yml b/.github/actions/setup-windows-build-env/action.yml index 398abf16a..43d4766a2 100644 --- a/.github/actions/setup-windows-build-env/action.yml +++ b/.github/actions/setup-windows-build-env/action.yml @@ -4,9 +4,26 @@ description: Setup Windows build environment for the GitHub Actions workflow. runs: using: 'composite' steps: + - name: Enable i386 architecture + shell: bash + run: sudo dpkg --add-architecture i386 + + - name: Cache apt archives + uses: actions/cache@v5 + with: + path: ${{ github.workspace }}/.apt-archives + key: ${{ runner.os }}-${{ runner.arch }}-apt-wine-mono-xvfb-v1 + - name: Install Wine, Mono, Xvfb and zip tools shell: bash run: | - sudo dpkg --add-architecture i386 + set -euo pipefail + APT_ARCHIVES="${{ github.workspace }}/.apt-archives" + mkdir -p "$APT_ARCHIVES" sudo apt-get update - sudo apt-get install -y wine64 wine32 mono-complete xvfb zip unzip + sudo apt-get install -y \ + -o "Dir::Cache::Archives=$APT_ARCHIVES" \ + -o APT::Keep-Downloaded-Packages=true \ + wine64 wine32 mono-complete xvfb zip unzip + # actions/cache must be able to read archives written by apt (root). + sudo chown -R "$(id -u):$(id -g)" "$APT_ARCHIVES" diff --git a/.github/workflows/pull-request-checks.yml b/.github/workflows/pull-request-checks.yml index d2b6019c0..50e8ea1a4 100644 --- a/.github/workflows/pull-request-checks.yml +++ b/.github/workflows/pull-request-checks.yml @@ -355,6 +355,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Build API container images run: | @@ -397,6 +399,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Build Worker container images run: | @@ -439,6 +443,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Build Server container images run: | @@ -534,6 +540,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Build binaries run: npx nx affected --target=scripts-binary --parallel=3 @@ -559,6 +567,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Install OpenAPI Generator CLI run: | @@ -590,6 +600,9 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' + install-electron: 'true' - name: Build binaries env: @@ -631,6 +644,9 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' + install-electron: 'true' - name: Setup Windows build environment uses: ./.github/actions/setup-windows-build-env diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 021e3eb4f..047c3acd0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -109,6 +109,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: 'Login to container registry' uses: docker/login-action@v4 @@ -156,6 +158,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: 'Login to container registry' uses: docker/login-action@v4 @@ -203,6 +207,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: 'Login to container registry' uses: docker/login-action@v4 @@ -250,6 +256,8 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' - name: Configure npm for GitHub Packages run: | @@ -294,6 +302,9 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' + install-electron: 'true' - name: Build binaries env: @@ -342,6 +353,9 @@ jobs: - name: Setup environment uses: ./.github/actions/setup-env + with: + install-dependencies: 'false' + install-electron: 'true' - name: Setup Windows build environment uses: ./.github/actions/setup-windows-build-env