Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions .github/actions/setup-electron/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Setup Electron
description: Restores cached Electron archives, validates and prepares Electron, and optionally saves the cache. Expects pnpm to be set up, except in lookup-only mode.
description: Restores cached Electron archives, validates and prepares Electron, and optionally saves the cache. Keeps an Electron that was prepared from the same inputs, as in a workspace image. Expects pnpm to be set up, except in lookup-only mode.

inputs:
arch:
Expand All @@ -20,6 +20,22 @@ outputs:
runs:
using: composite
steps:
# `pnpm run electron` prepares .build/electron from these inputs, including the root package.json,
# which it packages and which holds the Electron version, and the pnpm-lock.yaml that pins
# @vscode/gulp-electron. A workspace image holds the Electron that it prepared (see
# .github/workflows/workspace_image/README.md).
- name: Check the prepared Electron
id: prepared
if: inputs.lookup-only != 'true'
shell: bash
run: |
if [ -d .build/electron ] && [ "$(cat .build/electron.stamp 2>/dev/null)" = "$STAMP" ]; then
echo "Electron is prepared from the same inputs"
echo "current=true" >> "$GITHUB_OUTPUT"
fi
env:
STAMP: ${{ runner.os }}-${{ inputs.arch }}-${{ hashFiles('build/checksums/electron.txt', 'product.json', 'package.json', 'pnpm-lock.yaml', 'build/lib/electron.ts', 'build/lib/electronVersion.ts', 'build/pnpm-lock.yaml', 'resources/darwin/*.icns', 'resources/win32/code.ico') }}

- name: Prepare Electron cache path
if: runner.os != 'Windows'
shell: bash
Expand All @@ -39,16 +55,18 @@ runs:

- name: Restore Electron cache
id: restore
if: steps.prepared.outputs.current != 'true'
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ env.ELECTRON_CACHE_PATH }}
key: "electron-download-v1-${{ runner.os }}-${{ inputs.arch }}-${{ hashFiles('build/checksums/electron.txt') }}"
lookup-only: ${{ inputs.lookup-only }}

- name: Download Electron
if: inputs.lookup-only != 'true' && runner.os != 'Windows'
if: inputs.lookup-only != 'true' && steps.prepared.outputs.current != 'true' && runner.os != 'Windows'
shell: bash
run: |
rm -f .build/electron.stamp
for i in {1..3}; do
if pnpm run electron "$VSCODE_ARCH"; then
echo "Download successful on attempt $i"
Expand All @@ -67,12 +85,13 @@ runs:
VSCODE_ARCH: ${{ inputs.arch }}

- name: Download Electron
if: inputs.lookup-only != 'true' && runner.os == 'Windows'
if: inputs.lookup-only != 'true' && steps.prepared.outputs.current != 'true' && runner.os == 'Windows'
shell: pwsh
run: |
. build/azure-pipelines/win32/exec.ps1
$ErrorActionPreference = "Stop"

Remove-Item -Force -ErrorAction SilentlyContinue .build/electron.stamp
for ($i = 1; $i -le 3; $i++) {
try {
exec { pnpm run electron $env:VSCODE_ARCH }
Expand All @@ -90,8 +109,15 @@ runs:
env:
VSCODE_ARCH: ${{ inputs.arch }}

- name: Stamp the prepared Electron
if: inputs.lookup-only != 'true' && steps.prepared.outputs.current != 'true'
shell: bash
run: echo "$STAMP" > .build/electron.stamp
env:
STAMP: ${{ runner.os }}-${{ inputs.arch }}-${{ hashFiles('build/checksums/electron.txt', 'product.json', 'package.json', 'pnpm-lock.yaml', 'build/lib/electron.ts', 'build/lib/electronVersion.ts', 'build/pnpm-lock.yaml', 'resources/darwin/*.icns', 'resources/win32/code.ico') }}

- name: Save Electron cache
if: inputs.lookup-only != 'true' && inputs.save-cache == 'true' && steps.restore.outputs.cache-hit != 'true'
if: inputs.lookup-only != 'true' && inputs.save-cache == 'true' && steps.prepared.outputs.current != 'true' && steps.restore.outputs.cache-hit != 'true'
uses: actions/cache/save@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0
with:
path: ${{ env.ELECTRON_CACHE_PATH }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/node_modules_cache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ on Linux and `LOCALAPPDATA` on Windows. Cache paths and keys are handled within
the action.

Even on a cache hit, PR jobs run `pnpm run electron` to validate and prepare the
application from the cached archives using the current checkout. Checksum
application from the cached archives using the current checkout, unless
`.build/electron` was prepared from the same inputs: `setup-electron` stamps
them in `.build/electron.stamp`, which keeps the Electron of a
[workspace image](../workspace_image/README.md). Checksum
validation remains enabled: the current downloader still fetches
`SHASUMS256.txt` from GitHub, so this cache avoids the large ZIP downloads but
does not make Electron setup entirely network-independent.
Expand Down
60 changes: 58 additions & 2 deletions .github/workflows/pr-darwin-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ on:
description: Reason for selecting the Agent Host test profile
type: string
default: Change detection unavailable
workspace_image_branch:
description: The branch whose workspace images the jobs use (see .github/workflows/workspace_image/README.md)
type: string
default: main

env:
NPM_ARCH: arm64
Expand Down Expand Up @@ -79,28 +83,79 @@ jobs:
UNIT_TESTS: 'true'
TEST_SELECTION: 'true'
steps: &steps
# A workspace image of main holds a workspace whose dependencies, Electron and Playwright browsers
# are installed, which the checkout updates (see .github/workflows/workspace_image/README.md). Its
# scripts run before the checkout, so they come from the API, at the commit that the job tests.
- name: Download the workspace image scripts
id: image-scripts
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
dir="$RUNNER_TEMP/workspace-image"
mkdir -p "$dir"
echo '{ "type": "module" }' > "$dir/package.json"
files=(.nvmrc .github/workflows/workspace_image/image.ts)
args=()
for file in "${files[@]}"; do
args+=(-o "$dir/${file##*/}" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/contents/$file?ref=$GITHUB_SHA")
done
curl -fsSL --retry 3 --parallel -H "Authorization: Bearer $GH_TOKEN" -H 'Accept: application/vnd.github.raw' "${args[@]}"
for file in "${files[@]}"; do
[ -s "$dir/${file##*/}" ]
done
echo "node-version=$(tr -d '[:space:]' < "$dir/.nvmrc")" >> "$GITHUB_OUTPUT"

- name: Setup Node.js
if: steps.image-scripts.outcome == 'success'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ steps.image-scripts.outputs.node-version }}

# Without an image, the job installs everything as before
- name: Restore the workspace image
id: image
if: steps.image-scripts.outcome == 'success'
continue-on-error: true
timeout-minutes: 5
working-directory: ${{ runner.temp }}
run: node "$RUNNER_TEMP/workspace-image/image.ts" restore --name workspace-image-darwin-arm64.img --branch "$WORKSPACE_IMAGE_BRANCH"
env:
GH_TOKEN: ${{ github.token }}
WORKSPACE_IMAGE_BRANCH: ${{ inputs.workspace_image_branch }}

- name: Checkout microsoft/vscode
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
lfs: true
# Keeps the files of the workspace image, and reuses its .git
clean: false

- name: Setup Node.js
if: steps.image-scripts.outcome != 'success'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc

- name: Compare the dependencies with the workspace image
id: image-deps
if: steps.image.outputs.used == 'true'
run: node "$RUNNER_TEMP/workspace-image/image.ts" deps

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

- name: Restore node_modules cache
id: cache-node-modules
if: steps.image.outputs.used != 'true'
uses: ./.github/actions/restore-node-modules
with:
key-prefix: node_modules-macos
key-args: "darwin ${{ env.VSCODE_ARCH }} $(node -p process.arch)"

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
if: steps.cache-node-modules.outputs.cache-hit != 'true' && steps.image-deps.outputs.current != 'true'
run: |
set -e
c++ --version
Expand Down Expand Up @@ -164,8 +219,9 @@ jobs:
run: pnpm run compile

# pr-node-modules.yml fills this cache on main, so pull requests don't download the browsers.
# A workspace image holds them already (PLAYWRIGHT_BROWSERS_PATH).
- name: Restore Playwright browsers
if: ${{ env.BROWSER_TESTS == 'true' }}
if: ${{ env.BROWSER_TESTS == 'true' && steps.image.outputs.used != 'true' }}
uses: ./.github/actions/restore-playwright
with:
browsers: --only-shell chromium webkit
Expand Down
62 changes: 59 additions & 3 deletions .github/workflows/pr-linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ on:
description: Reason for selecting the Agent Host test profile
type: string
default: Change detection unavailable
workspace_image_branch:
description: The branch whose workspace images the jobs use (see .github/workflows/workspace_image/README.md)
type: string
default: main

env:
NPM_ARCH: x64
Expand Down Expand Up @@ -69,16 +73,66 @@ jobs:
UNIT_TESTS: 'true'
UNIT_TEST_SUITE: electron
steps: &steps
# A workspace image of main holds a workspace whose dependencies, Electron and Playwright browsers
# are installed, which the checkout updates (see .github/workflows/workspace_image/README.md). Its
# scripts run before the checkout, so they come from the API, at the commit that the job tests.
- name: Download the workspace image scripts
id: image-scripts
continue-on-error: true
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
dir="$RUNNER_TEMP/workspace-image"
mkdir -p "$dir"
echo '{ "type": "module" }' > "$dir/package.json"
files=(.nvmrc .github/workflows/workspace_image/image.ts)
args=()
for file in "${files[@]}"; do
args+=(-o "$dir/${file##*/}" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/contents/$file?ref=$GITHUB_SHA")
done
curl -fsSL --retry 3 --parallel -H "Authorization: Bearer $GH_TOKEN" -H 'Accept: application/vnd.github.raw' "${args[@]}"
for file in "${files[@]}"; do
[ -s "$dir/${file##*/}" ]
done
echo "node-version=$(tr -d '[:space:]' < "$dir/.nvmrc")" >> "$GITHUB_OUTPUT"

- name: Setup Node.js
if: steps.image-scripts.outcome == 'success'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: ${{ steps.image-scripts.outputs.node-version }}

# Without an image, the job installs everything as before
- name: Restore the workspace image
id: image
if: steps.image-scripts.outcome == 'success'
continue-on-error: true
timeout-minutes: 5
working-directory: ${{ runner.temp }}
run: node "$RUNNER_TEMP/workspace-image/image.ts" restore --name workspace-image-linux-x64.img --branch "$WORKSPACE_IMAGE_BRANCH"
env:
GH_TOKEN: ${{ github.token }}
WORKSPACE_IMAGE_BRANCH: ${{ inputs.workspace_image_branch }}

- name: Checkout microsoft/vscode
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
lfs: true
# Keeps the files of the workspace image, and reuses its .git
clean: false

- name: Setup Node.js
if: steps.image-scripts.outcome != 'success'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc

- name: Compare the dependencies with the workspace image
id: image-deps
if: steps.image.outputs.used == 'true'
run: node "$RUNNER_TEMP/workspace-image/image.ts" deps

- name: Setup pnpm
uses: ./.github/actions/setup-pnpm

Expand Down Expand Up @@ -106,13 +160,14 @@ jobs:

- name: Restore node_modules cache
id: cache-node-modules
if: steps.image.outputs.used != 'true'
uses: ./.github/actions/restore-node-modules
with:
key-prefix: node_modules-linux
key-args: "linux ${{ env.VSCODE_ARCH }} $(node -p process.arch)"

- name: Install build dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
if: steps.cache-node-modules.outputs.cache-hit != 'true' && steps.image-deps.outputs.current != 'true'
working-directory: build
run: |
set -e
Expand All @@ -129,7 +184,7 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
if: steps.cache-node-modules.outputs.cache-hit != 'true' && steps.image-deps.outputs.current != 'true'
Comment thread
lszomoru marked this conversation as resolved.
Resolved
run: |
set -e

Expand Down Expand Up @@ -306,8 +361,9 @@ jobs:
run: pnpm run compile

# pr-node-modules.yml fills this cache on main, so pull requests don't download the browsers.
# A workspace image holds them already (PLAYWRIGHT_BROWSERS_PATH).
- name: Restore Playwright browsers
if: ${{ env.BROWSER_TESTS == 'true' }}
if: ${{ env.BROWSER_TESTS == 'true' && steps.image.outputs.used != 'true' }}
uses: ./.github/actions/restore-playwright
with:
browsers: --only-shell chromium
Expand Down
Loading
Loading