Skip to content
Merged
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
64 changes: 63 additions & 1 deletion .github/workflows/pr-linux-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: x64
Expand Down Expand Up @@ -76,12 +80,64 @@ jobs:
UNIT_TEST_SUITE: electron
TEST_SELECTION: 'true'
steps: &steps
# A workspace image of main holds a workspace whose dependencies, Electron, Playwright browsers,
# and the sysroots and compilers of setup-env.sh 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, as in pr-workspace-images.yml.
- name: Download the workspace image scripts
id: image-scripts
continue-on-error: true
shell: bash
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
dir="$RUNNER_TEMP/workspace-image"
mkdir -p "$dir"
echo '{ "type": "module" }' > "$dir/package.json"
# The scripts keep their folders below workspace_image, such as win32/vhd.ps1
files=(.nvmrc .github/workflows/workspace_image/{image.ts,win32/vhd.ps1,win32/Vhd.cs})
args=()
for file in "${files[@]}"; do
args+=(-o "$dir/${file#.github/workflows/workspace_image/}" "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/contents/$file?ref=$GITHUB_SHA")
done
curl -fsSL --retry 3 --parallel --create-dirs -H "Authorization: Bearer $GH_TOKEN" -H 'Accept: application/vnd.github.raw' "${args[@]}"
for file in "${files[@]}"; do
[ -s "$dir/${file#.github/workflows/workspace_image/}" ]
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 }}

# The image is an ext4 volume, which a loop device mounts at the parent of the workspace. image.ts
# gives up before the timeout of the step, which could stop it with the image half mounted, and
# then unmounts it and detaches the loop device as after any other error, so that the job sets up
# as without an image. Pull requests to release branches look for images of their own branch,
# which pr-workspace-images.yml doesn't build.
- 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" --timeout-seconds 240
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
# With a workspace image, keeps its untracked files, such as node_modules, and reuses its .git
clean: ${{ steps.image.outputs.used != 'true' }}

- name: Setup Node.js
if: steps.image-scripts.outcome != 'success'
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version-file: .nvmrc
Expand Down Expand Up @@ -111,8 +167,10 @@ jobs:
sudo update-rc.d xvfb defaults
sudo service xvfb start

# A workspace image holds the node_modules of its commit, which the install steps update
- 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
Expand All @@ -135,6 +193,8 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# On a workspace image, pnpm installs only what changed since the commit of the image, and
# setup-env.sh reuses the sysroots and compilers in its .build folder
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: |
Expand Down Expand Up @@ -313,8 +373,10 @@ 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, and points PLAYWRIGHT_BROWSERS_PATH at them, which this
# action would point into the workspace.
- 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
4 changes: 2 additions & 2 deletions .github/workflows/pr-workspace-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ name: Code OSS (workspace images)
# pr-darwin-test.yml and pr-win32-test.yml): a disk image of a workspace of main, with its
# dependencies, Electron and the Playwright browsers installed, at the path of the workspaces of the
# jobs, and with a .git that their checkouts reuse. A job that mounts an image installs only what
# changed since. The Windows test jobs use the images, and the Linux and macOS test jobs adopt them
# in follow-up pull requests. See .github/workflows/workspace_image/README.md.
# changed since. The Windows and Linux test jobs use the images, and the macOS test jobs adopt them
# in a follow-up pull request. See .github/workflows/workspace_image/README.md.
# The daily and manual runs also prepare the WSL distribution of the Windows smoke tests (the
# wsl-distro job).
on:
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ jobs:
name: Linux
needs: changes
if: ${{ !cancelled() }}
# actions: read finds and downloads the workspace image (see .github/workflows/workspace_image/README.md)
permissions:
contents: read
pull-requests: read
actions: read
uses: ./.github/workflows/pr-linux-test.yml
with:
electron_unit_affected: ${{ needs.changes.result != 'success' || needs.changes.outputs.selected-unit-tests == 'true' }}
Expand All @@ -505,6 +510,8 @@ jobs:
# The provider integration tests and the Agent Host E2E tests read the profile.
agent_host_test_profile: ${{ needs.changes.outputs.agent-host-test-profile || 'full' }}
agent_host_test_profile_reason: ${{ needs.changes.outputs.agent-host-test-profile-reason || 'Change detection unavailable' }}
# Pull requests to release branches find no images of their branch, and install everything.
workspace_image_branch: ${{ github.base_ref }}

macos-tests:
name: macOS
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/workspace_image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Workspace images let the test jobs of pull requests ([pr-linux-test.yml](../pr-linux-test.yml), [pr-darwin-test.yml](../pr-darwin-test.yml) and [pr-win32-test.yml](../pr-win32-test.yml)) start from a disk image of a workspace of `main` instead of an empty folder: its dependencies, Electron and the Playwright browsers are installed, and its `.git` holds the commit it was built at. A job mounts the image, checks out its own commit, and installs only what changed since, which for most pull requests is nothing.

The Windows test jobs use the images, except the smoke test shard with the WSL suite, which runs on the 1ES pool and keeps its workspace on drive C. The Linux and macOS test jobs adopt them in follow-up pull requests, and until then install everything as before. [What a job does](#what-a-job-does) describes the steps of a job that uses the images.
The Windows and Linux test jobs use the images, except the Windows smoke test shard with the WSL suite, which runs on the 1ES pool and keeps its workspace on drive C. The macOS test jobs adopt them in a follow-up pull request, and until then install everything as before. [What a job does](#what-a-job-does) describes the steps of a job that uses the images.

[pr-workspace-images.yml](../pr-workspace-images.yml) builds an image for each platform on the runners of the jobs every day at 05:00 UTC, and when one of its inputs changes on `main`: those of the install, of the native builds (`NATIVE_BUILD_INPUTS` in `image.ts`) and of the prepared Electron. It doesn't build them for other pushes, as the checkout of a job fetches and writes only what changed since the commit of its image. The images are kept for 2 days, so the daily build keeps a recent image available. [image.ts](image.ts) restores, checks and builds them; it has no dependencies, as the jobs run it before they check out the repository.

Expand All @@ -11,7 +11,7 @@ The Windows test jobs use the images, except the smoke test shard with the WSL s
1. **Downloads the scripts** of its commit from the API (`image.ts`, and on Windows `win32/vhd.ps1` and `win32/Vhd.cs`), and `.nvmrc` for the Node.js version.
2. **Restores the image** (`image.ts restore`): finds the newest image of `main`, downloads it with parallel range requests, and mounts it at the parent folder of the workspace, so that the workspace keeps its path. Without an image, or on any error, it warns and the job installs everything as before. It gives up after 4 minutes (`--timeout-seconds`), before the timeout of its step could stop it with the image half attached, and then, as after any other error, unmounts and detaches the image, so that the workspace is an empty folder again; on Windows, it also deletes the VHDX, whose data Windows keeps in memory. Pull requests to release branches look for images of their own branch (`--branch`), which aren't built, and install everything as before. The job also doesn't use an image when the inputs of the base key of the `node_modules` caches (`computeNodeModulesBaseCacheKey` in `build/azure-pipelines/common/cacheKeys.ts`: the salt of the CI caches, the pnpmfiles, the `nativeBuild` targets and `packageManager` of `package.json`, the Node.js versions and the pnpm settings of the install roots, mirrored in `NATIVE_BUILD_INPUTS` of `image.ts`) differ between the commit of the image and its own, which the restore compares through the API before it downloads anything: installing on top of an image wouldn't build its native modules again, for example after an Electron update.
3. **Checks out its commit** with `clean: false`, which keeps the untracked files of the image and reuses its checkout: the shallow fetch sends the tag at the commit of the image, and downloads only what changed since, and git writes only the files that changed, as it compares their sizes and modification times, which the image keeps.
4. **Installs the dependencies** with its usual install steps, on the `node_modules` of the image instead of those of the `node_modules` cache. `pnpm install`, whose postinstall installs every other install root, installs only what changed since the commit of the image, as pnpm checks itself what is up to date.
4. **Installs the dependencies** with its usual install steps, on the `node_modules` of the image instead of those of the `node_modules` cache. `pnpm install`, whose postinstall installs every other install root, installs only what changed since the commit of the image, as pnpm checks itself what is up to date. On Linux, `setup-env.sh` reuses the sysroots and compilers in the `.build` folder of the image, and the system packages are installed as before, as they aren't in the image.
5. **Keeps the prepared Electron** when it was prepared from the same inputs (see [setup-electron](../../actions/setup-electron/action.yml)), and finds the Playwright browsers in the image (`PLAYWRIGHT_BROWSERS_PATH`), instead of in their cache, which would point `PLAYWRIGHT_BROWSERS_PATH` into the workspace.

## The images
Expand Down
10 changes: 7 additions & 3 deletions build/lib/test/workspaceImage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,17 @@ function loadSteps(workflow: string, job: string): readonly IStep[] {
}

suite('workspace images', () => {
// image.ts finds vhd.ps1 in the win32 folder beside it, which the download keeps
test('the Windows test jobs download the scripts like the job that builds the Windows image', () => {
// image.ts finds vhd.ps1 in the win32 folder beside it, which the download keeps. The jobs of a
// test workflow share their steps, so its first job stands for all of them.
test('the test jobs download the scripts like the jobs that build the images', () => {
const download = (workflow: string, job: string) => {
const step = loadSteps(workflow, job).find(step => step.id === 'image-scripts');
return { name: step?.name, shell: step?.shell, env: step?.env, run: step?.run };
};
assert.deepEqual(download('pr-win32-test.yml', 'electron-unit'), download('pr-workspace-images.yml', 'windows'));
assert.deepEqual(
{ linux: download('pr-linux-test.yml', 'electron-unit-electron'), windows: download('pr-win32-test.yml', 'electron-unit') },
{ linux: download('pr-workspace-images.yml', 'linux'), windows: download('pr-workspace-images.yml', 'windows') }
);
});

// image.ts runs before the checkout, without the files of the repository, so it lists the inputs
Expand Down
Loading