Files
coder/scripts/normalize_path.sh
Hugo Dutka a0e229afec chore: run test-go-pg on macOS and Windows in regular CI (#17853)
This PR starts running test-go-pg on macOS and Windows in regular CI.
Previously this suite was only run in the nightly gauntlet for 2
reasons:

- it was flaky
- it was slow (took 17 minutes)

We've since stabilized the flakiness by switching to depot runners,
using ram disks, optimizing the number of tests run in parallel, and
automatically re-running failing tests. We've also [brought
down](https://github.com/coder/coder/pull/17756) the time to run the
suite to 9 minutes. Additionally, this PR allows test-go-pg to use cache
from previous runs, which speeds it up further. The cache is only used
on PRs, `main` will still run tests without it.

This PR also:

- removes the nightly gauntlet since all tests now run in regular CI
- removes the `test-cli` job for the same reason
- removes the `setup-imdisk` action which is now fully replaced by
[coder/setup-ramdisk-action](https://github.com/coder/setup-ramdisk-action)
- makes 2 minor changes which could be separate PRs, but I rolled them
into this because they were helpful when iterating on it:
- replace the `if: always()` condition on the `gen` job with a `if: ${{
!cancelled() }}` to allow the job to be cancelled. Previously the job
would run to completion even if the entire workflow was cancelled. See
[the GitHub
docs](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/evaluate-expressions-in-workflows-and-actions#always)
for more details.
- disable the recently added `TestReinitializeAgent` since it does not
pass on Windows with Postgres. There's an open issue to fix it:
https://github.com/coder/internal/issues/642

This PR will:

- unblock https://github.com/coder/coder/issues/15109
- alleviate https://github.com/coder/internal/issues/647

I tested caching by temporarily enabling cache upload on this PR: here's
[a
run](https://github.com/coder/coder/actions/runs/15119046903/job/42496939341?pr=17853#step:13:1296)
showing cache being used.
2025-05-22 15:53:37 +02:00

56 lines
1.5 KiB
Bash

#!/bin/bash
# Call: normalize_path_with_symlinks [target_dir] [dir_prefix]
#
# Normalizes the PATH environment variable by replacing each directory that
# begins with dir_prefix with a symbolic link in target_dir. For example, if
# PATH is "/usr/bin:/bin", target_dir is /tmp, and dir_prefix is /usr, then
# PATH will become "/tmp/0:/bin", where /tmp/0 links to /usr/bin.
#
# This is useful for ensuring that PATH is consistent across CI runs and helps
# with reusing the same cache across them. Many of our go tests read the PATH
# variable, and if it changes between runs, the cache gets invalidated.
normalize_path_with_symlinks() {
local target_dir="${1:-}"
local dir_prefix="${2:-}"
if [[ -z "$target_dir" || -z "$dir_prefix" ]]; then
echo "Usage: normalize_path_with_symlinks <target_dir> <dir_prefix>"
return 1
fi
local old_path="$PATH"
local -a new_parts=()
local i=0
IFS=':' read -ra _parts <<<"$old_path"
for dir in "${_parts[@]}"; do
# Skip empty components that can arise from "::"
[[ -z $dir ]] && continue
# Skip directories that don't start with $dir_prefix
if [[ "$dir" != "$dir_prefix"* ]]; then
new_parts+=("$dir")
continue
fi
local link="$target_dir/$i"
# Replace any pre-existing file or link at $target_dir/$i
if [[ -e $link || -L $link ]]; then
rm -rf -- "$link"
fi
# without MSYS ln will deepcopy the directory on Windows
MSYS=winsymlinks:nativestrict ln -s -- "$dir" "$link"
new_parts+=("$link")
i=$((i + 1))
done
export PATH
PATH="$(
IFS=':'
echo "${new_parts[*]}"
)"
}