mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-06-01 06:16:14 -07:00
Compare commits
7 Commits
feature/co
...
feature/pr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcb0894d0e | ||
|
|
90b9b0c7b0 | ||
|
|
e9c247f04f | ||
|
|
cff759721a | ||
|
|
7e9d0bf53e | ||
|
|
8194790728 | ||
|
|
786ee3799c |
203
.github/workflows/validate-community-plugins.yml
vendored
203
.github/workflows/validate-community-plugins.yml
vendored
@@ -1,203 +0,0 @@
|
|||||||
name: Validate Community Plugins
|
|
||||||
|
|
||||||
on:
|
|
||||||
schedule:
|
|
||||||
# Run weekly on Sunday at 02:00 UTC
|
|
||||||
- cron: '0 2 * * 0'
|
|
||||||
workflow_dispatch:
|
|
||||||
inputs:
|
|
||||||
plugin_filter:
|
|
||||||
description: 'Filter plugins by name (regex pattern, empty = all)'
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
unity_version:
|
|
||||||
description: 'Override Unity version (empty = use plugin default)'
|
|
||||||
required: false
|
|
||||||
default: ''
|
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
issues: write
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
load-plugins:
|
|
||||||
name: Load Plugin Registry
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
outputs:
|
|
||||||
matrix: ${{ steps.parse.outputs.matrix }}
|
|
||||||
plugin_count: ${{ steps.parse.outputs.count }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Parse plugin registry
|
|
||||||
id: parse
|
|
||||||
uses: actions/github-script@v7
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const fs = require('fs');
|
|
||||||
const yaml = require('js-yaml');
|
|
||||||
|
|
||||||
const registry = yaml.load(fs.readFileSync('community-plugins.yml', 'utf8'));
|
|
||||||
let plugins = registry.plugins || [];
|
|
||||||
|
|
||||||
// Apply name filter if provided
|
|
||||||
const filter = '${{ github.event.inputs.plugin_filter }}';
|
|
||||||
if (filter) {
|
|
||||||
const regex = new RegExp(filter, 'i');
|
|
||||||
plugins = plugins.filter(p => regex.test(p.name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expand platform matrix
|
|
||||||
const matrix = [];
|
|
||||||
for (const plugin of plugins) {
|
|
||||||
const platforms = plugin.platforms || ['StandaloneLinux64'];
|
|
||||||
for (const platform of platforms) {
|
|
||||||
matrix.push({
|
|
||||||
name: plugin.name,
|
|
||||||
package: plugin.package,
|
|
||||||
source: plugin.source || 'git',
|
|
||||||
unity: '${{ github.event.inputs.unity_version }}' || plugin.unity || '2021.3',
|
|
||||||
platform: platform,
|
|
||||||
timeout: plugin.timeout || 30
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
core.setOutput('matrix', JSON.stringify({ include: matrix }));
|
|
||||||
core.setOutput('count', matrix.length);
|
|
||||||
console.log(`Found ${matrix.length} plugin-platform combinations to validate`);
|
|
||||||
|
|
||||||
validate:
|
|
||||||
name: '${{ matrix.name }} (${{ matrix.platform }})'
|
|
||||||
needs: load-plugins
|
|
||||||
if: needs.load-plugins.outputs.plugin_count > 0
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
timeout-minutes: ${{ fromJson(matrix.timeout) }}
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix: ${{ fromJson(needs.load-plugins.outputs.matrix) }}
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Create test project
|
|
||||||
run: |
|
|
||||||
mkdir -p test-project/Assets
|
|
||||||
mkdir -p test-project/Packages
|
|
||||||
mkdir -p test-project/ProjectSettings
|
|
||||||
|
|
||||||
# Create minimal manifest.json
|
|
||||||
if [ "${{ matrix.source }}" = "git" ]; then
|
|
||||||
cat > test-project/Packages/manifest.json << 'MANIFEST'
|
|
||||||
{
|
|
||||||
"dependencies": {
|
|
||||||
"com.unity.modules.imgui": "1.0.0",
|
|
||||||
"com.unity.modules.jsonserialize": "1.0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
MANIFEST
|
|
||||||
|
|
||||||
# Add git package via manifest
|
|
||||||
cd test-project
|
|
||||||
cat Packages/manifest.json | python3 -c "
|
|
||||||
import sys, json
|
|
||||||
manifest = json.load(sys.stdin)
|
|
||||||
manifest['dependencies']['${{ matrix.name }}'] = '${{ matrix.package }}'
|
|
||||||
json.dump(manifest, sys.stdout, indent=2)
|
|
||||||
" > Packages/manifest.tmp && mv Packages/manifest.tmp Packages/manifest.json
|
|
||||||
cd ..
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create minimal ProjectSettings
|
|
||||||
cat > test-project/ProjectSettings/ProjectVersion.txt << EOF
|
|
||||||
m_EditorVersion: ${{ matrix.unity }}
|
|
||||||
EOF
|
|
||||||
|
|
||||||
- name: Build with unity-builder
|
|
||||||
uses: ./
|
|
||||||
id: build
|
|
||||||
with:
|
|
||||||
projectPath: test-project
|
|
||||||
targetPlatform: ${{ matrix.platform }}
|
|
||||||
unityVersion: ${{ matrix.unity }}
|
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Record result
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
STATUS="${{ steps.build.outcome }}"
|
|
||||||
echo "## ${{ matrix.name }} — ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "" >> $GITHUB_STEP_SUMMARY
|
|
||||||
if [ "$STATUS" = "success" ]; then
|
|
||||||
echo "✅ **PASSED** — Compiled and built successfully" >> $GITHUB_STEP_SUMMARY
|
|
||||||
else
|
|
||||||
echo "❌ **FAILED** — Build or compilation failed" >> $GITHUB_STEP_SUMMARY
|
|
||||||
fi
|
|
||||||
echo "" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- Unity: ${{ matrix.unity }}" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- Platform: ${{ matrix.platform }}" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- Source: ${{ matrix.source }}" >> $GITHUB_STEP_SUMMARY
|
|
||||||
echo "- Package: \`${{ matrix.package }}\`" >> $GITHUB_STEP_SUMMARY
|
|
||||||
|
|
||||||
report:
|
|
||||||
name: Validation Report
|
|
||||||
needs: [load-plugins, validate]
|
|
||||||
if: always()
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Generate summary
|
|
||||||
uses: actions/github-script@v7
|
|
||||||
with:
|
|
||||||
script: |
|
|
||||||
const { data: run } = await github.rest.actions.listJobsForWorkflowRun({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
run_id: context.runId
|
|
||||||
});
|
|
||||||
|
|
||||||
const validateJobs = run.jobs.filter(j => j.name.startsWith('validate'));
|
|
||||||
const passed = validateJobs.filter(j => j.conclusion === 'success').length;
|
|
||||||
const failed = validateJobs.filter(j => j.conclusion === 'failure').length;
|
|
||||||
const total = validateJobs.length;
|
|
||||||
|
|
||||||
let summary = `# Community Plugin Validation Report\n\n`;
|
|
||||||
summary += `**${passed}/${total} passed** | ${failed} failed\n\n`;
|
|
||||||
summary += `| Plugin | Platform | Status |\n|--------|----------|--------|\n`;
|
|
||||||
|
|
||||||
for (const job of validateJobs) {
|
|
||||||
const icon = job.conclusion === 'success' ? '✅' : '❌';
|
|
||||||
summary += `| ${job.name} | | ${icon} ${job.conclusion} |\n`;
|
|
||||||
}
|
|
||||||
|
|
||||||
await core.summary.addRaw(summary).write();
|
|
||||||
|
|
||||||
// Create or update issue if there are failures
|
|
||||||
if (failed > 0) {
|
|
||||||
const title = `Community Plugin Validation: ${failed} failure(s) — ${new Date().toISOString().split('T')[0]}`;
|
|
||||||
const body = summary + `\n\n[Workflow Run](${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId})`;
|
|
||||||
|
|
||||||
const { data: issues } = await github.rest.issues.listForRepo({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
state: 'open',
|
|
||||||
labels: 'community-plugin-validation'
|
|
||||||
});
|
|
||||||
|
|
||||||
if (issues.length > 0) {
|
|
||||||
await github.rest.issues.createComment({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: issues[0].number,
|
|
||||||
body: body
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await github.rest.issues.create({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
title: title,
|
|
||||||
body: body,
|
|
||||||
labels: ['community-plugin-validation']
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
36
action.yml
36
action.yml
@@ -194,6 +194,42 @@ inputs:
|
|||||||
description:
|
description:
|
||||||
'[Orchestrator] Either local, k8s or aws can be used to run builds on a remote cluster. Additional parameters must
|
'[Orchestrator] Either local, k8s or aws can be used to run builds on a remote cluster. Additional parameters must
|
||||||
be configured.'
|
be configured.'
|
||||||
|
fallbackProviderStrategy:
|
||||||
|
default: ''
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] Fallback provider when the primary is unavailable. Used with runnerCheckEnabled for automatic
|
||||||
|
failover, or as a catch-all if the primary provider fails to initialize.'
|
||||||
|
runnerCheckEnabled:
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] Check GitHub Actions runner availability before starting a build. When no suitable runners are
|
||||||
|
available and fallbackProviderStrategy is set, automatically routes to the fallback provider.'
|
||||||
|
runnerCheckLabels:
|
||||||
|
default: ''
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] Comma-separated runner labels to filter when checking availability (e.g. self-hosted,linux).
|
||||||
|
When empty, checks all runners in the repository.'
|
||||||
|
runnerCheckMinAvailable:
|
||||||
|
default: '1'
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] Minimum number of idle runners required for the primary provider. If fewer are available,
|
||||||
|
routes to fallbackProviderStrategy.'
|
||||||
|
retryOnFallback:
|
||||||
|
default: 'false'
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] When true and fallbackProviderStrategy is set, automatically retry the build on the fallback
|
||||||
|
provider if the primary provider fails. Useful for long builds where transient cloud failures are common.'
|
||||||
|
providerInitTimeout:
|
||||||
|
default: '0'
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
'[Orchestrator] Maximum seconds to wait for the primary provider to initialize (setupWorkflow). If exceeded
|
||||||
|
and fallbackProviderStrategy is set, switches to the fallback. Set to 0 to disable (default).'
|
||||||
resourceTracking:
|
resourceTracking:
|
||||||
default: 'false'
|
default: 'false'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
# Community Plugin Validation Registry
|
|
||||||
# Packages listed here are automatically tested on a schedule
|
|
||||||
# to ensure compatibility with unity-builder.
|
|
||||||
#
|
|
||||||
# Format:
|
|
||||||
# - name: Human-readable name
|
|
||||||
# package: UPM package name or git URL
|
|
||||||
# source: upm | git | asset-store
|
|
||||||
# unity: Minimum Unity version (optional, defaults to 2021.3)
|
|
||||||
# platforms: List of platforms to test (optional, defaults to [StandaloneLinux64])
|
|
||||||
# timeout: Build timeout in minutes (optional, defaults to 30)
|
|
||||||
|
|
||||||
plugins:
|
|
||||||
# Example entries — community members can submit PRs to add their packages
|
|
||||||
- name: UniTask
|
|
||||||
package: https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask
|
|
||||||
source: git
|
|
||||||
platforms: [StandaloneLinux64, StandaloneWindows64]
|
|
||||||
|
|
||||||
- name: NaughtyAttributes
|
|
||||||
package: https://github.com/dbrizov/NaughtyAttributes.git?path=Assets/NaughtyAttributes
|
|
||||||
source: git
|
|
||||||
|
|
||||||
- name: Unity Atoms
|
|
||||||
package: https://github.com/unity-atoms/unity-atoms.git
|
|
||||||
source: git
|
|
||||||
platforms: [StandaloneLinux64]
|
|
||||||
256
dist/index.js
generated
vendored
256
dist/index.js
generated
vendored
@@ -327,6 +327,12 @@ class BuildParameters {
|
|||||||
containerRegistryRepository: input_1.default.containerRegistryRepository,
|
containerRegistryRepository: input_1.default.containerRegistryRepository,
|
||||||
containerRegistryImageVersion: input_1.default.containerRegistryImageVersion,
|
containerRegistryImageVersion: input_1.default.containerRegistryImageVersion,
|
||||||
providerStrategy: orchestrator_options_1.default.providerStrategy,
|
providerStrategy: orchestrator_options_1.default.providerStrategy,
|
||||||
|
fallbackProviderStrategy: orchestrator_options_1.default.fallbackProviderStrategy,
|
||||||
|
runnerCheckEnabled: orchestrator_options_1.default.runnerCheckEnabled,
|
||||||
|
runnerCheckLabels: orchestrator_options_1.default.runnerCheckLabels,
|
||||||
|
runnerCheckMinAvailable: orchestrator_options_1.default.runnerCheckMinAvailable,
|
||||||
|
retryOnFallback: orchestrator_options_1.default.retryOnFallback,
|
||||||
|
providerInitTimeout: orchestrator_options_1.default.providerInitTimeout,
|
||||||
buildPlatform: orchestrator_options_1.default.buildPlatform,
|
buildPlatform: orchestrator_options_1.default.buildPlatform,
|
||||||
kubeConfig: orchestrator_options_1.default.kubeConfig,
|
kubeConfig: orchestrator_options_1.default.kubeConfig,
|
||||||
containerMemory: orchestrator_options_1.default.containerMemory,
|
containerMemory: orchestrator_options_1.default.containerMemory,
|
||||||
@@ -2204,6 +2210,25 @@ class OrchestratorOptions {
|
|||||||
}
|
}
|
||||||
return provider || 'local';
|
return provider || 'local';
|
||||||
}
|
}
|
||||||
|
static get fallbackProviderStrategy() {
|
||||||
|
return OrchestratorOptions.getInput('fallbackProviderStrategy') || '';
|
||||||
|
}
|
||||||
|
static get runnerCheckEnabled() {
|
||||||
|
return OrchestratorOptions.getInput('runnerCheckEnabled') === 'true';
|
||||||
|
}
|
||||||
|
static get runnerCheckLabels() {
|
||||||
|
const labels = OrchestratorOptions.getInput('runnerCheckLabels');
|
||||||
|
return labels ? labels.split(',').map((l) => l.trim()) : [];
|
||||||
|
}
|
||||||
|
static get runnerCheckMinAvailable() {
|
||||||
|
return Number(OrchestratorOptions.getInput('runnerCheckMinAvailable')) || 1;
|
||||||
|
}
|
||||||
|
static get retryOnFallback() {
|
||||||
|
return OrchestratorOptions.getInput('retryOnFallback') === 'true';
|
||||||
|
}
|
||||||
|
static get providerInitTimeout() {
|
||||||
|
return Number(OrchestratorOptions.getInput('providerInitTimeout')) || 0;
|
||||||
|
}
|
||||||
static get containerCpu() {
|
static get containerCpu() {
|
||||||
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
||||||
}
|
}
|
||||||
@@ -2508,6 +2533,7 @@ const follow_log_stream_service_1 = __nccwpck_require__(36149);
|
|||||||
const orchestrator_result_1 = __importDefault(__nccwpck_require__(86819));
|
const orchestrator_result_1 = __importDefault(__nccwpck_require__(86819));
|
||||||
const orchestrator_options_1 = __importDefault(__nccwpck_require__(82473));
|
const orchestrator_options_1 = __importDefault(__nccwpck_require__(82473));
|
||||||
const resource_tracking_1 = __importDefault(__nccwpck_require__(42604));
|
const resource_tracking_1 = __importDefault(__nccwpck_require__(42604));
|
||||||
|
const runner_availability_service_1 = __nccwpck_require__(18876);
|
||||||
class Orchestrator {
|
class Orchestrator {
|
||||||
static get isOrchestratorEnvironment() {
|
static get isOrchestratorEnvironment() {
|
||||||
return process.env[`GITHUB_ACTIONS`] !== `true`;
|
return process.env[`GITHUB_ACTIONS`] !== `true`;
|
||||||
@@ -2544,6 +2570,26 @@ class Orchestrator {
|
|||||||
}
|
}
|
||||||
static async setupSelectedBuildPlatform() {
|
static async setupSelectedBuildPlatform() {
|
||||||
orchestrator_logger_1.default.log(`Orchestrator platform selected ${Orchestrator.buildParameters.providerStrategy}`);
|
orchestrator_logger_1.default.log(`Orchestrator platform selected ${Orchestrator.buildParameters.providerStrategy}`);
|
||||||
|
// Check runner availability and apply fallback if needed
|
||||||
|
if (Orchestrator.buildParameters.runnerCheckEnabled && Orchestrator.buildParameters.fallbackProviderStrategy) {
|
||||||
|
const owner = orchestrator_options_1.default.githubOwner;
|
||||||
|
const repo = orchestrator_options_1.default.githubRepoName;
|
||||||
|
const token = Orchestrator.buildParameters.gitPrivateToken || process.env.GITHUB_TOKEN || '';
|
||||||
|
orchestrator_logger_1.default.log(`Checking runner availability (labels: [${Orchestrator.buildParameters.runnerCheckLabels.join(', ')}], min: ${Orchestrator.buildParameters.runnerCheckMinAvailable})`);
|
||||||
|
const result = await runner_availability_service_1.RunnerAvailabilityService.checkAvailability(owner, repo, token, Orchestrator.buildParameters.runnerCheckLabels, Orchestrator.buildParameters.runnerCheckMinAvailable);
|
||||||
|
orchestrator_logger_1.default.log(`Runner check: ${result.totalRunners} total, ${result.matchingRunners} matching, ${result.idleRunners} idle — ${result.reason}`);
|
||||||
|
if (result.shouldFallback) {
|
||||||
|
const original = Orchestrator.buildParameters.providerStrategy;
|
||||||
|
const fallback = Orchestrator.buildParameters.fallbackProviderStrategy;
|
||||||
|
orchestrator_logger_1.default.log(`Falling back from '${original}' to '${fallback}' — ${result.reason}`);
|
||||||
|
Orchestrator.buildParameters.providerStrategy = fallback;
|
||||||
|
core.setOutput('providerFallbackUsed', 'true');
|
||||||
|
core.setOutput('providerFallbackReason', result.reason);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.setOutput('providerFallbackUsed', 'false');
|
||||||
|
}
|
||||||
|
}
|
||||||
// Detect LocalStack endpoints and handle AWS provider appropriately
|
// Detect LocalStack endpoints and handle AWS provider appropriately
|
||||||
// AWS_FORCE_PROVIDER options:
|
// AWS_FORCE_PROVIDER options:
|
||||||
// - 'aws': Force AWS provider (requires LocalStack Pro with ECS support)
|
// - 'aws': Force AWS provider (requires LocalStack Pro with ECS support)
|
||||||
@@ -2642,13 +2688,33 @@ class Orchestrator {
|
|||||||
if (baseImage.includes(`undefined`)) {
|
if (baseImage.includes(`undefined`)) {
|
||||||
throw new Error(`baseImage is undefined`);
|
throw new Error(`baseImage is undefined`);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
return await Orchestrator.runWithProvider(buildParameters, baseImage);
|
||||||
|
}
|
||||||
|
catch (primaryError) {
|
||||||
|
// Retry on fallback provider if enabled and a fallback is configured
|
||||||
|
const fallback = buildParameters.fallbackProviderStrategy;
|
||||||
|
const alreadyOnFallback = buildParameters.providerStrategy === fallback;
|
||||||
|
if (buildParameters.retryOnFallback && fallback && !alreadyOnFallback) {
|
||||||
|
orchestrator_logger_1.default.log(`Primary provider '${buildParameters.providerStrategy}' failed: ${primaryError.message}`);
|
||||||
|
orchestrator_logger_1.default.log(`Retrying build on fallback provider '${fallback}'...`);
|
||||||
|
buildParameters.providerStrategy = fallback;
|
||||||
|
core.setOutput('providerFallbackUsed', 'true');
|
||||||
|
core.setOutput('providerFallbackReason', `Primary provider failed: ${primaryError.message}`);
|
||||||
|
return await Orchestrator.runWithProvider(buildParameters, baseImage);
|
||||||
|
}
|
||||||
|
throw primaryError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static async runWithProvider(buildParameters, baseImage) {
|
||||||
await Orchestrator.setup(buildParameters);
|
await Orchestrator.setup(buildParameters);
|
||||||
// When aws-local mode is enabled, validate AWS CloudFormation templates
|
// When aws-local mode is enabled, validate AWS CloudFormation templates
|
||||||
// This ensures AWS templates are correct even when executing via local-docker
|
// This ensures AWS templates are correct even when executing via local-docker
|
||||||
if (Orchestrator.validateAwsTemplates) {
|
if (Orchestrator.validateAwsTemplates) {
|
||||||
await Orchestrator.validateAwsCloudFormationTemplates();
|
await Orchestrator.validateAwsCloudFormationTemplates();
|
||||||
}
|
}
|
||||||
await Orchestrator.Provider.setupWorkflow(Orchestrator.buildParameters.buildGuid, Orchestrator.buildParameters, Orchestrator.buildParameters.branch, Orchestrator.defaultSecrets);
|
// Setup workflow with optional init timeout
|
||||||
|
await Orchestrator.setupWorkflowWithTimeout();
|
||||||
try {
|
try {
|
||||||
if (buildParameters.maxRetainedWorkspaces > 0) {
|
if (buildParameters.maxRetainedWorkspaces > 0) {
|
||||||
Orchestrator.lockedWorkspace = shared_workspace_locking_1.default.NewWorkspaceName();
|
Orchestrator.lockedWorkspace = shared_workspace_locking_1.default.NewWorkspaceName();
|
||||||
@@ -2698,6 +2764,24 @@ class Orchestrator {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Runs setupWorkflow with an optional timeout. If providerInitTimeout is set and the
|
||||||
|
* provider takes longer than that to initialize, throws an error that triggers
|
||||||
|
* retry-on-fallback (if enabled).
|
||||||
|
*/
|
||||||
|
static async setupWorkflowWithTimeout() {
|
||||||
|
const timeoutSeconds = Orchestrator.buildParameters.providerInitTimeout;
|
||||||
|
const setupPromise = Orchestrator.Provider.setupWorkflow(Orchestrator.buildParameters.buildGuid, Orchestrator.buildParameters, Orchestrator.buildParameters.branch, Orchestrator.defaultSecrets);
|
||||||
|
if (timeoutSeconds <= 0) {
|
||||||
|
await setupPromise;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
orchestrator_logger_1.default.log(`Provider init timeout: ${timeoutSeconds}s`);
|
||||||
|
const timeoutPromise = new Promise((_, reject) => {
|
||||||
|
setTimeout(() => reject(new Error(`Provider initialization timed out after ${timeoutSeconds}s`)), timeoutSeconds * 1000);
|
||||||
|
});
|
||||||
|
await Promise.race([setupPromise, timeoutPromise]);
|
||||||
|
}
|
||||||
static async updateStatusWithBuildParameters() {
|
static async updateStatusWithBuildParameters() {
|
||||||
const content = { ...Orchestrator.buildParameters };
|
const content = { ...Orchestrator.buildParameters };
|
||||||
content.gitPrivateToken = ``;
|
content.gitPrivateToken = ``;
|
||||||
@@ -8639,6 +8723,176 @@ class ResourceTracking {
|
|||||||
exports["default"] = ResourceTracking;
|
exports["default"] = ResourceTracking;
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 18876:
|
||||||
|
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
|
exports.RunnerAvailabilityService = void 0;
|
||||||
|
const core_1 = __nccwpck_require__(76762);
|
||||||
|
const orchestrator_logger_1 = __importDefault(__nccwpck_require__(32549));
|
||||||
|
/**
|
||||||
|
* Maximum number of pages to fetch when paginating through GitHub API results.
|
||||||
|
* 100 pages * 100 per page = 10,000 runners maximum.
|
||||||
|
*/
|
||||||
|
const MAX_PAGINATION_PAGES = 100;
|
||||||
|
/**
|
||||||
|
* Total timeout in milliseconds for the pagination loop.
|
||||||
|
* Prevents indefinite API calls if GitHub is slow or pagination is unexpectedly deep.
|
||||||
|
*/
|
||||||
|
const PAGINATION_TIMEOUT_MS = 30000;
|
||||||
|
/**
|
||||||
|
* Checks GitHub Actions runner availability to support automatic provider fallback.
|
||||||
|
*
|
||||||
|
* When a user configures `runnerCheckEnabled: true` with a `fallbackProviderStrategy`,
|
||||||
|
* this service queries the GitHub API for runner status before the build starts.
|
||||||
|
* If insufficient runners are available, the orchestrator routes to the fallback provider.
|
||||||
|
*/
|
||||||
|
class RunnerAvailabilityService {
|
||||||
|
/**
|
||||||
|
* Check if enough runners are available to handle the build.
|
||||||
|
*
|
||||||
|
* @param owner - GitHub repository owner
|
||||||
|
* @param repo - GitHub repository name
|
||||||
|
* @param token - GitHub token with repo/actions scope
|
||||||
|
* @param requiredLabels - Labels runners must have (empty = any runner)
|
||||||
|
* @param minAvailable - Minimum idle runners required
|
||||||
|
* @returns RunnerCheckResult with decision and diagnostics
|
||||||
|
*/
|
||||||
|
static async checkAvailability(owner, repo, token, requiredLabels, minAvailable) {
|
||||||
|
if (!token) {
|
||||||
|
return {
|
||||||
|
shouldFallback: false,
|
||||||
|
reason: 'No GitHub token available — skipping runner check',
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const octokit = new core_1.Octokit({ auth: token });
|
||||||
|
// Fetch all runners for the repository
|
||||||
|
const runners = await RunnerAvailabilityService.fetchRunners(octokit, owner, repo);
|
||||||
|
if (runners.length === 0) {
|
||||||
|
return {
|
||||||
|
shouldFallback: true,
|
||||||
|
reason: 'No runners registered for this repository',
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// Filter by required labels
|
||||||
|
const matching = RunnerAvailabilityService.filterByLabels(runners, requiredLabels);
|
||||||
|
// Count idle (online + not busy)
|
||||||
|
const idle = matching.filter((r) => r.status === 'online' && !r.busy);
|
||||||
|
const result = {
|
||||||
|
shouldFallback: idle.length < minAvailable,
|
||||||
|
reason: idle.length >= minAvailable
|
||||||
|
? `${idle.length} idle runner(s) available (need ${minAvailable})`
|
||||||
|
: `Only ${idle.length} idle runner(s) available, need ${minAvailable}`,
|
||||||
|
totalRunners: runners.length,
|
||||||
|
matchingRunners: matching.length,
|
||||||
|
idleRunners: idle.length,
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
// If the API call fails (permissions, rate limit, etc.), don't block the build
|
||||||
|
orchestrator_logger_1.default.log(`Runner availability check failed: ${error.message}`);
|
||||||
|
return {
|
||||||
|
shouldFallback: false,
|
||||||
|
reason: `Runner check failed (${error.message}) — proceeding with primary provider`,
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Fetch all runners for a repository, handling pagination.
|
||||||
|
*
|
||||||
|
* Includes defensive limits:
|
||||||
|
* - Maximum page count (MAX_PAGINATION_PAGES) to prevent infinite loops
|
||||||
|
* - Total timeout (PAGINATION_TIMEOUT_MS) to prevent indefinite API calls
|
||||||
|
* - Rate-limit detection (HTTP 403/429 with X-RateLimit-Remaining header)
|
||||||
|
*/
|
||||||
|
static async fetchRunners(octokit, owner, repo) {
|
||||||
|
const allRunners = [];
|
||||||
|
let page = 1;
|
||||||
|
const perPage = 100;
|
||||||
|
const startTime = Date.now();
|
||||||
|
while (page <= MAX_PAGINATION_PAGES) {
|
||||||
|
// Check total timeout
|
||||||
|
if (Date.now() - startTime > PAGINATION_TIMEOUT_MS) {
|
||||||
|
orchestrator_logger_1.default.logWarning(`[RunnerAvailability] Pagination timeout reached after ${page - 1} pages and ${Date.now() - startTime}ms. ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
let response;
|
||||||
|
try {
|
||||||
|
response = await octokit.request('GET /repos/{owner}/{repo}/actions/runners', {
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
per_page: perPage,
|
||||||
|
page,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (requestError) {
|
||||||
|
// Octokit throws for non-2xx responses. Check if this is a rate limit error.
|
||||||
|
const status = requestError.status ?? requestError.response?.status;
|
||||||
|
if (status === 403 || status === 429) {
|
||||||
|
const resetTime = requestError.response?.headers?.['x-ratelimit-reset'] ?? requestError.headers?.['x-ratelimit-reset'];
|
||||||
|
const resetMessage = resetTime
|
||||||
|
? ` Resets at ${new Date(Number.parseInt(String(resetTime), 10) * 1000).toISOString()}`
|
||||||
|
: '';
|
||||||
|
orchestrator_logger_1.default.logWarning(`[RunnerAvailability] GitHub API rate limit reached (HTTP ${status}).${resetMessage} ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Re-throw non-rate-limit errors to be handled by the outer catch
|
||||||
|
throw requestError;
|
||||||
|
}
|
||||||
|
const runners = (response.data.runners || []);
|
||||||
|
allRunners.push(...runners);
|
||||||
|
if (runners.length < perPage)
|
||||||
|
break;
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
if (page > MAX_PAGINATION_PAGES) {
|
||||||
|
orchestrator_logger_1.default.logWarning(`[RunnerAvailability] Maximum pagination limit reached (${MAX_PAGINATION_PAGES} pages). ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`);
|
||||||
|
}
|
||||||
|
if (allRunners.length === 0) {
|
||||||
|
orchestrator_logger_1.default.log('[RunnerAvailability] No runners found. Possible causes: ' +
|
||||||
|
'wrong token permissions (needs repo or actions scope), ' +
|
||||||
|
'no self-hosted runners registered, ' +
|
||||||
|
'or runners are registered at the organization level instead of the repository.');
|
||||||
|
}
|
||||||
|
return allRunners;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Filter runners by required labels. A runner matches if it has ALL required labels.
|
||||||
|
* If requiredLabels is empty, all runners match.
|
||||||
|
*/
|
||||||
|
static filterByLabels(runners, requiredLabels) {
|
||||||
|
if (requiredLabels.length === 0)
|
||||||
|
return runners;
|
||||||
|
return runners.filter((runner) => {
|
||||||
|
const runnerLabelNames = runner.labels.map((l) => l.name.toLowerCase());
|
||||||
|
return requiredLabels.every((required) => runnerLabelNames.includes(required.toLowerCase()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.RunnerAvailabilityService = RunnerAvailabilityService;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 54222:
|
/***/ 54222:
|
||||||
|
|||||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@@ -54,6 +54,12 @@ class BuildParameters {
|
|||||||
public sshAgent!: string;
|
public sshAgent!: string;
|
||||||
public sshPublicKeysDirectoryPath!: string;
|
public sshPublicKeysDirectoryPath!: string;
|
||||||
public providerStrategy!: string;
|
public providerStrategy!: string;
|
||||||
|
public fallbackProviderStrategy!: string;
|
||||||
|
public runnerCheckEnabled!: boolean;
|
||||||
|
public runnerCheckLabels!: string[];
|
||||||
|
public runnerCheckMinAvailable!: number;
|
||||||
|
public retryOnFallback!: boolean;
|
||||||
|
public providerInitTimeout!: number;
|
||||||
public gitPrivateToken!: string;
|
public gitPrivateToken!: string;
|
||||||
public awsStackName!: string;
|
public awsStackName!: string;
|
||||||
public awsEndpoint?: string;
|
public awsEndpoint?: string;
|
||||||
@@ -194,6 +200,12 @@ class BuildParameters {
|
|||||||
containerRegistryRepository: Input.containerRegistryRepository,
|
containerRegistryRepository: Input.containerRegistryRepository,
|
||||||
containerRegistryImageVersion: Input.containerRegistryImageVersion,
|
containerRegistryImageVersion: Input.containerRegistryImageVersion,
|
||||||
providerStrategy: OrchestratorOptions.providerStrategy,
|
providerStrategy: OrchestratorOptions.providerStrategy,
|
||||||
|
fallbackProviderStrategy: OrchestratorOptions.fallbackProviderStrategy,
|
||||||
|
runnerCheckEnabled: OrchestratorOptions.runnerCheckEnabled,
|
||||||
|
runnerCheckLabels: OrchestratorOptions.runnerCheckLabels,
|
||||||
|
runnerCheckMinAvailable: OrchestratorOptions.runnerCheckMinAvailable,
|
||||||
|
retryOnFallback: OrchestratorOptions.retryOnFallback,
|
||||||
|
providerInitTimeout: OrchestratorOptions.providerInitTimeout,
|
||||||
buildPlatform: OrchestratorOptions.buildPlatform,
|
buildPlatform: OrchestratorOptions.buildPlatform,
|
||||||
kubeConfig: OrchestratorOptions.kubeConfig,
|
kubeConfig: OrchestratorOptions.kubeConfig,
|
||||||
containerMemory: OrchestratorOptions.containerMemory,
|
containerMemory: OrchestratorOptions.containerMemory,
|
||||||
|
|||||||
@@ -138,6 +138,32 @@ class OrchestratorOptions {
|
|||||||
return provider || 'local';
|
return provider || 'local';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get fallbackProviderStrategy(): string {
|
||||||
|
return OrchestratorOptions.getInput('fallbackProviderStrategy') || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get runnerCheckEnabled(): boolean {
|
||||||
|
return OrchestratorOptions.getInput('runnerCheckEnabled') === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get runnerCheckLabels(): string[] {
|
||||||
|
const labels = OrchestratorOptions.getInput('runnerCheckLabels');
|
||||||
|
|
||||||
|
return labels ? labels.split(',').map((l) => l.trim()) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get runnerCheckMinAvailable(): number {
|
||||||
|
return Number(OrchestratorOptions.getInput('runnerCheckMinAvailable')) || 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get retryOnFallback(): boolean {
|
||||||
|
return OrchestratorOptions.getInput('retryOnFallback') === 'true';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get providerInitTimeout(): number {
|
||||||
|
return Number(OrchestratorOptions.getInput('providerInitTimeout')) || 0;
|
||||||
|
}
|
||||||
|
|
||||||
static get containerCpu(): string {
|
static get containerCpu(): string {
|
||||||
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
return OrchestratorOptions.getInput('containerCpu') || `1024`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import { FollowLogStreamService } from './services/core/follow-log-stream-servic
|
|||||||
import OrchestratorResult from './services/core/orchestrator-result';
|
import OrchestratorResult from './services/core/orchestrator-result';
|
||||||
import OrchestratorOptions from './options/orchestrator-options';
|
import OrchestratorOptions from './options/orchestrator-options';
|
||||||
import ResourceTracking from './services/core/resource-tracking';
|
import ResourceTracking from './services/core/resource-tracking';
|
||||||
|
import { RunnerAvailabilityService } from './services/core/runner-availability-service';
|
||||||
|
|
||||||
class Orchestrator {
|
class Orchestrator {
|
||||||
public static Provider: ProviderInterface;
|
public static Provider: ProviderInterface;
|
||||||
@@ -76,6 +77,42 @@ class Orchestrator {
|
|||||||
private static async setupSelectedBuildPlatform() {
|
private static async setupSelectedBuildPlatform() {
|
||||||
OrchestratorLogger.log(`Orchestrator platform selected ${Orchestrator.buildParameters.providerStrategy}`);
|
OrchestratorLogger.log(`Orchestrator platform selected ${Orchestrator.buildParameters.providerStrategy}`);
|
||||||
|
|
||||||
|
// Check runner availability and apply fallback if needed
|
||||||
|
if (Orchestrator.buildParameters.runnerCheckEnabled && Orchestrator.buildParameters.fallbackProviderStrategy) {
|
||||||
|
const owner = OrchestratorOptions.githubOwner;
|
||||||
|
const repo = OrchestratorOptions.githubRepoName;
|
||||||
|
const token = Orchestrator.buildParameters.gitPrivateToken || process.env.GITHUB_TOKEN || '';
|
||||||
|
|
||||||
|
OrchestratorLogger.log(
|
||||||
|
`Checking runner availability (labels: [${Orchestrator.buildParameters.runnerCheckLabels.join(', ')}], min: ${
|
||||||
|
Orchestrator.buildParameters.runnerCheckMinAvailable
|
||||||
|
})`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability(
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
token,
|
||||||
|
Orchestrator.buildParameters.runnerCheckLabels,
|
||||||
|
Orchestrator.buildParameters.runnerCheckMinAvailable,
|
||||||
|
);
|
||||||
|
|
||||||
|
OrchestratorLogger.log(
|
||||||
|
`Runner check: ${result.totalRunners} total, ${result.matchingRunners} matching, ${result.idleRunners} idle — ${result.reason}`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.shouldFallback) {
|
||||||
|
const original = Orchestrator.buildParameters.providerStrategy;
|
||||||
|
const fallback = Orchestrator.buildParameters.fallbackProviderStrategy;
|
||||||
|
OrchestratorLogger.log(`Falling back from '${original}' to '${fallback}' — ${result.reason}`);
|
||||||
|
Orchestrator.buildParameters.providerStrategy = fallback;
|
||||||
|
core.setOutput('providerFallbackUsed', 'true');
|
||||||
|
core.setOutput('providerFallbackReason', result.reason);
|
||||||
|
} else {
|
||||||
|
core.setOutput('providerFallbackUsed', 'false');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Detect LocalStack endpoints and handle AWS provider appropriately
|
// Detect LocalStack endpoints and handle AWS provider appropriately
|
||||||
// AWS_FORCE_PROVIDER options:
|
// AWS_FORCE_PROVIDER options:
|
||||||
// - 'aws': Force AWS provider (requires LocalStack Pro with ECS support)
|
// - 'aws': Force AWS provider (requires LocalStack Pro with ECS support)
|
||||||
@@ -182,6 +219,30 @@ class Orchestrator {
|
|||||||
if (baseImage.includes(`undefined`)) {
|
if (baseImage.includes(`undefined`)) {
|
||||||
throw new Error(`baseImage is undefined`);
|
throw new Error(`baseImage is undefined`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await Orchestrator.runWithProvider(buildParameters, baseImage);
|
||||||
|
} catch (primaryError: any) {
|
||||||
|
// Retry on fallback provider if enabled and a fallback is configured
|
||||||
|
const fallback = buildParameters.fallbackProviderStrategy;
|
||||||
|
const alreadyOnFallback = buildParameters.providerStrategy === fallback;
|
||||||
|
if (buildParameters.retryOnFallback && fallback && !alreadyOnFallback) {
|
||||||
|
OrchestratorLogger.log(
|
||||||
|
`Primary provider '${buildParameters.providerStrategy}' failed: ${primaryError.message}`,
|
||||||
|
);
|
||||||
|
OrchestratorLogger.log(`Retrying build on fallback provider '${fallback}'...`);
|
||||||
|
buildParameters.providerStrategy = fallback;
|
||||||
|
core.setOutput('providerFallbackUsed', 'true');
|
||||||
|
core.setOutput('providerFallbackReason', `Primary provider failed: ${primaryError.message}`);
|
||||||
|
|
||||||
|
return await Orchestrator.runWithProvider(buildParameters, baseImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw primaryError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async runWithProvider(buildParameters: BuildParameters, baseImage: string) {
|
||||||
await Orchestrator.setup(buildParameters);
|
await Orchestrator.setup(buildParameters);
|
||||||
|
|
||||||
// When aws-local mode is enabled, validate AWS CloudFormation templates
|
// When aws-local mode is enabled, validate AWS CloudFormation templates
|
||||||
@@ -189,12 +250,10 @@ class Orchestrator {
|
|||||||
if (Orchestrator.validateAwsTemplates) {
|
if (Orchestrator.validateAwsTemplates) {
|
||||||
await Orchestrator.validateAwsCloudFormationTemplates();
|
await Orchestrator.validateAwsCloudFormationTemplates();
|
||||||
}
|
}
|
||||||
await Orchestrator.Provider.setupWorkflow(
|
|
||||||
Orchestrator.buildParameters.buildGuid,
|
// Setup workflow with optional init timeout
|
||||||
Orchestrator.buildParameters,
|
await Orchestrator.setupWorkflowWithTimeout();
|
||||||
Orchestrator.buildParameters.branch,
|
|
||||||
Orchestrator.defaultSecrets,
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
if (buildParameters.maxRetainedWorkspaces > 0) {
|
if (buildParameters.maxRetainedWorkspaces > 0) {
|
||||||
Orchestrator.lockedWorkspace = SharedWorkspaceLocking.NewWorkspaceName();
|
Orchestrator.lockedWorkspace = SharedWorkspaceLocking.NewWorkspaceName();
|
||||||
@@ -275,6 +334,39 @@ class Orchestrator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Runs setupWorkflow with an optional timeout. If providerInitTimeout is set and the
|
||||||
|
* provider takes longer than that to initialize, throws an error that triggers
|
||||||
|
* retry-on-fallback (if enabled).
|
||||||
|
*/
|
||||||
|
private static async setupWorkflowWithTimeout() {
|
||||||
|
const timeoutSeconds = Orchestrator.buildParameters.providerInitTimeout;
|
||||||
|
|
||||||
|
const setupPromise = Orchestrator.Provider.setupWorkflow(
|
||||||
|
Orchestrator.buildParameters.buildGuid,
|
||||||
|
Orchestrator.buildParameters,
|
||||||
|
Orchestrator.buildParameters.branch,
|
||||||
|
Orchestrator.defaultSecrets,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (timeoutSeconds <= 0) {
|
||||||
|
await setupPromise;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
OrchestratorLogger.log(`Provider init timeout: ${timeoutSeconds}s`);
|
||||||
|
|
||||||
|
const timeoutPromise = new Promise<never>((_, reject) => {
|
||||||
|
setTimeout(
|
||||||
|
() => reject(new Error(`Provider initialization timed out after ${timeoutSeconds}s`)),
|
||||||
|
timeoutSeconds * 1000,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.race([setupPromise, timeoutPromise]);
|
||||||
|
}
|
||||||
|
|
||||||
private static async updateStatusWithBuildParameters() {
|
private static async updateStatusWithBuildParameters() {
|
||||||
const content = { ...Orchestrator.buildParameters };
|
const content = { ...Orchestrator.buildParameters };
|
||||||
content.gitPrivateToken = ``;
|
content.gitPrivateToken = ``;
|
||||||
|
|||||||
@@ -0,0 +1,318 @@
|
|||||||
|
import { RunnerAvailabilityService } from './runner-availability-service';
|
||||||
|
|
||||||
|
// Mock @octokit/core
|
||||||
|
jest.mock('@octokit/core', () => ({
|
||||||
|
Octokit: jest.fn().mockImplementation(() => ({
|
||||||
|
request: jest.fn(),
|
||||||
|
})),
|
||||||
|
}));
|
||||||
|
|
||||||
|
jest.mock('./orchestrator-logger', () => ({
|
||||||
|
__esModule: true,
|
||||||
|
default: {
|
||||||
|
log: jest.fn(),
|
||||||
|
logWarning: jest.fn(),
|
||||||
|
error: jest.fn(),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
import { Octokit } from '@octokit/core';
|
||||||
|
|
||||||
|
const MockedOctokit = Octokit as jest.MockedClass<typeof Octokit>;
|
||||||
|
|
||||||
|
function createMockRunners(runners: Array<{ name: string; status: string; busy: boolean; labels: string[] }>) {
|
||||||
|
return runners.map((r, i) => ({
|
||||||
|
id: i + 1,
|
||||||
|
name: r.name,
|
||||||
|
status: r.status,
|
||||||
|
busy: r.busy,
|
||||||
|
labels: r.labels.map((l) => ({ name: l })),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('RunnerAvailabilityService', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('checkAvailability', () => {
|
||||||
|
it('should skip check and not fallback when no token is provided', async () => {
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', '', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.reason).toContain('No GitHub token');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback when no runners are registered', async () => {
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners: [] } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
expect(result.reason).toContain('No runners registered');
|
||||||
|
expect(result.totalRunners).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not fallback when enough idle runners are available', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'runner-1', status: 'online', busy: false, labels: ['self-hosted', 'linux'] },
|
||||||
|
{ name: 'runner-2', status: 'online', busy: false, labels: ['self-hosted', 'linux'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.idleRunners).toBe(2);
|
||||||
|
expect(result.totalRunners).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback when all runners are busy', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'runner-1', status: 'online', busy: true, labels: ['self-hosted'] },
|
||||||
|
{ name: 'runner-2', status: 'online', busy: true, labels: ['self-hosted'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
expect(result.idleRunners).toBe(0);
|
||||||
|
expect(result.matchingRunners).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback when all runners are offline', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'runner-1', status: 'offline', busy: false, labels: ['self-hosted'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
expect(result.idleRunners).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should filter runners by required labels', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'linux-runner', status: 'online', busy: false, labels: ['self-hosted', 'linux'] },
|
||||||
|
{ name: 'windows-runner', status: 'online', busy: false, labels: ['self-hosted', 'windows'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability(
|
||||||
|
'owner',
|
||||||
|
'repo',
|
||||||
|
'token',
|
||||||
|
['self-hosted', 'linux'],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.matchingRunners).toBe(1);
|
||||||
|
expect(result.idleRunners).toBe(1);
|
||||||
|
expect(result.totalRunners).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should fallback when no runners match required labels', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'windows-runner', status: 'online', busy: false, labels: ['self-hosted', 'windows'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability(
|
||||||
|
'owner',
|
||||||
|
'repo',
|
||||||
|
'token',
|
||||||
|
['self-hosted', 'linux'],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
expect(result.matchingRunners).toBe(0);
|
||||||
|
expect(result.idleRunners).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should respect minAvailable threshold', async () => {
|
||||||
|
const runners = createMockRunners([{ name: 'runner-1', status: 'online', busy: false, labels: ['self-hosted'] }]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
// Need 2, have 1 — should fallback
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 2);
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
expect(result.idleRunners).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be case-insensitive for label matching', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'runner-1', status: 'online', busy: false, labels: ['Self-Hosted', 'Linux'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability(
|
||||||
|
'owner',
|
||||||
|
'repo',
|
||||||
|
'token',
|
||||||
|
['self-hosted', 'linux'],
|
||||||
|
1,
|
||||||
|
);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.matchingRunners).toBe(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not fallback on API error (fail-open)', async () => {
|
||||||
|
const mockRequest = jest.fn().mockRejectedValue(new Error('403 Forbidden'));
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.reason).toContain('Runner check failed');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should count only online+idle runners', async () => {
|
||||||
|
const runners = createMockRunners([
|
||||||
|
{ name: 'idle', status: 'online', busy: false, labels: ['self-hosted'] },
|
||||||
|
{ name: 'busy', status: 'online', busy: true, labels: ['self-hosted'] },
|
||||||
|
{ name: 'offline', status: 'offline', busy: false, labels: ['self-hosted'] },
|
||||||
|
]);
|
||||||
|
const mockRequest = jest.fn().mockResolvedValue({ status: 200, data: { runners } });
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
expect(result.totalRunners).toBe(3);
|
||||||
|
expect(result.matchingRunners).toBe(3);
|
||||||
|
expect(result.idleRunners).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('pagination limits', () => {
|
||||||
|
it('should stop paginating after reaching the page limit', async () => {
|
||||||
|
// Return full pages (100 runners each) to force continued pagination
|
||||||
|
let callCount = 0;
|
||||||
|
const mockRequest = jest.fn().mockImplementation(() => {
|
||||||
|
callCount++;
|
||||||
|
const runners = createMockRunners(
|
||||||
|
Array.from({ length: 100 }, (_, i) => ({
|
||||||
|
name: `runner-${callCount}-${i}`,
|
||||||
|
status: 'online' as const,
|
||||||
|
busy: false,
|
||||||
|
labels: ['self-hosted'],
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Promise.resolve({ status: 200, data: { runners } });
|
||||||
|
});
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
|
||||||
|
// Should have called at most 100 pages (the MAX_PAGINATION_PAGES limit)
|
||||||
|
expect(mockRequest).toHaveBeenCalledTimes(100);
|
||||||
|
// Should still have runners from the pages it did fetch
|
||||||
|
expect(result.totalRunners).toBe(10000);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should stop paginating on rate limit (HTTP 403)', async () => {
|
||||||
|
let callCount = 0;
|
||||||
|
const mockRequest = jest.fn().mockImplementation(() => {
|
||||||
|
callCount++;
|
||||||
|
if (callCount === 2) {
|
||||||
|
// Octokit throws for non-2xx responses
|
||||||
|
const error: any = new Error('API rate limit exceeded');
|
||||||
|
error.status = 403;
|
||||||
|
error.response = {
|
||||||
|
status: 403,
|
||||||
|
headers: { 'x-ratelimit-reset': String(Math.floor(Date.now() / 1000) + 3600) },
|
||||||
|
};
|
||||||
|
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
const runners = createMockRunners(
|
||||||
|
Array.from({ length: 100 }, (_, i) => ({
|
||||||
|
name: `runner-${i}`,
|
||||||
|
status: 'online' as const,
|
||||||
|
busy: false,
|
||||||
|
labels: ['self-hosted'],
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Promise.resolve({ status: 200, data: { runners } });
|
||||||
|
});
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
|
||||||
|
// Should have stopped at page 2 (rate limited)
|
||||||
|
expect(mockRequest).toHaveBeenCalledTimes(2);
|
||||||
|
// Should use the 100 runners from the first page
|
||||||
|
expect(result.totalRunners).toBe(100);
|
||||||
|
expect(result.shouldFallback).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should stop paginating on rate limit (HTTP 429)', async () => {
|
||||||
|
let callCount = 0;
|
||||||
|
const mockRequest = jest.fn().mockImplementation(() => {
|
||||||
|
callCount++;
|
||||||
|
if (callCount === 1) {
|
||||||
|
// Octokit throws for non-2xx responses
|
||||||
|
const error: any = new Error('Too Many Requests');
|
||||||
|
error.status = 429;
|
||||||
|
error.response = { status: 429, headers: {} };
|
||||||
|
|
||||||
|
return Promise.reject(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve({ status: 200, data: { runners: [] } });
|
||||||
|
});
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
|
||||||
|
// Should have stopped at first page (rate limited immediately)
|
||||||
|
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||||
|
// No runners found — should fallback
|
||||||
|
expect(result.totalRunners).toBe(0);
|
||||||
|
expect(result.shouldFallback).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle pagination timeout gracefully', async () => {
|
||||||
|
// Mock Date.now to simulate timeout
|
||||||
|
const originalDateNow = Date.now;
|
||||||
|
let callCount = 0;
|
||||||
|
|
||||||
|
const mockRequest = jest.fn().mockImplementation(() => {
|
||||||
|
callCount++;
|
||||||
|
// After first call, advance time past the timeout
|
||||||
|
if (callCount >= 2) {
|
||||||
|
Date.now = jest.fn(() => originalDateNow() + 31_000);
|
||||||
|
}
|
||||||
|
const runners = createMockRunners(
|
||||||
|
Array.from({ length: 100 }, (_, i) => ({
|
||||||
|
name: `runner-${callCount}-${i}`,
|
||||||
|
status: 'online' as const,
|
||||||
|
busy: false,
|
||||||
|
labels: ['self-hosted'],
|
||||||
|
})),
|
||||||
|
);
|
||||||
|
|
||||||
|
return Promise.resolve({ status: 200, data: { runners } });
|
||||||
|
});
|
||||||
|
MockedOctokit.mockImplementation(() => ({ request: mockRequest } as any));
|
||||||
|
|
||||||
|
const result = await RunnerAvailabilityService.checkAvailability('owner', 'repo', 'token', [], 1);
|
||||||
|
|
||||||
|
// Should have stopped after timeout was detected (2 pages: first succeeds, second triggers timeout check)
|
||||||
|
expect(mockRequest.mock.calls.length).toBeLessThanOrEqual(3);
|
||||||
|
// Should have runners from pages fetched before timeout
|
||||||
|
expect(result.totalRunners).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
// Restore
|
||||||
|
Date.now = originalDateNow;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -0,0 +1,205 @@
|
|||||||
|
import { Octokit } from '@octokit/core';
|
||||||
|
import OrchestratorLogger from './orchestrator-logger';
|
||||||
|
|
||||||
|
interface GitHubRunner {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
status: 'online' | 'offline';
|
||||||
|
busy: boolean;
|
||||||
|
labels: Array<{ name: string }>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RunnerCheckResult {
|
||||||
|
shouldFallback: boolean;
|
||||||
|
reason: string;
|
||||||
|
totalRunners: number;
|
||||||
|
matchingRunners: number;
|
||||||
|
idleRunners: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum number of pages to fetch when paginating through GitHub API results.
|
||||||
|
* 100 pages * 100 per page = 10,000 runners maximum.
|
||||||
|
*/
|
||||||
|
const MAX_PAGINATION_PAGES = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Total timeout in milliseconds for the pagination loop.
|
||||||
|
* Prevents indefinite API calls if GitHub is slow or pagination is unexpectedly deep.
|
||||||
|
*/
|
||||||
|
const PAGINATION_TIMEOUT_MS = 30_000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks GitHub Actions runner availability to support automatic provider fallback.
|
||||||
|
*
|
||||||
|
* When a user configures `runnerCheckEnabled: true` with a `fallbackProviderStrategy`,
|
||||||
|
* this service queries the GitHub API for runner status before the build starts.
|
||||||
|
* If insufficient runners are available, the orchestrator routes to the fallback provider.
|
||||||
|
*/
|
||||||
|
export class RunnerAvailabilityService {
|
||||||
|
/**
|
||||||
|
* Check if enough runners are available to handle the build.
|
||||||
|
*
|
||||||
|
* @param owner - GitHub repository owner
|
||||||
|
* @param repo - GitHub repository name
|
||||||
|
* @param token - GitHub token with repo/actions scope
|
||||||
|
* @param requiredLabels - Labels runners must have (empty = any runner)
|
||||||
|
* @param minAvailable - Minimum idle runners required
|
||||||
|
* @returns RunnerCheckResult with decision and diagnostics
|
||||||
|
*/
|
||||||
|
static async checkAvailability(
|
||||||
|
owner: string,
|
||||||
|
repo: string,
|
||||||
|
token: string,
|
||||||
|
requiredLabels: string[],
|
||||||
|
minAvailable: number,
|
||||||
|
): Promise<RunnerCheckResult> {
|
||||||
|
if (!token) {
|
||||||
|
return {
|
||||||
|
shouldFallback: false,
|
||||||
|
reason: 'No GitHub token available — skipping runner check',
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const octokit = new Octokit({ auth: token });
|
||||||
|
|
||||||
|
// Fetch all runners for the repository
|
||||||
|
const runners = await RunnerAvailabilityService.fetchRunners(octokit, owner, repo);
|
||||||
|
|
||||||
|
if (runners.length === 0) {
|
||||||
|
return {
|
||||||
|
shouldFallback: true,
|
||||||
|
reason: 'No runners registered for this repository',
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter by required labels
|
||||||
|
const matching = RunnerAvailabilityService.filterByLabels(runners, requiredLabels);
|
||||||
|
|
||||||
|
// Count idle (online + not busy)
|
||||||
|
const idle = matching.filter((r) => r.status === 'online' && !r.busy);
|
||||||
|
|
||||||
|
const result: RunnerCheckResult = {
|
||||||
|
shouldFallback: idle.length < minAvailable,
|
||||||
|
reason:
|
||||||
|
idle.length >= minAvailable
|
||||||
|
? `${idle.length} idle runner(s) available (need ${minAvailable})`
|
||||||
|
: `Only ${idle.length} idle runner(s) available, need ${minAvailable}`,
|
||||||
|
totalRunners: runners.length,
|
||||||
|
matchingRunners: matching.length,
|
||||||
|
idleRunners: idle.length,
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (error: any) {
|
||||||
|
// If the API call fails (permissions, rate limit, etc.), don't block the build
|
||||||
|
OrchestratorLogger.log(`Runner availability check failed: ${error.message}`);
|
||||||
|
|
||||||
|
return {
|
||||||
|
shouldFallback: false,
|
||||||
|
reason: `Runner check failed (${error.message}) — proceeding with primary provider`,
|
||||||
|
totalRunners: 0,
|
||||||
|
matchingRunners: 0,
|
||||||
|
idleRunners: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch all runners for a repository, handling pagination.
|
||||||
|
*
|
||||||
|
* Includes defensive limits:
|
||||||
|
* - Maximum page count (MAX_PAGINATION_PAGES) to prevent infinite loops
|
||||||
|
* - Total timeout (PAGINATION_TIMEOUT_MS) to prevent indefinite API calls
|
||||||
|
* - Rate-limit detection (HTTP 403/429 with X-RateLimit-Remaining header)
|
||||||
|
*/
|
||||||
|
private static async fetchRunners(octokit: Octokit, owner: string, repo: string): Promise<GitHubRunner[]> {
|
||||||
|
const allRunners: GitHubRunner[] = [];
|
||||||
|
let page = 1;
|
||||||
|
const perPage = 100;
|
||||||
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
while (page <= MAX_PAGINATION_PAGES) {
|
||||||
|
// Check total timeout
|
||||||
|
if (Date.now() - startTime > PAGINATION_TIMEOUT_MS) {
|
||||||
|
OrchestratorLogger.logWarning(
|
||||||
|
`[RunnerAvailability] Pagination timeout reached after ${page - 1} pages and ${Date.now() - startTime}ms. ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
let response: any;
|
||||||
|
try {
|
||||||
|
response = await octokit.request('GET /repos/{owner}/{repo}/actions/runners', {
|
||||||
|
owner,
|
||||||
|
repo,
|
||||||
|
per_page: perPage,
|
||||||
|
page,
|
||||||
|
});
|
||||||
|
} catch (requestError: any) {
|
||||||
|
// Octokit throws for non-2xx responses. Check if this is a rate limit error.
|
||||||
|
const status = requestError.status ?? requestError.response?.status;
|
||||||
|
if (status === 403 || status === 429) {
|
||||||
|
const resetTime =
|
||||||
|
requestError.response?.headers?.['x-ratelimit-reset'] ?? requestError.headers?.['x-ratelimit-reset'];
|
||||||
|
const resetMessage = resetTime
|
||||||
|
? ` Resets at ${new Date(Number.parseInt(String(resetTime), 10) * 1000).toISOString()}`
|
||||||
|
: '';
|
||||||
|
OrchestratorLogger.logWarning(
|
||||||
|
`[RunnerAvailability] GitHub API rate limit reached (HTTP ${status}).${resetMessage} ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Re-throw non-rate-limit errors to be handled by the outer catch
|
||||||
|
throw requestError;
|
||||||
|
}
|
||||||
|
|
||||||
|
const runners = (response.data.runners || []) as GitHubRunner[];
|
||||||
|
allRunners.push(...runners);
|
||||||
|
|
||||||
|
if (runners.length < perPage) break;
|
||||||
|
page++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (page > MAX_PAGINATION_PAGES) {
|
||||||
|
OrchestratorLogger.logWarning(
|
||||||
|
`[RunnerAvailability] Maximum pagination limit reached (${MAX_PAGINATION_PAGES} pages). ` +
|
||||||
|
`Using ${allRunners.length} runners found so far.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allRunners.length === 0) {
|
||||||
|
OrchestratorLogger.log(
|
||||||
|
'[RunnerAvailability] No runners found. Possible causes: ' +
|
||||||
|
'wrong token permissions (needs repo or actions scope), ' +
|
||||||
|
'no self-hosted runners registered, ' +
|
||||||
|
'or runners are registered at the organization level instead of the repository.',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allRunners;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter runners by required labels. A runner matches if it has ALL required labels.
|
||||||
|
* If requiredLabels is empty, all runners match.
|
||||||
|
*/
|
||||||
|
private static filterByLabels(runners: GitHubRunner[], requiredLabels: string[]): GitHubRunner[] {
|
||||||
|
if (requiredLabels.length === 0) return runners;
|
||||||
|
|
||||||
|
return runners.filter((runner) => {
|
||||||
|
const runnerLabelNames = runner.labels.map((l) => l.name.toLowerCase());
|
||||||
|
|
||||||
|
return requiredLabels.every((required) => runnerLabelNames.includes(required.toLowerCase()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user