mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-05-31 13:56:13 -07:00
* chore: quality-tightening (oxfmt + oxlint + tsc + vitest + husky + actionlint)
Standard rollout for unity-builder. Most of the work was porting 24
test files from jest 27 to vitest 4.
- prettier -> oxfmt
- eslint (with @typescript-eslint, github, jest, prettier, unicorn) ->
oxlint with eslint-plugin-unicorn
- jest 27 + jest-circus + ts-jest + @types/jest + @jest/globals ->
vitest 4 + vite 7 + @vitest/coverage-istanbul (jest config files
removed)
- new: tsgo --noEmit (alongside tsc fallback)
- lefthook (and lefthook.yml) -> husky 9 with the standard
scripts/ensure-husky.mjs self-heal pattern + lint-staged
- new: gitleaks, actionlint, shellcheck as mise-managed binaries
- TypeScript bumped target ES2020 -> ES2022 + lib ES2022 + DOM (for
Error.cause and modern globals)
Test migration (24 files):
- Bulk-converted jest.* -> vi.*; jest.Mocked -> Mocked from vitest;
jest.MockedFunction -> MockedFunction.
- Added vitest imports to all *.test.ts files (and __mocks__/*.ts)
that didn't have them.
- src/index.ts: extracted runMain() as a named export and gated the
module-level invocation behind NODE_ENV !== 'test'. The
index-plugin-features test now calls runMain() directly instead of
relying on jest's removed vi.isolateModules.
- index-plugin-features.test.ts: moved hoisted refs (mockPlugin,
mockLoadOrchestratorPlugin) into vi.hoisted() so vi.mock factories
can reference them. Replaced arrow constructor mock for ImageTag
with regular function() {...} (vitest 4 disallows arrows as ctors).
Replaced require('./model') / require('@actions/core') inside test
bodies with top-level imports.
- model/orchestrator-plugin.test.ts: dropped jest's '{ virtual: true }'
flag (vitest doesn't support it); replaced the
'mock factory throws' pattern with 'createPlugin throws' so vitest
doesn't wrap the error message at the assertion site.
- model/versioning.test.ts: stray jest.spyOn -> vi.spyOn; replaced
mockImplementation() with no args (jest pattern) by
mockResolvedValue('') / mockImplementation(() => undefined) where
the source expects a string return.
Workflow shell-quoting cleanup (actionlint):
- All bare $GITHUB_STEP_SUMMARY / $GITHUB_OUTPUT / $GITHUB_ENV
redirects quoted across 2 workflows (SC2086).
- s3://$AWS_STACK_NAME / s3://$BUCKET_NAME -> s3://"$AWS_STACK_NAME"
/ s3://"$BUCKET_NAME".
- 'for i in {1..N}; do ... done' loops where i isn't referenced in
the body renamed to 'for _ in' (SC2034).
- 'grep ... | wc -l' -> 'grep -c ...' (SC2126).
- Multiple consecutive '>> $file' redirects in
validate-community-plugins.yml summary block collapsed into a
single block redirect (SC2129).
- 'cat $file | python3 -c "..."' -> 'python3 -c "..." < $file'
(SC2002).
- http://${VAR}:port -> http://"${VAR}":port (SC2086).
tsgo: kept tsc --noEmit as the default 'typecheck' because
unity-builder publishes CommonJS for the GitHub Action consumer,
which conflicts with tsgo's bundler/node16 moduleResolution
requirement (per playbook trap #9). 'yarn typecheck:tsgo' is wired
up for when consumers move to ESM.
Caveats: 28 pre-existing oxlint warnings remain (mostly
typescript/no-explicit-any across the build-parameter shapes and
vitest/no-disabled-tests on 2 explicitly skipped scenarios). Per
playbook trap #22 the lint script drops --deny-warnings.
Verified locally: format clean, lint 0/28, typecheck clean,
test 340/342 (2 pre-existing skipped), actionlint clean across all
12 workflows.
* ci(unity-builder): fix Tests + Plugin Architecture Health on quality-tightening
Three issues surfaced in CI after the jest -> vitest port:
1. **Obsolete snapshot blocks Tests job.**
src/model/__snapshots__/versioning.test.ts.snap had two entries
for the same 'throws for invalid strategy' assertion: one in the
vitest format ('Versioning > determineBuildVersion > ...') and one
in the legacy jest format without the '>'. vitest correctly
regenerates the new one and flags the old one as obsolete; CI
runs without --update so 'Test Files 1 failed' even though all
343 tests passed. Removed the obsolete entry.
2. **'Plugin Architecture Health' workflow still calls jest.**
.github/workflows/validate-orchestrator.yml had two 'npx jest'
steps (orchestrator-plugin unit tests + orchestrator-standalone
tests). The unity-builder + orchestrator codebases are both on
vitest now. Replaced both with 'yarn vitest run'.
3. **jest-fail-on-console + src/jest.setup.ts left over.**
The earlier vitest port missed the jest-fail-on-console
integration. yarn install in CI surfaced
YN0002: doesn't provide @jest/globals (requested by
jest-fail-on-console). Removed jest-fail-on-console + jest.setup.ts;
added src/test/setup.ts with the equivalent vitest beforeEach
spies (same as unity-test-runner).
---------
Co-authored-by: frostebite <jas.f.ukcmti@gmail.com>
256 lines
10 KiB
YAML
256 lines
10 KiB
YAML
name: Validate Orchestrator Compatibility
|
|
|
|
# ==============================================================================
|
|
# Essential plugin health checks — runs on every PR and push.
|
|
# Fast (~5 min): compilation, unit tests, plugin interface, type declarations.
|
|
#
|
|
# For exhaustive integration tests (k8s, AWS, local-docker, rclone) see
|
|
# validate-orchestrator-integration.yml which runs on a daily cron.
|
|
# ==============================================================================
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
push:
|
|
branches: [main, 'release/**', 'feature/**', 'refactor/**']
|
|
paths:
|
|
- 'src/model/orchestrator-plugin.ts'
|
|
- 'src/model/build-parameters.ts'
|
|
- 'src/model/input.ts'
|
|
- 'src/model/github.ts'
|
|
- 'src/model/cli/cli.ts'
|
|
- 'src/model/input-readers/**'
|
|
- 'src/index.ts'
|
|
- 'src/types/game-ci-orchestrator.d.ts'
|
|
- 'action.yml'
|
|
- 'package.json'
|
|
- 'yarn.lock'
|
|
- '.github/workflows/validate-orchestrator.yml'
|
|
pull_request:
|
|
branches: [main, 'release/**']
|
|
paths:
|
|
- 'src/model/orchestrator-plugin.ts'
|
|
- 'src/model/build-parameters.ts'
|
|
- 'src/model/input.ts'
|
|
- 'src/model/github.ts'
|
|
- 'src/model/cli/cli.ts'
|
|
- 'src/model/input-readers/**'
|
|
- 'src/index.ts'
|
|
- 'src/types/game-ci-orchestrator.d.ts'
|
|
- 'action.yml'
|
|
- 'package.json'
|
|
- 'yarn.lock'
|
|
- '.github/workflows/validate-orchestrator.yml'
|
|
|
|
permissions:
|
|
contents: read
|
|
packages: read
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
|
|
cancel-in-progress: true
|
|
|
|
jobs:
|
|
# ============================================================================
|
|
# PLUGIN ARCHITECTURE HEALTH CHECK
|
|
# ============================================================================
|
|
# Validates that:
|
|
# 1. unity-builder compiles and its unit tests pass
|
|
# 2. Plugin loader degrades gracefully without orchestrator
|
|
# 3. Orchestrator compiles and its unit tests pass
|
|
# 4. Plugin loader loads all services when orchestrator is installed
|
|
# 5. Type declarations match actual exports
|
|
# ============================================================================
|
|
plugin-health:
|
|
name: Plugin Architecture Health
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout unity-builder
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Checkout orchestrator
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: game-ci/orchestrator
|
|
ref: ${{ github.head_ref || github.ref_name }}
|
|
path: orchestrator-standalone
|
|
continue-on-error: true
|
|
id: orchestrator-branch
|
|
|
|
- name: Fallback to orchestrator main branch
|
|
if: steps.orchestrator-branch.outcome == 'failure'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: game-ci/orchestrator
|
|
path: orchestrator-standalone
|
|
|
|
- name: Install package manager (from package.json)
|
|
run: |
|
|
corepack enable
|
|
corepack install
|
|
- uses: actions/setup-node@v4
|
|
with:
|
|
node-version: 20
|
|
- name: Resolve yarn cache folder
|
|
id: yarn-config
|
|
run: echo "cacheFolder=$(yarn config get cacheFolder)" >> "$GITHUB_OUTPUT"
|
|
- name: Restore yarn install cache (node_modules + cacheFolder + install-state)
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: |
|
|
${{ steps.yarn-config.outputs.cacheFolder }}
|
|
.yarn/install-state.gz
|
|
key: yarn-v2-${{ runner.os }}-node-20-${{ hashFiles('yarn.lock') }}
|
|
restore-keys: |
|
|
yarn-v2-${{ runner.os }}-node-20-
|
|
|
|
# --- unity-builder compilation and tests ---
|
|
- name: Install unity-builder dependencies
|
|
env:
|
|
YARN_ENABLE_HARDENED_MODE: 'false'
|
|
run: |
|
|
case "$(yarn --version)" in 1.*) echo 'expected up-to-date yarn version'; exit 1 ;; esac
|
|
yarn install --immutable
|
|
|
|
- name: Build unity-builder
|
|
run: |
|
|
echo "Building unity-builder TypeScript..."
|
|
npx tsc
|
|
echo "✓ unity-builder compiles successfully"
|
|
|
|
- name: Run orchestrator-plugin unit tests
|
|
run: |
|
|
echo "Running orchestrator-plugin unit tests..."
|
|
yarn vitest run orchestrator-plugin
|
|
|
|
# --- Plugin loader without orchestrator ---
|
|
- name: Verify plugin loader returns undefined without orchestrator
|
|
run: |
|
|
echo "Checking plugin loader handles missing @game-ci/orchestrator..."
|
|
node -e "
|
|
const { loadOrchestratorPlugin } = require('./lib/model/orchestrator-plugin');
|
|
(async () => {
|
|
const plugin = await loadOrchestratorPlugin();
|
|
if (plugin !== undefined) {
|
|
console.error('ERROR: loadOrchestratorPlugin should return undefined when package not installed');
|
|
process.exit(1);
|
|
}
|
|
console.log('✓ loadOrchestratorPlugin() returns undefined when package not installed');
|
|
})();
|
|
"
|
|
|
|
- name: Verify orchestrator type declarations exist
|
|
run: |
|
|
if [ -f "src/types/game-ci-orchestrator.d.ts" ]; then
|
|
echo "✓ Type declarations for @game-ci/orchestrator exist"
|
|
else
|
|
echo "::error::Missing type declarations: src/types/game-ci-orchestrator.d.ts"
|
|
exit 1
|
|
fi
|
|
|
|
# --- Orchestrator compilation and tests ---
|
|
- name: Build and pack orchestrator
|
|
working-directory: orchestrator-standalone
|
|
run: |
|
|
yarn install --immutable
|
|
echo "Building orchestrator..."
|
|
npx tsc
|
|
echo "✓ orchestrator compiles successfully"
|
|
echo "Packing orchestrator as tarball..."
|
|
npm pack
|
|
|
|
- name: Run orchestrator unit tests
|
|
working-directory: orchestrator-standalone
|
|
run: |
|
|
echo "Running orchestrator unit tests..."
|
|
yarn vitest run 2>&1 | tail -30
|
|
|
|
# --- Plugin loader with orchestrator installed ---
|
|
- name: Install orchestrator into unity-builder
|
|
run: |
|
|
echo "Installing orchestrator into unity-builder workspace..."
|
|
npm install ./orchestrator-standalone/game-ci-orchestrator-*.tgz --no-save --legacy-peer-deps
|
|
|
|
- name: Verify plugin loader returns exports with orchestrator installed
|
|
run: |
|
|
echo "Checking plugin loader returns defined exports..."
|
|
node -e "
|
|
const { loadOrchestratorPlugin } = require('./lib/model/orchestrator-plugin');
|
|
(async () => {
|
|
const plugin = await loadOrchestratorPlugin();
|
|
if (plugin === undefined) {
|
|
console.error('ERROR: loadOrchestratorPlugin should return defined plugin when package is installed');
|
|
process.exit(1);
|
|
}
|
|
const lifecycleMethods = [
|
|
'initialize', 'canHandleBuild', 'handleBuild',
|
|
'beforeLocalBuild', 'afterLocalBuild', 'handlePostBuild',
|
|
];
|
|
for (const method of lifecycleMethods) {
|
|
if (typeof plugin[method] !== 'function') {
|
|
console.error('ERROR: plugin.' + method + ' should be a function, got ' + typeof plugin[method]);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
console.log('✓ loadOrchestratorPlugin() returns plugin with all ' + lifecycleMethods.length + ' lifecycle methods');
|
|
})();
|
|
"
|
|
|
|
- name: Verify type declarations match orchestrator exports
|
|
run: |
|
|
echo "Checking type declarations align with orchestrator exports..."
|
|
node -e "
|
|
const orch = require('@game-ci/orchestrator');
|
|
const expectedExports = [
|
|
'Orchestrator', 'BuildReliabilityService', 'TestWorkflowService',
|
|
'HotRunnerService', 'OutputService', 'OutputTypeRegistry',
|
|
'ArtifactUploadHandler', 'IncrementalSyncService',
|
|
'ChildWorkspaceService', 'LocalCacheService', 'SubmoduleProfileService',
|
|
'LfsAgentService', 'GitHooksService',
|
|
];
|
|
const missing = expectedExports.filter(e => orch[e] === undefined);
|
|
if (missing.length > 0) {
|
|
console.error('ERROR: Missing exports from @game-ci/orchestrator:', missing.join(', '));
|
|
process.exit(1);
|
|
}
|
|
console.log('✓ All ' + expectedExports.length + ' declared exports present in orchestrator package');
|
|
"
|
|
|
|
- name: Smoke test orchestrator build wiring
|
|
run: |
|
|
echo "Verifying orchestrator build wiring end-to-end..."
|
|
node -e "
|
|
const { loadOrchestratorPlugin } = require('./lib/model/orchestrator-plugin');
|
|
|
|
(async () => {
|
|
// Verify plugin loads successfully with orchestrator installed
|
|
const plugin = await loadOrchestratorPlugin();
|
|
if (plugin === undefined) {
|
|
console.error('ERROR: plugin should be defined when orchestrator is installed');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Verify all lifecycle methods are callable
|
|
const lifecycleMethods = [
|
|
'initialize', 'canHandleBuild', 'handleBuild',
|
|
'beforeLocalBuild', 'afterLocalBuild', 'handlePostBuild',
|
|
];
|
|
for (const m of lifecycleMethods) {
|
|
if (typeof plugin[m] !== 'function') {
|
|
console.error('ERROR: plugin.' + m + ' should be a function, got ' + typeof plugin[m]);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
console.log('✓ Plugin has all ' + lifecycleMethods.length + ' lifecycle methods');
|
|
|
|
// Verify canHandleBuild returns a boolean
|
|
const canHandle = plugin.canHandleBuild();
|
|
if (typeof canHandle !== 'boolean') {
|
|
console.error('ERROR: canHandleBuild() should return a boolean, got ' + typeof canHandle);
|
|
process.exit(1);
|
|
}
|
|
console.log('✓ canHandleBuild() returns boolean');
|
|
|
|
console.log('✓ Plugin architecture wiring verified');
|
|
})();
|
|
"
|