-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
151 lines (126 loc) · 6.04 KB
/
Copy pathapp.js
File metadata and controls
151 lines (126 loc) · 6.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
const SHADOW_CONFIG = {
github: {
owner: "ShadowOS-Linux",
repo: "shadowos-linux",
workflowFile: "build-iso.yml"
}
};
const runtimeState = {
de: null,
gpu: null,
steam: null,
liveData: {
suiteId: null,
artifacts: {}
}
};
document.addEventListener("DOMContentLoaded", () => {
initializeUIEventListeners();
fetchLatestArtifacts();
});
// Binds layout options and interaction hooks to the engine state
function initializeUIEventListeners() {
document.querySelectorAll('.selector-grid button').forEach(button => {
button.addEventListener('click', (e) => {
const currentButton = e.currentTarget;
const parentGrid = currentButton.parentElement;
const matrixStep = parentGrid.getAttribute('data-step');
const elementValue = currentButton.getAttribute('data-value');
parentGrid.querySelectorAll('button').forEach(btn => btn.classList.remove('active'));
currentButton.classList.add('active');
if (matrixStep === 'de') runtimeState.de = elementValue;
if (matrixStep === 'gpu') runtimeState.gpu = elementValue;
if (matrixStep === 'steam') runtimeState.steam = elementValue;
evaluateShadowPipeline();
});
});
}
/**
* Queries GitHub's Workflow and Artifact endpoints to resolve suite and artifact indices
*/
async function fetchLatestArtifacts() {
const { owner, repo, workflowFile } = SHADOW_CONFIG.github;
const runUrl = `https://api.github.com/repos/${owner}/${repo}/actions/workflows/${workflowFile}/runs?status=success&per_page=1`;
try {
const runResponse = await fetch(runUrl);
if (!runResponse.ok) throw new Error(`Workflow API responded with status: ${runResponse.status}`);
const runData = await runResponse.json();
if (!runData.workflow_runs || runData.workflow_runs.length === 0) {
throw new Error("No successful runs discovered in history.");
}
const latestRun = runData.workflow_runs[0];
const runId = latestRun.id.toString();
runtimeState.liveData.suiteId = latestRun.check_suite_id.toString();
const artifactsUrl = `https://api.github.com/repos/${owner}/${repo}/actions/runs/${runId}/artifacts`;
const artifactResponse = await fetch(artifactsUrl);
if (!artifactResponse.ok) throw new Error(`Artifacts sub-API dropped: ${artifactResponse.status}`);
const artifactData = await artifactResponse.json();
if (!artifactData.artifacts || artifactData.artifacts.length === 0) {
throw new Error("Run log contains no archived zip payloads.");
}
artifactData.artifacts.forEach(item => {
const fileName = item.name;
const internalArtifactId = item.id.toString();
const prefixMatch = fileName.match(/^(shadowos-[a-z-]+?)-f\d+/);
if (prefixMatch) {
const variantKey = prefixMatch[1];
runtimeState.liveData.artifacts[variantKey] = {
name: fileName,
id: internalArtifactId
};
}
});
console.log(`Pipeline Indexed! Suite ID: ${runtimeState.liveData.suiteId}`);
evaluateShadowPipeline();
} catch (error) {
console.error("Failed to sync remote artifact tree:", error);
const buildFilenameText = document.getElementById('build-filename');
if (buildFilenameText) {
buildFilenameText.textContent = "Error parsing real-time build names. Please refresh.";
buildFilenameText.style.color = "#ff6b6b";
}
}
}
function evaluateShadowPipeline() {
const stepGpu = document.getElementById('step-gpu');
const stepSteam = document.getElementById('step-steam');
const finalDownload = document.getElementById('final-download');
const buildStringText = document.getElementById('configuration-string');
const buildFilenameText = document.getElementById('build-filename');
const downloadBtn = document.querySelector('.download-btn');
if (runtimeState.de !== null && stepGpu) stepGpu.classList.add('visible');
if (runtimeState.de !== null && runtimeState.gpu !== null && stepSteam) stepSteam.classList.add('visible');
if (runtimeState.de !== null && runtimeState.gpu !== null && runtimeState.steam !== null) {
const { owner, repo } = SHADOW_CONFIG.github;
const variantTarget = `shadowos-${runtimeState.de}${runtimeState.gpu}${runtimeState.steam}`;
if (buildStringText) buildStringText.textContent = `VARIANT="${variantTarget}"`;
if (!runtimeState.liveData.suiteId || Object.keys(runtimeState.liveData.artifacts).length === 0) {
if (buildFilenameText) {
buildFilenameText.textContent = "Fetching build tracking metrics from GitHub index...";
buildFilenameText.style.color = "var(--accent)";
}
if (downloadBtn) downloadBtn.removeAttribute('href');
if (finalDownload) finalDownload.classList.add('visible');
return;
}
const matchedArtifact = runtimeState.liveData.artifacts[variantTarget];
if (matchedArtifact) {
if (buildFilenameText) {
buildFilenameText.textContent = matchedArtifact.name;
buildFilenameText.style.color = "#f0f6fc";
}
if (downloadBtn) {
downloadBtn.href = `https://nightly.link/${owner}/${repo}/suites/${runtimeState.liveData.suiteId}/artifacts/${matchedArtifact.id}`;
}
} else {
if (buildFilenameText) {
buildFilenameText.textContent = "Selected configuration variant not found in this build run.";
buildFilenameText.style.color = "#ff6b6b";
}
if (downloadBtn) downloadBtn.removeAttribute('href');
}
if (finalDownload) finalDownload.classList.add('visible');
} else {
if (finalDownload) finalDownload.classList.remove('visible');
}
}