Skip to content

Merge branch 'main' of https://github.com/bigBrodyG/JavaProjects #28

Merge branch 'main' of https://github.com/bigBrodyG/JavaProjects

Merge branch 'main' of https://github.com/bigBrodyG/JavaProjects #28

name: Auto-Update Java Showcase Website
on:
push:
branches: [ main ]
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: "pages"
cancel-in-progress: false
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Create necessary directories
run: |
mkdir -p docs
# Support both old structure (root level) and new structure (Esercizi/Laboratorio)
for project in */src Esercizi/*/src Laboratorio/*/src; do
if [ -d "$(dirname "$project")" ]; then
project_name=$(dirname "$project")
mkdir -p "$project_name/bin"
fi
done
- name: Auto-detect and compile all Java projects
run: |
echo "🔍 Auto-detecting Java projects..."
# Find all Java projects in root, Esercizi/, and Laboratorio/ folders
for project_dir in */src Esercizi/*/src Laboratorio/*/src; do
# Skip if not a valid directory
if [ ! -d "$project_dir" ]; then
continue
fi
project_path=$(dirname "$project_dir")
project_name=$(basename "$project_path")
# Check if there are any Java files
java_files=$(find "$project_path/src" -name "*.java" 2>/dev/null | wc -l)
if [ "$java_files" -eq 0 ]; then
continue
fi
echo "📦 Compiling $project_name (from $project_path)..."
# Ensure bin directory exists
mkdir -p "$project_path/bin"
# Compile all Java files in the project
javac -d "$project_path/bin" "$project_path/src"/*.java 2>&1 | tee "docs/${project_name,,}-compile.log" || true
# Find the main class by trying to run each compiled class
main_class=""
if [ -d "$project_path/bin" ] && [ "$(ls -A $project_path/bin/*.class 2>/dev/null | wc -l)" -gt 0 ]; then
for class_file in "$project_path/bin"/*.class; do
if [ -f "$class_file" ]; then
class_name=$(basename "$class_file" .class)
# Try to run it - if it has a main method it will execute
if (cd "$project_path/bin" && timeout 5 java "$class_name" > /dev/null 2>&1); then
main_class="$class_name"
break
fi
fi
done
fi
# If we found a main class, run it and capture output
if [ -n "$main_class" ]; then
echo "▶️ Running $project_name ($main_class)..."
(cd "$project_path/bin" && timeout 10 java "$main_class" > "$(pwd | sed 's|/[^/]*$||'| sed 's|/[^/]*$||')/docs/${project_name,,}-output.txt" 2>&1) || echo "Error running $main_class" > "docs/${project_name,,}-output.txt"
else
# Try Main as fallback
if [ -f "$project_path/bin/Main.class" ]; then
echo "▶️ Running $project_name (Main)..."
(cd "$project_path/bin" && timeout 10 java Main > "$(pwd | sed 's|/[^/]*$||'| sed 's|/[^/]*$||')/docs/${project_name,,}-output.txt" 2>&1) || echo "Error running Main" > "docs/${project_name,,}-output.txt"
else
echo "⚠️ No main class found for $project_name"
echo "No main method found" > "docs/${project_name,,}-output.txt"
fi
fi
done
- name: Generate website with all projects
run: |
echo "🎨 Generating website..."
python3 .github/scripts/generate-site.py
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs
deploy:
if: github.ref == 'refs/heads/main'
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build-and-deploy
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4