Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 87f4535

Browse files
authored
chore: optimize CI setup time on Windows (#17666)
This PR focuses on optimizing go-test CI times on Windows. It: - backs the `$RUNNER_TEMP` directory with a RAM disk. This directory is used by actions like cache, setup-go, and setup-terraform as a staging area - backs `GOCACHE`, `GOMODCACHE`, and `GOPATH` with a RAM disk - backs `$GITHUB_WORKSPACE` with a RAM disk - that's where the repository is checked out - uses preinstalled Go on Windows runners - starts using the depot Windows runner From what I've seen, these changes bring test times down to be on par with Linux and macOS. The biggest improvement comes from backing frequently accessed paths with RAM disks. The C drive is surprisingly slow - I ran some performance tests with [fio](https://fio.readthedocs.io/en/latest/fio_doc.html#) where I tested IOPS on many small files, and the RAM disk was 100x faster. Additionally, the depot runners seem to have more consistent performance than the ones provided by GitHub.
1 parent a646478 commit 87f4535

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

.github/actions/setup-go/action.yaml

+27-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,42 @@ inputs:
55
version:
66
description: "The Go version to use."
77
default: "1.24.2"
8+
use-preinstalled-go:
9+
description: "Whether to use preinstalled Go."
10+
default: "false"
11+
use-temp-cache-dirs:
12+
description: "Whether to use temporary GOCACHE and GOMODCACHE directories."
13+
default: "false"
814
runs:
915
using: "composite"
1016
steps:
17+
- name: Override GOCACHE and GOMODCACHE
18+
shell: bash
19+
if: inputs.use-temp-cache-dirs == 'true'
20+
run: |
21+
# cd to another directory to ensure we're not inside a Go project.
22+
# That'd trigger Go to download the toolchain for that project.
23+
cd "$RUNNER_TEMP"
24+
# RUNNER_TEMP should be backed by a RAM disk on Windows if
25+
# coder/setup-ramdisk-action was used
26+
export GOCACHE_DIR="$RUNNER_TEMP""\go-cache"
27+
export GOMODCACHE_DIR="$RUNNER_TEMP""\go-mod-cache"
28+
export GOPATH_DIR="$RUNNER_TEMP""\go-path"
29+
mkdir -p "$GOCACHE_DIR"
30+
mkdir -p "$GOMODCACHE_DIR"
31+
mkdir -p "$GOPATH_DIR"
32+
go env -w GOCACHE="$GOCACHE_DIR"
33+
go env -w GOMODCACHE="$GOMODCACHE_DIR"
34+
go env -w GOPATH="$GOPATH_DIR"
35+
1136
- name: Setup Go
1237
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
1338
with:
14-
go-version: ${{ inputs.version }}
39+
go-version: ${{ inputs.use-preinstalled-go == 'false' && inputs.version || '' }}
1540

1641
- name: Install gotestsum
1742
shell: bash
18-
run: go install gotest.tools/gotestsum@latest
43+
run: go install gotest.tools/gotestsum@3f7ff0ec4aeb6f95f5d67c998b71f272aa8a8b41 # v1.12.1
1944

2045
# It isn't necessary that we ever do this, but it helps
2146
# separate the "setup" from the "run" times.

.github/workflows/ci.yaml

+15-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ jobs:
313313
run: ./scripts/check_unstaged.sh
314314

315315
test-go:
316-
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'windows-latest-16-cores' || matrix.os }}
316+
runs-on: ${{ matrix.os == 'ubuntu-latest' && github.repository_owner == 'coder' && 'depot-ubuntu-22.04-4' || matrix.os == 'macos-latest' && github.repository_owner == 'coder' && 'depot-macos-latest' || matrix.os == 'windows-2022' && github.repository_owner == 'coder' && 'depot-windows-2022-16' || matrix.os }}
317317
needs: changes
318318
if: needs.changes.outputs.go == 'true' || needs.changes.outputs.ci == 'true' || github.ref == 'refs/heads/main'
319319
timeout-minutes: 20
@@ -326,17 +326,31 @@ jobs:
326326
- windows-2022
327327
steps:
328328
- name: Harden Runner
329+
# Harden Runner is only supported on Ubuntu runners.
330+
if: runner.os == 'Linux'
329331
uses: step-security/harden-runner@0634a2670c59f64b4a01f0f96f84700a4088b9f0 # v2.12.0
330332
with:
331333
egress-policy: audit
332334

335+
# Set up RAM disks to speed up the rest of the job. This action is in
336+
# a separate repository to allow its use before actions/checkout.
337+
- name: Setup RAM Disks
338+
if: runner.os == 'Windows'
339+
uses: coder/setup-ramdisk-action@79dacfe70c47ad6d6c0dd7f45412368802641439
340+
333341
- name: Checkout
334342
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
335343
with:
336344
fetch-depth: 1
337345

338346
- name: Setup Go
339347
uses: ./.github/actions/setup-go
348+
with:
349+
# Runners have Go baked-in and Go will automatically
350+
# download the toolchain configured in go.mod, so we don't
351+
# need to reinstall it. It's faster on Windows runners.
352+
use-preinstalled-go: ${{ runner.os == 'Windows' }}
353+
use-temp-cache-dirs: ${{ runner.os == 'Windows' }}
340354

341355
- name: Setup Terraform
342356
uses: ./.github/actions/setup-tf

0 commit comments

Comments
 (0)