Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .github/scripts/generate-packages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
const fs = require('fs');
const path = require('path');

/**
* Generate packages.json file by scanning the dist directory structure
* @param {string} distPath - Path to the dist directory
* @returns {Object} Generated packages data
*/
function generatePackagesJson(distPath = '.') {
console.log(`Scanning dist directory: ${distPath}`);

const repositories = [];

try {
// Read the dist directory
const distDir = fs.readdirSync(distPath, { withFileTypes: true });

// Process each subdirectory as a potential repository
for (const dirent of distDir) {
if (dirent.isDirectory() && dirent.name !== '.git') {
console.log(`Processing repository: ${dirent.name}`);
const repoData = scanRepositoryDirectory(path.join(distPath, dirent.name));
if (repoData) {
repositories.push(repoData);
console.log(` Found ${repoData.releases.length} releases`);
} else {
console.log(` No releases with assets found`);
}
}
}

// Sort repositories by name
repositories.sort((a, b) => a.name.localeCompare(b.name));

// Calculate totals
const totalReleases = repositories.reduce((sum, repo) => sum + repo.releases.length, 0);
const totalAssets = repositories.reduce((sum, repo) =>
sum + repo.releases.reduce((releaseSum, release) => releaseSum + release.assetCount, 0), 0
);

const packagesData = {
lastUpdated: new Date().toISOString(),
repositories: repositories,
stats: {
totalRepositories: repositories.length,
totalReleases: totalReleases,
totalAssets: totalAssets
}
};

console.log(`Generated packages data:`);
console.log(` Repositories: ${repositories.length}`);
console.log(` Total Releases: ${totalReleases}`);
console.log(` Total Assets: ${totalAssets}`);

return packagesData;

} catch (error) {
console.error('Error scanning dist directory:', error);
throw error;
}
}

/**
* Scan a repository directory to find releases and count assets
* @param {string} repoPath - Path to the repository directory
* @returns {Object|null} Repository data with releases or null if no valid releases
*/
function scanRepositoryDirectory(repoPath) {
const repoName = path.basename(repoPath);
const releases = [];

try {
if (!fs.existsSync(repoPath) || !fs.statSync(repoPath).isDirectory()) {
return null;
}

// Scan for release directories
const repoDirContents = fs.readdirSync(repoPath, { withFileTypes: true });

for (const dirent of repoDirContents) {
if (dirent.isDirectory()) {
const releaseData = scanReleaseDirectory(path.join(repoPath, dirent.name));
if (releaseData) {
releases.push(releaseData);
}
}
}

// Sort releases by tag name (newest first, assuming semantic versioning)
releases.sort((a, b) => b.tag.localeCompare(a.tag, undefined, { numeric: true, sensitivity: 'base' }));

if (releases.length > 0) {
return {
name: repoName,
releases: releases
};
}

return null;

} catch (error) {
console.error(`Error processing repository ${repoName}:`, error);
return null;
}
}

/**
* Scan a release directory to count asset files
* @param {string} releasePath - Path to the release directory
* @returns {Object|null} Release data with asset count or null if no assets
*/
function scanReleaseDirectory(releasePath) {
const releaseTag = path.basename(releasePath);

try {
if (!fs.existsSync(releasePath) || !fs.statSync(releasePath).isDirectory()) {
return null;
}

// Count actual asset files (exclude hash files and README)
const releaseContents = fs.readdirSync(releasePath, { withFileTypes: true });
const assetFiles = releaseContents.filter(dirent => {
if (!dirent.isFile()) return false;

const filename = dirent.name;
// Skip hash files and README
return !(filename.endsWith('.sha256') ||
filename.endsWith('.sha512') ||
filename.endsWith('.md5') ||
filename === 'README.md');
});

if (assetFiles.length > 0) {
return {
tag: releaseTag,
assetCount: assetFiles.length
};
}

return null;

} catch (error) {
console.error(`Error processing release ${releaseTag}:`, error);
return null;
}
}

/**
* Write packages.json file to the specified path
* @param {Object} packagesData - The packages data to write
* @param {string} outputPath - Path where to write the packages.json file
*/
function writePackagesJson(packagesData, outputPath = './packages.json') {
try {
const jsonString = JSON.stringify(packagesData, null, 2);
fs.writeFileSync(outputPath, jsonString, 'utf8');
console.log(`Generated packages.json: ${outputPath}`);
} catch (error) {
console.error('Error writing packages.json:', error);
throw error;
}
}

module.exports = {
generatePackagesJson,
scanRepositoryDirectory,
scanReleaseDirectory,
writePackagesJson
};
56 changes: 18 additions & 38 deletions .github/workflows/sync-release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,52 +67,32 @@ jobs:
process.chdir('./dist');
await syncReleaseAssets(github, context, isPullRequest, maxNewAssets);

- name: Commit and push changes
if: github.event_name != 'pull_request'
uses: actions-js/push@v1.5
- name: Generate packages.json
uses: actions/github-script@v8
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
branch: dist
directory: dist
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'Update release assets - ${{ github.run_id }}'
github-token: ${{ secrets.GH_BOT_TOKEN }}
script: |
// Import the packages generation module
const { generatePackagesJson, writePackagesJson } = require('./.github/scripts/generate-packages.js');

deploy-website:
needs: sync-assets
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
token: ${{ secrets.GH_BOT_TOKEN }}
console.log('Generating packages.json from dist directory...');

- name: Create or checkout gh-pages branch into gh-pages directory
run: |
git fetch origin
if git rev-parse --verify origin/gh-pages >/dev/null 2>&1; then
echo "gh-pages branch exists, checking it out"
git worktree add gh-pages origin/gh-pages
cd gh-pages
git pull origin gh-pages
else
echo "gh-pages branch doesn't exist, creating new one"
git worktree add --orphan gh-pages
cd gh-pages
git rm -rf . 2>/dev/null || true
fi
// Change to dist directory
process.chdir('./dist');

- name: Copy website files to gh-pages directory
run: |
cp -r gh-pages-template/* gh-pages/
// Generate the packages data
const packagesData = generatePackagesJson('.');

// Write the packages.json file
writePackagesJson(packagesData, './packages.json');

- name: Commit and push changes
if: github.event_name != 'pull_request'
uses: actions-js/push@v1.5
with:
author_email: ${{ secrets.GH_BOT_EMAIL }}
author_name: ${{ secrets.GH_BOT_NAME }}
branch: gh-pages
directory: gh-pages
branch: dist
directory: dist
github_token: ${{ secrets.GH_BOT_TOKEN }}
message: 'Update from ${{ github.sha }}'
message: 'Update release assets - ${{ github.run_id }}'
49 changes: 49 additions & 0 deletions .github/workflows/update-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: Build GH-Pages
permissions:
contents: read

on:
pull_request:
branches:
- master
types:
- opened
- synchronize
- reopened
push:
branches:
- master
workflow_dispatch:

concurrency:
group: "${{ github.workflow }}-${{ github.ref }}"
cancel-in-progress: true

jobs:
prep:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v5

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: prep
path: gh-pages-template/
if-no-files-found: error
include-hidden-files: true
retention-days: 1

call-jekyll-build:
needs: prep
uses: LizardByte/LizardByte.github.io/.github/workflows/jekyll-build.yml@master
secrets:
GH_BOT_EMAIL: ${{ secrets.GH_BOT_EMAIL }}
GH_BOT_NAME: ${{ secrets.GH_BOT_NAME }}
GH_BOT_TOKEN: ${{ secrets.GH_BOT_TOKEN }}
with:
clean_gh_pages: true
site_artifact: 'prep'
target_branch: 'gh-pages'
25 changes: 25 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

version: 2

build:
os: ubuntu-24.04
tools:
ruby: "3.3"
apt_packages:
- 7zip
- jq
jobs:
install:
- |
mkdir -p "./tmp"
branch="master"
base_url="https://raw.githubusercontent.com/LizardByte/LizardByte.github.io"
url="${base_url}/refs/heads/${branch}/scripts/readthedocs_build.sh"
curl -sSL -o "./tmp/readthedocs_build.sh" "${url}"
chmod +x "./tmp/readthedocs_build.sh"
build:
html:
- "./tmp/readthedocs_build.sh"
Loading