Skip to content

Commit b246c21

Browse files
committed
Below:
* Cleaned the GitHub Workflow * Added an index.html page that allows to view and download compiled artifacts
1 parent c244eba commit b246c21

File tree

4 files changed

+160
-2
lines changed

4 files changed

+160
-2
lines changed

.github/workflows/go.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,33 @@ jobs:
3535
go-version: '1.24.1'
3636
- name: Setup Pages
3737
uses: actions/configure-pages@v5
38-
- name: Build
38+
- name: Prepare dependencies
3939
run: |
4040
go mod tidy # Ensures all required dependencies are installed
4141
echo "All required dependencies are installed"
42+
- name: Build undervolt-go
43+
run: |
4244
echo "Building undervolt-go..."
4345
go build -ldflags="-X 'main.version=$(git describe --tags)'" -o undervolt-go main.go # When building your application, pass the version from git tags using ldflags.
4446
echo "Build complete!"
47+
- name: Make compiled binary available
48+
run: |
4549
echo "Working on making the compiled binary available..."
4650
mkdir public
4751
cp -r ./undervolt-go ./public/ # Copy the binary to the public directory
48-
cp -r ./install/ ./public/ # Copy the scripts in the install directory to the public directory
52+
cp -r ./dist/script/ ./public/ # Copy the install scripts to the public directory
4953
echo "Ready to deploy!"
54+
- name: Output the files structure into a JSON file
55+
run: |
56+
sudo apt update
57+
sudo apt install -y tree
58+
tree -J public > ./public/files.json
59+
echo "JSON Manifest generated with the directory structure!"
60+
- name: Make web pages available
61+
run: |
62+
cp -r ./dist/pages/ ./public/ # Copy the web pages to the public directory
5063
- name: Upload artifact
64+
# upload artifact in the build stage, so that it is later on accessible in the deploy stage
5165
uses: actions/upload-pages-artifact@v3
5266
with:
5367
# Upload entire repository

dist/pages/index.html

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Artifact Explorer</title>
6+
<!-- PicoCSS via CDN -->
7+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@latest/css/pico.min.css">
8+
<style>
9+
.file-list {
10+
list-style: none;
11+
padding-left: 1rem;
12+
}
13+
.file-list li {
14+
margin: 0.5rem 0;
15+
}
16+
.breadcrumb {
17+
margin-bottom: 1rem;
18+
}
19+
.breadcrumb a {
20+
text-decoration: none;
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
<header>
26+
<h1>Artifact Explorer</h1>
27+
</header>
28+
<main>
29+
<!-- Breadcrumb navigation -->
30+
<nav id="breadcrumb" class="breadcrumb"></nav>
31+
<!-- File and folder list -->
32+
<ul id="fileList" class="file-list"></ul>
33+
</main>
34+
35+
<script>
36+
let fileTree = null;
37+
// breadcrumb holds the nodes from the root (index 0) to the current directory.
38+
let breadcrumb = [];
39+
40+
// Compute the relative URL for a child node.
41+
// If the root is "public" and you want to hide it, skip it in the URL.
42+
function computePath(child) {
43+
// Build parts from breadcrumb (skipping the root if its name is "public")
44+
let parts = [];
45+
for (let i = 0; i < breadcrumb.length; i++) {
46+
if (i === 0 && breadcrumb[i].name === "public") continue;
47+
parts.push(breadcrumb[i].name);
48+
}
49+
parts.push(child.name);
50+
return parts.join('/');
51+
}
52+
53+
// Render breadcrumb navigation.
54+
function renderBreadcrumb() {
55+
const nav = document.getElementById('breadcrumb');
56+
nav.innerHTML = '';
57+
58+
// Always add a link to the root.
59+
const rootLink = document.createElement('a');
60+
rootLink.href = '#';
61+
rootLink.textContent = breadcrumb[0].name;
62+
rootLink.addEventListener('click', (e) => {
63+
e.preventDefault();
64+
breadcrumb = [fileTree];
65+
renderDirectory(fileTree);
66+
});
67+
nav.appendChild(rootLink);
68+
69+
// For subsequent levels, add links.
70+
for (let i = 1; i < breadcrumb.length; i++) {
71+
const separator = document.createTextNode(' / ');
72+
nav.appendChild(separator);
73+
74+
const link = document.createElement('a');
75+
link.href = '#';
76+
link.textContent = breadcrumb[i].name;
77+
// Clicking a breadcrumb link goes back to that level.
78+
link.addEventListener('click', (e) => {
79+
e.preventDefault();
80+
breadcrumb = breadcrumb.slice(0, i + 1);
81+
renderDirectory(breadcrumb[breadcrumb.length - 1]);
82+
});
83+
nav.appendChild(link);
84+
}
85+
}
86+
87+
// Render the list of files and directories for a given node.
88+
function renderDirectory(node) {
89+
renderBreadcrumb();
90+
const list = document.getElementById('fileList');
91+
list.innerHTML = '';
92+
93+
// Ensure we have a "contents" array.
94+
if (!node.contents || node.contents.length === 0) {
95+
const li = document.createElement('li');
96+
li.textContent = 'No files or folders here.';
97+
list.appendChild(li);
98+
return;
99+
}
100+
101+
// Sort directories first.
102+
const sortedItems = node.contents.slice().sort((a, b) => {
103+
if (a.type === b.type) return a.name.localeCompare(b.name);
104+
return a.type === 'directory' ? -1 : 1;
105+
});
106+
107+
sortedItems.forEach(item => {
108+
const li = document.createElement('li');
109+
const link = document.createElement('a');
110+
link.href = '#';
111+
112+
if (item.type === 'directory') {
113+
link.textContent = item.name + '/';
114+
link.addEventListener('click', (e) => {
115+
e.preventDefault();
116+
breadcrumb.push(item);
117+
renderDirectory(item);
118+
});
119+
} else if (item.type === 'file') {
120+
// For files, compute the URL for download.
121+
const filePath = computePath(item);
122+
link.href = filePath;
123+
link.textContent = item.name;
124+
// Optionally, you can add link.download = item.name; if you want to force download.
125+
}
126+
li.appendChild(link);
127+
list.appendChild(li);
128+
});
129+
}
130+
131+
// Fetch the JSON manifest (output of tree -J)
132+
fetch('files.json')
133+
.then(response => response.json())
134+
.then(data => {
135+
// data is an array with a single element.
136+
fileTree = data[0];
137+
// Initialize breadcrumb with the root.
138+
breadcrumb = [fileTree];
139+
renderDirectory(fileTree);
140+
})
141+
.catch(error => console.error('Error loading file manifest:', error));
142+
</script>
143+
</body>
144+
</html>

0 commit comments

Comments
 (0)